|
1 |
| -from visidata import VisiData, vd, Column, Sheet, Fanout |
| 1 | +from visidata import VisiData, vd, Column, Sheet, Fanout, asyncthread |
2 | 2 |
|
3 | 3 | @Column.api
|
4 | 4 | def setWidth(self, w):
|
@@ -35,22 +35,35 @@ def hide_col(vd, col):
|
35 | 35 | if not col: vd.fail("no columns to hide")
|
36 | 36 | col.hide()
|
37 | 37 |
|
| 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 | + |
38 | 49 | Sheet.addCommand('_', 'resize-col-max', 'if cursorCol: cursorCol.toggleWidth(cursorCol.getMaxWidth(visibleRows))', 'toggle width of current column between full and default width')
|
39 | 50 | Sheet.addCommand('z_', 'resize-col-input', 'width = int(input("set width= ", value=cursorCol.width)); cursorCol.setWidth(width)', 'adjust width of current column to N')
|
40 | 51 | 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')
|
41 | 52 | 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')
|
42 | 53 |
|
43 | 54 | Sheet.addCommand('-', 'hide-col', 'hide_col(cursorCol)', 'hide the current column')
|
44 | 55 | 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') |
45 | 57 |
|
46 | 58 | Sheet.addCommand('gv', 'unhide-cols', 'unhide_cols(columns, visibleRows)', 'unhide all hidden columns on current sheet')
|
47 | 59 | Sheet.addCommand('v', 'toggle-multiline', 'for c in visibleCols: c.toggleMultiline()', 'toggle multiline display')
|
48 | 60 | 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')
|
49 | 61 | 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')
|
50 | 62 |
|
51 | 63 | 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 |
54 | 67 | Column > Resize > half width > resize-col-half
|
55 | 68 | Column > Resize > current column width to max > resize-col-max
|
56 | 69 | Column > Resize > current column width to N > resize-col-input
|
|
0 commit comments