vis-tables - Vis plugin for writing tables
ssh://anon@thyssentishman.com/vis-tables
Log | Files | Refs | Feed | Contribute | README | LICENSE

Commit: 6016cc5e4607aa55f4d483a2f5e69c7f196fd462
Parent: c0289760baa0c4ee5532c292e6a73f56222e139b
Author: Johannes Thyssen Tishman
Date:   Wed, 20 Nov 2024 11:43:09 +0000

Handle strings longer than 99 characters

Lua limits format specifiers to a field width of 99 (two digits).
https://www.lua.org/source/5.4/lstrlib.c.html#MAX_ITEMF

Diffstat:
M init.lua | 8 ++++++++

1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/init.lua b/init.lua
@@ -50,11 +50,19 @@ local function gettable(ln, lc, lines)
 	for i = tbl.start, tbl.finish do
 		local fields = {}
 		local row = lines[i]
+		local col = 1
 		row = row:gsub('^%s*(.-)%s*$', '%1')
 		for s in row:gmatch('[^' .. esc(M.csep) .. ']+') do
 			s = s:match('%S') and 
 				s:gsub('^%s*(.-)%s*$', '%1') or ' '
+			if #s > 99 then
+				s = s:sub(1,99)
+				vis:info(('%d,%d:' ..
+					' The string exceeds the maximum length (99)' ..
+					' and has been truncated'):format(i,col))
+			end
 			table.insert(fields, s)
+			col = col + 1
 		end
 		tbl[i - tbl.start + 1] = fields
 	end