Skip to content

Commit ec87287

Browse files
committed
[features-] add command hide-uniform-cols
1 parent 136d671 commit ec87287

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

visidata/features/layout.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from visidata import VisiData, vd, Column, Sheet, Fanout
1+
from visidata import VisiData, vd, Column, Sheet, Fanout, asyncthread
22

33
@Column.api
44
def setWidth(self, w):
@@ -35,22 +35,35 @@ def hide_col(vd, col):
3535
if not col: vd.fail("no columns to hide")
3636
col.hide()
3737

38+
@Sheet.api
39+
@asyncthread
40+
def hide_uniform_cols(sheet):
41+
if len(sheet.rows) < 2:
42+
return
43+
for col in sheet.visibleCols:
44+
vals = (col.getTypedValue(r) for r in sheet.rows)
45+
first = next(vals)
46+
if all(v == first for v in vals):
47+
col.hide()
48+
3849
Sheet.addCommand('_', 'resize-col-max', 'if cursorCol: cursorCol.toggleWidth(cursorCol.getMaxWidth(visibleRows))', 'toggle width of current column between full and default width')
3950
Sheet.addCommand('z_', 'resize-col-input', 'width = int(input("set width= ", value=cursorCol.width)); cursorCol.setWidth(width)', 'adjust width of current column to N')
4051
Sheet.addCommand('g_', 'resize-cols-max', 'for c in visibleCols: c.setWidth(c.getMaxWidth(visibleRows))', 'toggle widths of all visible columns between full and default width')
4152
Sheet.addCommand('gz_', 'resize-cols-input', 'width = int(input("set width= ", value=cursorCol.width)); Fanout(visibleCols).setWidth(width)', 'adjust widths of all visible columns to N')
4253

4354
Sheet.addCommand('-', 'hide-col', 'hide_col(cursorCol)', 'hide the current column')
4455
Sheet.addCommand('z-', 'resize-col-half', 'cursorCol.setWidth(cursorCol.width//2)', 'reduce width of current column by half')
56+
Sheet.addCommand(None, 'hide-uniform-cols', 'sheet.hide_uniform_cols()', 'hide any column that has multiple rows but only one distinct value')
4557

4658
Sheet.addCommand('gv', 'unhide-cols', 'unhide_cols(columns, visibleRows)', 'unhide all hidden columns on current sheet')
4759
Sheet.addCommand('v', 'toggle-multiline', 'for c in visibleCols: c.toggleMultiline()', 'toggle multiline display')
4860
Sheet.addCommand('zv', 'resize-height-input', 'Fanout(visibleCols).height=int(input("set height for all columns to: ", value=max(c.height for c in sheet.visibleCols)))', 'resize row height to N')
4961
Sheet.addCommand('gzv', 'resize-height-max', 'h=calc_height(cursorRow, {}, maxheight=windowHeight-1); vd.status(f"set height for all columns to {h}"); Fanout(visibleCols).height=h', 'resize row height to max height needed to see this row')
5062

5163
vd.addMenuItems('''
52-
Column > Hide > hide-col
53-
Column > Unhide all > unhide-cols
64+
Column > Hide > Hide > hide-col
65+
Column > Hide > Hide uniform > hide-uniform-cols
66+
Column > Hide > Unhide all > unhide-cols
5467
Column > Resize > half width > resize-col-half
5568
Column > Resize > current column width to max > resize-col-max
5669
Column > Resize > current column width to N > resize-col-input

0 commit comments

Comments
 (0)