changeset 13937:cfe3e85e715f

util.human.io: Support disabling column widths This makes columns be of variable with, padding and ellipsis is disabled. With the separator set to "\t", this produces TSV output
author Kim Alvefur <zash@zash.se>
date Sat, 30 Aug 2025 21:55:03 +0200
parents 4f1b6f6e68c0
children 88f5ea4c28ce
files util/human/io.lua
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/util/human/io.lua	Sat Aug 30 21:54:07 2025 +0200
+++ b/util/human/io.lua	Sat Aug 30 21:55:03 2025 +0200
@@ -167,10 +167,15 @@
 end
 
 local function new_table(col_specs, max_width, separator)
-	max_width = max_width or term_width(80);
 	separator = separator or " | ";
 
-	local widths = calculate_column_widths(col_specs, separator, max_width);
+	local widths;
+	if max_width ~= -1 then
+		max_width = max_width or term_width(80);
+		widths = calculate_column_widths(col_specs, separator, max_width)
+	else
+		widths = {};
+	end
 
 	return function (row)
 		local titles;
@@ -189,14 +194,16 @@
 			else
 				v = tostring(v);
 			end
-			if len(v) < width then
-				if column.align == "right" then
-					v = padleft(v, width);
-				else
-					v = padright(v, width);
+			if width then
+				if len(v) < width then
+					if column.align == "right" then
+						v = padleft(v, width);
+					else
+						v = padright(v, width);
+					end
+				elseif len(v) > width then
+					v = (column.ellipsis or ellipsis)(v, width);
 				end
-			elseif len(v) > width then
-				v = (column.ellipsis or ellipsis)(v, width);
 			end
 			table.insert(output, v);
 		end