Skip to content

Commit

Permalink
[loaders] improve fixed-width saver saulpw#2255
Browse files Browse the repository at this point in the history
Don't add so many spaces between columns.
Use the max width of the data, rather than the max width of the window.
  • Loading branch information
daviewales committed Jan 23, 2024
1 parent 6424f63 commit e2d9550
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions visidata/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,20 @@ def getMaxWidth(self, rows):
w = min(w, self.sheet.windowWidth)
return w

def getMaxDataWidth(self, rows): #2255 need real max width for fixed width saver
'''Return the maximum length of any cell in column or its header,
even if wider than window. (Slow for large cells!)'''

w = 0
nlen = dispwidth(self.name)
if len(rows) > 0:
w_max = 0
for r in rows:
row_w = dispwidth(self.getDisplayValue(r))
if w_max < row_w:
w_max = row_w
w = w_max
return max(w, nlen)


# ---- basic Columns
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/fixed_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def save_fixed(vd, p, *vsheets):
widths = {} # Column -> width:int
# headers
for col in Progress(sheet.visibleCols, gerund='sizing'):
widths[col] = col.getMaxWidth(sheet.rows) #1849
widths[col] = col.getMaxDataWidth(sheet.rows) #1849 #2255
fp.write(('{0:%s} ' % widths[col]).format(col.name))
fp.write('\n')

Expand Down

0 comments on commit e2d9550

Please sign in to comment.