nuno 修订了这个 Gist 1 month ago. 转到此修订
1 file changed, 31 insertions
gistfile1.txt(文件已创建)
| @@ -0,0 +1,31 @@ | |||
| 1 | + | function ui::logs::wg_row() { | |
| 2 | + | local ts="${1:-}" client="${2:-}" endpoint="${3:-}" event="${4:-}" count="${5:-1}" \ | |
| 3 | + | w_client="${6:-20}" w_endpoint="${7:-20}" | |
| 4 | + | local event_color | |
| 5 | + | case "$event" in | |
| 6 | + | handshake) event_color="\033[1;32m" ;; | |
| 7 | + | attempt) event_color="\033[1;31m" ;; | |
| 8 | + | *) event_color="\033[0;37m" ;; | |
| 9 | + | esac | |
| 10 | + | local count_suffix="" | |
| 11 | + | [[ "$count" -gt 1 ]] && count_suffix=" \033[2m(x${count})\033[0m" | |
| 12 | + | local client_pad endpoint_pad_n | |
| 13 | + | client_pad=$(printf "%-${w_client}s" "$client") | |
| 14 | + | endpoint_pad_n=$(( w_endpoint - ${#endpoint} )) | |
| 15 | + | [[ $endpoint_pad_n -lt 0 ]] && endpoint_pad_n=0 | |
| 16 | + | printf " %s %s %s%*s %b%s\033[0m%b\n" \ | |
| 17 | + | "$ts" "$client_pad" "$endpoint" "$endpoint_pad_n" "" \ | |
| 18 | + | "$event_color" "$event" "$count_suffix" | |
| 19 | + | } | |
| 20 | + | function ui::logs::wg_row_table() { | |
| 21 | + | local ts="${1:-}" client="${2:-}" endpoint="${3:-}" event="${4:-}" count="${5:-1}" | |
| 22 | + | local count_str="" | |
| 23 | + | [[ "$count" -gt 1 ]] && count_str=" (x${count})" | |
| 24 | + | local event_colored | |
| 25 | + | case "$event" in | |
| 26 | + | attempt*) event_colored="\033[1;31m${event}\033[0m" ;; | |
| 27 | + | handshake*) event_colored="\033[1;32m${event}\033[0m" ;; | |
| 28 | + | *) event_colored="$event" ;; | |
| 29 | + | esac | |
| 30 | + | printf " %-20s %-20s %-18s %b%s\n" "$ts" "$client" "$endpoint" "$event_colored" "$count_str" | |
| 31 | + | } | |
上一页
下一页