-
-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Description
problem
Currently cli/format-table can't handle ANSI escape codes.
Given for example:
(cli/format-table {:rows [["foo" "<- something plain"]
["\033[31mbar\033[0m" "<- something red"]]})...the foo- and bar-cell have the same width when printed (ie 3). But as the bar-cell is considered to have a width of 12, the foo-cell gets padded to this length as well, making it look off when printed.
Less common, but same idea when using emoji's: (count "🚀 bar") ;;=> 6 (but 5 when printed).
possible approaches
provide widths
Providing the width of every cell, e.g. via metadata on a row:
user=> rows
[^{:column-widths [3 18]}
["foo" "<- something plain"]
^{:column-widths [3 16]}
["\033[31mbar\033[0m" "<- something red"]]This metadata would be used instead of (map count row) in #cli/pad-cells:
Lines 526 to 532 in 836b15f
| (defn pad-cells [rows] | |
| (let [widths (reduce | |
| (fn [widths row] | |
| (map max (map count row) widths)) (repeat 0) rows) | |
| pad-row (fn [row] | |
| (map (fn [width col] (pad width col)) widths row))] | |
| (map pad-row rows))) |
This solution would also double as a solution to the problem 'how to customise spacing between columns'.
Happy to provide a PR.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels