Software /
code /
prosody
Comparison
util/human/io.lua @ 10911:9dc34e1556d9
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 04 Jun 2020 21:32:28 +0200 |
parent | 10910:e890b83f08cf |
child | 10917:1eb83bc6f706 |
comparison
equal
deleted
inserted
replaced
10910:e890b83f08cf | 10911:9dc34e1556d9 |
---|---|
129 titles, row = true, array.pluck(col_specs, "title", ""); | 129 titles, row = true, array.pluck(col_specs, "title", ""); |
130 end | 130 end |
131 local output = {}; | 131 local output = {}; |
132 for i, column in ipairs(col_specs) do | 132 for i, column in ipairs(col_specs) do |
133 local width = widths[i]; | 133 local width = widths[i]; |
134 local v = tostring(row[not titles and column.key or i] or ""); | 134 local v = (not titles and column.mapper or tostring)(row[not titles and column.key or i] or "", row); |
135 if #v < width then | 135 if #v < width then |
136 if column.align == "right" then | 136 if column.align == "right" then |
137 v = padleft(v, width-1).." "; | 137 v = padleft(v, width-1).." "; |
138 else | 138 else |
139 v = padright(v, width); | 139 v = padright(v, width); |