util.human.io.table: Allow a map callaback per column
authorKim Alvefur <zash@zash.se>
Thu, 04 Jun 2020 21:32:28 +0200
changeset 10915 9dc34e1556d9
parent 10914 e890b83f08cf
child 10919 687273948ec7
util.human.io.table: Allow a map callaback per column This allows e.g. mapping booleans to "yes" or "no", specific number formatting or generating virtual columns. All while not mutating the underlying data or creating additional temporary tables.
util/human/io.lua
--- a/util/human/io.lua	Thu Jun 04 18:40:37 2020 +0200
+++ b/util/human/io.lua	Thu Jun 04 21:32:28 2020 +0200
@@ -131,7 +131,7 @@
 		local output = {};
 		for i, column in ipairs(col_specs) do
 			local width = widths[i];
-			local v = tostring(row[not titles and column.key or i] or "");
+			local v = (not titles and column.mapper or tostring)(row[not titles and column.key or i] or "", row);
 			if #v < width then
 				if column.align == "right" then
 					v = padleft(v, width-1).." ";