aboutsummaryrefslogtreecommitdiffstats
path: root/util/human
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-06-03 22:45:33 +0100
committerMatthew Wild <mwild1@gmail.com>2020-06-03 22:45:33 +0100
commit8467f4f9eaeeaf1c70c8ee958eb9eb9757c8fb64 (patch)
tree28222bffceb5ee2e97ad81909fb599063d70c9b2 /util/human
parent56c159d7c947f3bb71b33a4ff3e4f1fba8ebd30a (diff)
downloadprosody-8467f4f9eaeeaf1c70c8ee958eb9eb9757c8fb64.tar.gz
prosody-8467f4f9eaeeaf1c70c8ee958eb9eb9757c8fb64.zip
util.human.io: table: switch row function to simply returning prepared row string
Diffstat (limited to 'util/human')
-rw-r--r--util/human/io.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/util/human/io.lua b/util/human/io.lua
index 338509b1..dfed3b09 100644
--- a/util/human/io.lua
+++ b/util/human/io.lua
@@ -93,7 +93,7 @@ local function padleft(s, width)
return string.rep(" ", width-#s)..s;
end
-local function table(col_specs, max_width, padding)
+local function new_table(col_specs, max_width, padding)
max_width = max_width or 80;
padding = padding or 4;
@@ -118,7 +118,8 @@ local function table(col_specs, max_width, padding)
end
end
- return function (row, f)
+ return function (row)
+ local output = {};
for i, column in ipairs(col_specs) do
local width = widths[i];
local v = tostring(row[column.key or i] or ""):sub(1, width);
@@ -129,9 +130,9 @@ local function table(col_specs, max_width, padding)
v = padright(v, width);
end
end
- (f or io.stdout):write(v);
+ table.insert(output, v);
end
- (f or io.stdout):write("\n");
+ return table.concat(output);
end;
end
@@ -145,5 +146,5 @@ return {
printf = printf;
padleft = padleft;
padright = padright;
- table = table;
+ table = new_table;
};