From d0be22c817cbb80101fda0a0296dc4210f2eadcd Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Mon, 15 Apr 2024 02:06:05 -0700 Subject: [PATCH] [mouse-] click on error note to run error-cell --- visidata/mouse.py | 10 ++++++++++ visidata/pyobj.py | 2 ++ visidata/textsheet.py | 20 +++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/visidata/mouse.py b/visidata/mouse.py index 838418bca..463eff2d1 100644 --- a/visidata/mouse.py +++ b/visidata/mouse.py @@ -114,6 +114,13 @@ def visibleColAtX(sheet, x): if colx <= x <= colx+w: return vcolidx +@Sheet.api +def isNoteAtX(sheet, ridx, vcolidx, mouse_x): + note_offset = 1 + colx, w = sheet._visibleColLayout[vcolidx] + if mouse_x == colx+w - note_offset: + return True + return False @Sheet.api def visibleRowAtY(sheet, y): @@ -130,6 +137,9 @@ def go_mouse(sheet): cidx = sheet.visibleColAtX(sheet.mouseX) if cidx is not None: sheet.cursorVisibleColIndex = cidx + if getattr(sheet.cursorCell, "error", None): + if sheet.isNoteAtX(ridx, cidx, sheet.mouseX): + sheet.exec_command('error-cell') Sheet.addCommand(None, 'scroll-mouse', 'sheet.topRowIndex=cursorRowIndex-mouseY+1', 'scroll to mouse cursor location') diff --git a/visidata/pyobj.py b/visidata/pyobj.py index 81c8546f8..58fd783da 100644 --- a/visidata/pyobj.py +++ b/visidata/pyobj.py @@ -279,6 +279,8 @@ def launch_repl(v, i): BaseSheet.addCommand('', 'assert-expr', 'expr=inputPythonExpr(); assert sheet.evalExpr(expr), f"{expr} not true"', 'eval Python expression and assert result is truthy') BaseSheet.addCommand('', 'assert-expr-row', 'expr=inputPythonExpr(); assert sheet.evalExpr(expr, row=cursorRow), f"{expr} not true"', 'eval Python expression in context of current row, and assert result is truthy') +Sheet.addCommand(None, 'view-cell', 'vd.push(openCellPyobj(cursorCol, cursorRowIndex))', 'view contents of current cell in a new sheet') + Sheet.addCommand('^Y', 'pyobj-row', 'status(type(cursorRow).__name__); vd.push(openRowPyobj(cursorRowIndex))', 'open current row as Python object') Sheet.addCommand('z^Y', 'pyobj-cell', 'status(type(cursorValue).__name__); vd.push(openCellPyobj(cursorCol, cursorRowIndex))', 'open current cell as Python object') BaseSheet.addCommand('g^Y', 'pyobj-sheet', 'status(type(sheet).__name__); vd.push(PyobjSheet(sheet.name+"_sheet", source=sheet))', 'open current sheet as Python object') diff --git a/visidata/textsheet.py b/visidata/textsheet.py index d0154395d..d8ff23dd4 100644 --- a/visidata/textsheet.py +++ b/visidata/textsheet.py @@ -55,8 +55,23 @@ def writelines(sheet, fn): # .source is list of source text lines to 'load' # .sourceSheet is Sheet error came from class ErrorSheet(TextSheet): + columns = [ + ColumnItem('linenum', 0, type=int, width=0), + ColumnItem('error', 1), + ] + guide = '''# Error Sheet''' precious = False +class ErrorCellSheet(ErrorSheet): + columns = [ + ColumnItem('linenum', 0, type=int, width=0), + ColumnItem('cell_error', 1), + ] + guide = '''# Error Cell Sheet +This sheet shows the error that occurred when calculating a cell. +- `q` to quit this error sheet. +''' + class ErrorsSheet(Sheet): columns = [ @@ -83,15 +98,14 @@ def recentErrorsSheet(self): BaseSheet.addCommand('^E', 'error-recent', 'vd.lastErrors and vd.push(recentErrorsSheet) or status("no error")', 'view traceback for most recent error') BaseSheet.addCommand('g^E', 'errors-all', 'vd.push(vd.allErrorsSheet)', 'view traceback for most recent errors') -Sheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet("%s[%s].%s" % (name, cursorRowIndex, cursorCol.name), sourceSheet=sheet, source=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet') -Sheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+"_cell_error", sourceSheet=sheet, source=getattr(cursorCell, "error", None) or fail("no error this cell")))', 'view traceback for error in current cell') +Sheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorCellSheet(sheet.name+"_cell_error", sourceSheet=sheet, source=getattr(cursorCell, "error", None) or fail("no error this cell")))', 'view traceback for error in current cell') TextSheet.addCommand('^O', 'sysopen-sheet', 'sheet.sysopen(sheet.cursorRowIndex)', 'open copy of text sheet in $EDITOR and reload on exit') TextSheet.options.save_filetype = 'txt' -vd.addGlobals({'TextSheet': TextSheet, 'ErrorSheet': ErrorSheet}) +vd.addGlobals({'TextSheet': TextSheet, 'ErrorSheet': ErrorSheet, 'ErrorCellSheet': ErrorCellSheet}) vd.addMenuItems(''' View > Errors > recent > error-recent