diff --git a/visidata/column.py b/visidata/column.py index 7bf448cf6..01d0d2274 100644 --- a/visidata/column.py +++ b/visidata/column.py @@ -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 diff --git a/visidata/loaders/fixed_width.py b/visidata/loaders/fixed_width.py index 9a215ba1c..295d83228 100644 --- a/visidata/loaders/fixed_width.py +++ b/visidata/loaders/fixed_width.py @@ -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')