aboutsummaryrefslogtreecommitdiffstats
path: root/util/human/io.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-12 12:14:27 +0100
committerKim Alvefur <zash@zash.se>2021-11-12 12:14:27 +0100
commitf8afa0807b38482f361eaab228193b53dbebc962 (patch)
treee5b57a467c921d7f1e98ff646f030c596d03e434 /util/human/io.lua
parente162a73d737e60c41ba7e0e13e2ab898b58b7e0b (diff)
downloadprosody-f8afa0807b38482f361eaab228193b53dbebc962.tar.gz
prosody-f8afa0807b38482f361eaab228193b53dbebc962.zip
util.human.io: Factor out ellipsis function
Could be useful elsewhere
Diffstat (limited to 'util/human/io.lua')
-rw-r--r--util/human/io.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/human/io.lua b/util/human/io.lua
index f8868cc6..2e59ea85 100644
--- a/util/human/io.lua
+++ b/util/human/io.lua
@@ -95,6 +95,10 @@ local function padleft(s, width)
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 @@ local function new_table(col_specs, max_width)
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 @@ return {
printf = printf;
padleft = padleft;
padright = padright;
+ ellipsis = ellipsis;
table = new_table;
};