Changeset

10896:c7a0eab27165

util.human.io: table: Fix title printing when columns use named keys
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Jun 2020 10:39:55 +0100
parents 10895:5777968301e8
children 10897:37df1e757f02
files util/human/io.lua
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/util/human/io.lua	Thu Jun 04 10:39:12 2020 +0100
+++ b/util/human/io.lua	Thu Jun 04 10:39:55 2020 +0100
@@ -121,13 +121,14 @@
 	end
 
 	return function (row)
+		local titles;
 		if not row then
-			row = array.pluck(col_specs, "title");
+			titles, row = true, array.pluck(col_specs, "title", "");
 		end
 		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);
+			local v = tostring(row[not titles and column.key or i] or ""):sub(1, width);
 			if #v < width then
 				if column.align == "right" then
 					v = padleft(v, width-1).." ";