From 3e56cf7698fec12936920d7ae00ecd78ddf8c1c9 Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Mon, 17 Jul 2023 03:08:05 -0700 Subject: [PATCH 1/2] [layout-] stop errors: hide-col on empty sheet, inputMultiple() --- visidata/_input.py | 2 +- visidata/features/layout.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/visidata/_input.py b/visidata/_input.py index 15dd7ba62..7602d5853 100644 --- a/visidata/_input.py +++ b/visidata/_input.py @@ -388,7 +388,7 @@ def _throw(v, i): for k, v in kwargs.items(): promptlen = clipdraw(sheet._scr, y-v.get('dy'), 0, v.get('prompt'), attr, w=sheet.windowWidth-1) #1947 - promptlen = clipdraw(sheet._scr, y-v.get('dy'), promptlen, v.get('value'), attr, w=sheet.windowWidth-1) + promptlen = clipdraw(sheet._scr, y-v.get('dy'), promptlen, v.get('value', ''), attr, w=sheet.windowWidth-1) try: input_kwargs = kwargs[cur_input_key] diff --git a/visidata/features/layout.py b/visidata/features/layout.py index f4407c1b0..f03b9212c 100644 --- a/visidata/features/layout.py +++ b/visidata/features/layout.py @@ -36,7 +36,7 @@ def unhide_cols(vd, cols, rows): 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') 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') -Sheet.addCommand('-', 'hide-col', 'cursorCol.hide()', 'Hide current column') +Sheet.addCommand('-', 'hide-col', 'if cursorCol: cursorCol.hide()', 'Hide current column') Sheet.addCommand('z-', 'resize-col-half', 'cursorCol.setWidth(cursorCol.width//2)', 'reduce width of current column by half') Sheet.addCommand('gv', 'unhide-cols', 'unhide_cols(columns, visibleRows)', 'Show all columns') From a3235719944b7669031a0cdec4031b0af138bf2b Mon Sep 17 00:00:00 2001 From: anjakefala Date: Wed, 26 Jul 2023 18:51:57 -0700 Subject: [PATCH 2/2] [layout-] fail if hide-col on empty sheet --- visidata/features/layout.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/visidata/features/layout.py b/visidata/features/layout.py index f03b9212c..a1bd64b38 100644 --- a/visidata/features/layout.py +++ b/visidata/features/layout.py @@ -30,13 +30,17 @@ def unhide_cols(vd, cols, rows): for c in cols: c.setWidth(abs(c.width or 0) or c.getMaxWidth(rows)) +@VisiData.api +def hide_col(vd, col): + if not col: vd.fail("no columns to hide") + col.hide() Sheet.addCommand('_', 'resize-col-max', 'cursorCol.toggleWidth(cursorCol.getMaxWidth(visibleRows))', 'toggle width of current column between full and default width') Sheet.addCommand('z_', 'resize-col-input', 'width = int(input("set width= ", value=cursorCol.width)); cursorCol.setWidth(width)', 'adjust width of current column to N') 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') 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') -Sheet.addCommand('-', 'hide-col', 'if cursorCol: cursorCol.hide()', 'Hide current column') +Sheet.addCommand('-', 'hide-col', 'hide_col(cursorCol)', 'Hide current column') Sheet.addCommand('z-', 'resize-col-half', 'cursorCol.setWidth(cursorCol.width//2)', 'reduce width of current column by half') Sheet.addCommand('gv', 'unhide-cols', 'unhide_cols(columns, visibleRows)', 'Show all columns')