From 190ca31c6c99671ca9045562145fbf0c0e0a1e44 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 30 Dec 2010 21:08:22 +0000 Subject: [PATCH] Don't pad the last item in each row in tab.lua. This prevents one long line from making all other lines wrap with blanks. --- nselib/tab.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nselib/tab.lua b/nselib/tab.lua index 93a44079b..c553dccd9 100644 --- a/nselib/tab.lua +++ b/nselib/tab.lua @@ -84,18 +84,19 @@ function dump(t) assert(t) local column_width = {} - local num_columns = 0 + local num_columns = {} local buf = strbuf.new() -- find widest element in each column for i, row in ipairs(t) do + num_columns[i] = 0 for x, elem in pairs(row) do local elem_width = string.len(elem) if not column_width[x] or elem_width > column_width[x] then column_width[x] = elem_width end - if x > num_columns then - num_columns = x + if x > num_columns[i] then + num_columns[i] = x end end end @@ -103,9 +104,13 @@ function dump(t) -- build buf with padding so all column elements line up for i, row in ipairs(t) do local text_row = {} - for x = 1, num_columns do + for x = 1, num_columns[i] do local elem = row[x] or "" - text_row[#text_row + 1] = elem .. string.rep(" ", column_width[x] - #elem) + if x < num_columns[i] then + text_row[#text_row + 1] = elem .. string.rep(" ", column_width[x] - #elem) + else + text_row[#text_row + 1] = elem + end end buf = buf .. table.concat(text_row, " ") .. "\n" end