diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2025-10-22 06:39:13 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2025-10-22 06:39:13 +0200 |
commit | 04ff3adccc48664c366b705ab9265c155633671d (patch) | |
tree | b75b89e8fc5b8e833eb15cca59506e7b36acb554 /lib/remote/print.sh | |
parent | 9378edc09d4a0b9f19ef4314e0de7efa9634d849 (diff) | |
download | conky-04ff3adccc48664c366b705ab9265c155633671d.tar.gz conky-04ff3adccc48664c366b705ab9265c155633671d.tar.bz2 conky-04ff3adccc48664c366b705ab9265c155633671d.tar.xz conky-04ff3adccc48664c366b705ab9265c155633671d.zip |
Diffstat (limited to 'lib/remote/print.sh')
-rw-r--r-- | lib/remote/print.sh | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/remote/print.sh b/lib/remote/print.sh index a0fdcbe..ef9c9b8 100644 --- a/lib/remote/print.sh +++ b/lib/remote/print.sh @@ -130,9 +130,33 @@ function print_hline { echo | eol } +acolumn() { + local sep="$1" out="$2" + awk -v FS="$sep" -v SEP="$out" -v OFS='' ' + function strip(s) { gsub(/\x1B\[[0-9;?]*[ -/]*[@-~]/, "", s); return s } + { + rows[NR] = $0 + if (NF > cols) cols = NF + for (i = 1; i <= NF; i++) + if (length(strip($i)) > w[i]) w[i] = length(strip($i)) + } + END { + for (r = 1; r <= NR; r++) { + n = split(rows[r], a, FS) + for (i = 1; i <= n; i++) { + pad = w[i] - length(strip(a[i])) + printf "%s%*s", a[i], (i < n ? pad : 0), "" + if (i < n) printf "%s", SEP + } + print "" + } + }' +} + function print_table { # The problem here is that all escapes for colors are treated as normal visible symbols - sed "s/ ::: /@/g" | column -t -s "@" -o " " | eol +# sed "s/ ::: /@/g" | column -t -s "@" -o "x x" --output-width 0 | eol + sed "s/ ::: /@/g" | acolumn "@" " " | eol } function decorate_table { |