Mercurial > prosody-hg
comparison util/human/io.lua @ 13045:da0b3cb9a2ec
util.human.io: table: use term_width() to discover terminal width
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 07 Apr 2023 12:35:39 +0100 |
| parents | 5bd272095388 |
| children | d939bf469057 |
comparison
equal
deleted
inserted
replaced
| 13044:5bd272095388 | 13045:da0b3cb9a2ec |
|---|---|
| 124 if width == 1 then return "…"; end | 124 if width == 1 then return "…"; end |
| 125 return utf8_cut(s, width - 1) .. "…"; | 125 return utf8_cut(s, width - 1) .. "…"; |
| 126 end | 126 end |
| 127 | 127 |
| 128 local function new_table(col_specs, max_width) | 128 local function new_table(col_specs, max_width) |
| 129 max_width = max_width or tonumber(os.getenv("COLUMNS")) or 80; | 129 max_width = max_width or term_width(os.getenv("COLUMNS") or 80); |
| 130 local separator = " | "; | 130 local separator = " | "; |
| 131 | 131 |
| 132 local widths = {}; | 132 local widths = {}; |
| 133 local total_width = max_width - #separator * (#col_specs-1); | 133 local total_width = max_width - #separator * (#col_specs-1); |
| 134 local free_width = total_width; | 134 local free_width = total_width; |
