Software /
code /
prosody
Diff
util/human/io.lua @ 11894:57106c61d104
util.human.io: Factor out ellipsis function
Could be useful elsewhere
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Nov 2021 12:14:27 +0100 |
parent | 11893:afef1e170de7 |
child | 11895:d278a4c6da7f |
line wrap: on
line diff
--- a/util/human/io.lua Fri Nov 12 11:44:31 2021 +0100 +++ b/util/human/io.lua Fri Nov 12 12:14:27 2021 +0100 @@ -95,6 +95,10 @@ return string.rep(" ", width-#s)..s; end +local function ellipsis(s, width) + return s:sub(1, width-1) .. "…"; +end + local function new_table(col_specs, max_width) max_width = max_width or tonumber(os.getenv("COLUMNS")) or 80; local separator = " | "; @@ -147,7 +151,7 @@ v = padright(v, width); end elseif #v > width then - v = v:sub(1, width-1) .. "…"; + v = ellipsis(v, width); end table.insert(output, v); end @@ -165,5 +169,6 @@ printf = printf; padleft = padleft; padright = padright; + ellipsis = ellipsis; table = new_table; };