Mercurial > prosody-hg
diff util/human/io.lua @ 13935:6a493e41c2cc
util.human.io: Factor out column width calculation
Goal is to make it optional and have e.g. CSV/TSV output
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 30 Aug 2025 21:52:00 +0200 |
| parents | 82513890a1d8 |
| children | 4f1b6f6e68c0 |
line wrap: on
line diff
--- a/util/human/io.lua Sun Aug 24 20:05:36 2025 +0200 +++ b/util/human/io.lua Sat Aug 30 21:52:00 2025 +0200 @@ -131,10 +131,7 @@ return utf8_cut(s, width - 1) .. "…"; end -local function new_table(col_specs, max_width) - max_width = max_width or term_width(80); - local separator = " | "; - +local function calculate_column_widths(col_specs, separator, max_width) local widths = {}; local total_width = max_width - #separator * (#col_specs-1); local free_width = total_width; @@ -166,6 +163,15 @@ end end + return widths; +end + +local function new_table(col_specs, max_width) + max_width = max_width or term_width(80); + local separator = " | "; + + local widths = calculate_column_widths(col_specs, separator, max_width); + return function (row) local titles; if not row then
