nuno zrewidował ten Gist 1 month ago. Przejdź do rewizji
1 file changed, 33 insertions
gistfile1.txt(stworzono plik)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | function ui::activity::service_row() { | |
| 2 | + | local dest_display="${1:-}" drop_count="${2:-0}" drop_word="${3:-drops}" \ | |
| 3 | + | drops_col="${4:-30}" w_drops="${5:-1}" | |
| 4 | + | ||
| 5 | + | # Align drop count with peer drop column | |
| 6 | + | # Service row visible prefix: " → " (6 visible) + ${#dest_display} | |
| 7 | + | # But "→" is 3 bytes, 1 visible — arrow_prefix bytes = 8, visible = 6 | |
| 8 | + | local arrow_prefix=" → " | |
| 9 | + | local prefix_bytes=${#arrow_prefix} # 8 bytes due to → being 3 bytes | |
| 10 | + | local prefix_len=$(( prefix_bytes + ${#dest_display} )) | |
| 11 | + | local pad_n=$(( drops_col - prefix_len )) | |
| 12 | + | [[ $pad_n -lt 1 ]] && pad_n=1 | |
| 13 | + | ||
| 14 | + | printf " \033[2m→\033[0m %s%*s %${w_drops}s %s\n" \ | |
| 15 | + | "$dest_display" "$pad_n" "" "$drop_count" "$drop_word" | |
| 16 | + | } | |
| 17 | + | function ui::activity::accept_dest_row() { | |
| 18 | + | local dest="${1:-}" bytes_raw="${2:-0}" bytes_fmt="${3:-}" \ | |
| 19 | + | count="${4:-0}" drops_col="${5:-40}" w_drops="${6:-4}" | |
| 20 | + | ||
| 21 | + | local conn_word="conns" | |
| 22 | + | [[ "$count" -eq 1 ]] && conn_word="conn" | |
| 23 | + | ||
| 24 | + | local arrow_prefix=" → " | |
| 25 | + | # Pad dest to align count at drops_col | |
| 26 | + | # arrow_prefix visible length = 6, → = 3 bytes so prefix_bytes = 8 | |
| 27 | + | local prefix_visible=6 | |
| 28 | + | local dest_width=$(( drops_col - 5 - w_drops )) | |
| 29 | + | [[ $dest_width -lt 0 ]] && dest_width=28 | |
| 30 | + | ||
| 31 | + | printf "%s\033[0;32m%-${dest_width}s %4s %-5s %-8s\033[0m\n" \ | |
| 32 | + | "$arrow_prefix" "$dest" "$count" "$conn_word" "$bytes_fmt" | |
| 33 | + | } | |
Nowsze
Starsze