Comparison

util/human/io.lua @ 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
parent 10894:d15a4284fdf8
child 10904:d009a79f723a
comparison
equal deleted inserted replaced
10895:5777968301e8 10896:c7a0eab27165
119 widths[i] = math.floor(free_width*(pc_width/100)); 119 widths[i] = math.floor(free_width*(pc_width/100));
120 end 120 end
121 end 121 end
122 122
123 return function (row) 123 return function (row)
124 local titles;
124 if not row then 125 if not row then
125 row = array.pluck(col_specs, "title"); 126 titles, row = true, array.pluck(col_specs, "title", "");
126 end 127 end
127 local output = {}; 128 local output = {};
128 for i, column in ipairs(col_specs) do 129 for i, column in ipairs(col_specs) do
129 local width = widths[i]; 130 local width = widths[i];
130 local v = tostring(row[column.key or i] or ""):sub(1, width); 131 local v = tostring(row[not titles and column.key or i] or ""):sub(1, width);
131 if #v < width then 132 if #v < width then
132 if column.align == "right" then 133 if column.align == "right" then
133 v = padleft(v, width-1).." "; 134 v = padleft(v, width-1).." ";
134 else 135 else
135 v = padright(v, width); 136 v = padright(v, width);