Zuletzt aktiv 1 month ago

nuno hat die Gist bearbeitet 1 month ago. Zu Änderung gehen

1 file changed, 66 insertions

gistfile1.txt(Datei erstellt)

@@ -0,0 +1,66 @@
1 + function ui::logs::fw_row() {
2 + local ts="${1:-}" client="${2:-}" dest_ip="${3:-}" dest_port="${4:-}" \
3 + proto="${5:-}" svc_name="${6:-}" count="${7:-1}" \
4 + w_client="${8:-20}" w_dest="${9:-30}" \
5 + src_endpoint="${10:-}" src_resolved="${11:-}"
6 + w_endpoint="${12:-0}" resolved_only="${13:-false}"
7 +
8 + local ts_pad client_pad
9 + ts_pad=$(printf "%-11s" "$ts")
10 + client_pad=$(printf "%-${w_client}s" "$client")
11 +
12 + # ── Source endpoint — always render at w_endpoint width ──
13 + local src_padded=""
14 + if [[ "$w_endpoint" -gt 0 ]]; then
15 + if [[ -n "$src_endpoint" ]]; then
16 + local src_colored="$src_endpoint"
17 + [[ -n "$src_resolved" ]] && \
18 + src_colored="${src_endpoint} \033[2m→ ${src_resolved}\033[0m"
19 + src_padded=$(ui::pad_mb "$src_colored" "$w_endpoint")
20 + else
21 + # No endpoint — use dim dash padded to w_endpoint
22 + src_padded=$(ui::pad_mb "\033[2m—\033[0m" "$w_endpoint")
23 + fi
24 + fi
25 +
26 + # ── Destination ──
27 + local svc_display=""
28 + local raw_suffix=""
29 + if [[ -n "$svc_name" ]]; then
30 + [[ -n "$dest_port" ]] && svc_display="${svc_name}/${proto}" \
31 + || svc_display="${svc_name} (${proto})"
32 + [[ -n "$dest_port" ]] && raw_suffix=" \033[2m(${dest_ip}:${dest_port})\033[0m" \
33 + || raw_suffix=" \033[2m(${dest_ip})\033[0m"
34 + else
35 + [[ -n "$dest_port" ]] && svc_display="${dest_ip}:${dest_port}/${proto}" \
36 + || svc_display="${dest_ip} (${proto})"
37 + fi
38 +
39 + # Pad so count aligns — based on full dest (svc + raw_suffix plain length)
40 + local raw_plain=""
41 + [[ -n "$svc_name" && -n "$dest_port" ]] && raw_plain=" (${dest_ip}:${dest_port})"
42 + [[ -n "$svc_name" && -z "$dest_port" ]] && raw_plain=" (${dest_ip})"
43 + local full_dest_len=$(( ${#svc_display} + ${#raw_plain} ))
44 + local dest_pad_n=$(( w_dest - full_dest_len ))
45 + [[ $dest_pad_n -lt 0 ]] && dest_pad_n=0
46 +
47 + # ── Count ──
48 + local count_suffix=""
49 + [[ "$count" -gt 1 ]] && count_suffix=" \033[2m(x${count})\033[0m"
50 +
51 + # ── Render ──
52 + if [[ "$w_endpoint" -gt 0 ]]; then
53 + printf " %s %s %b \033[1;31m→\033[0m %s%b%*s%b\n" \
54 + "$ts_pad" "$client_pad" \
55 + "$src_padded" \
56 + "$svc_display" "$raw_suffix" \
57 + "$dest_pad_n" "" \
58 + "$count_suffix"
59 + else
60 + printf " %s %s \033[1;31m→\033[0m %s%b%*s%b\n" \
61 + "$ts_pad" "$client_pad" \
62 + "$svc_display" "$raw_suffix" \
63 + "$dest_pad_n" "" \
64 + "$count_suffix"
65 + fi
66 + }
Neuer Älter