Comparison

util/human/io.lua @ 10904:d009a79f723a

util.human.io: Remove padding option and use $COLUMNS as default width
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Jun 2020 17:24:30 +0100
parent 10896:c7a0eab27165
child 10907:6af28c756752
comparison
equal deleted inserted replaced
10903:c5f26f9adb31 10904:d009a79f723a
93 93
94 local function padleft(s, width) 94 local function padleft(s, width)
95 return string.rep(" ", width-#s)..s; 95 return string.rep(" ", width-#s)..s;
96 end 96 end
97 97
98 local function new_table(col_specs, max_width, padding) 98 local function new_table(col_specs, max_width)
99 max_width = max_width or 80; 99 max_width = max_width or tonumber(os.getenv("COLUMNS")) or 80;
100 padding = padding or 4;
101 100
102 local widths = {}; 101 local widths = {};
103 local total_width = max_width - padding; 102 local total_width = max_width;
104 local free_width = total_width; 103 local free_width = total_width;
105 -- Calculate width of fixed-size columns 104 -- Calculate width of fixed-size columns
106 for i = 1, #col_specs do 105 for i = 1, #col_specs do
107 local width = col_specs[i].width or "0"; 106 local width = col_specs[i].width or "0";
108 if not(type(width) == "string" and width:sub(-1) == "%") then 107 if not(type(width) == "string" and width:sub(-1) == "%") then