Skip to content

Commit

Permalink
[mouse-] click on error note to run error-cell
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Apr 15, 2024
1 parent 581cdf1 commit d0be22c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
10 changes: 10 additions & 0 deletions visidata/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')

Expand Down
2 changes: 2 additions & 0 deletions visidata/pyobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
20 changes: 17 additions & 3 deletions visidata/textsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
Expand Down

0 comments on commit d0be22c

Please sign in to comment.