Skip to content

Commit

Permalink
Merge pull request #2381 from midichef/error_note_click
Browse files Browse the repository at this point in the history
[mouse-] click on error note to run error-cell
  • Loading branch information
anjakefala committed Jul 1, 2024
2 parents 90d3409 + fbd06c8 commit 173285c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions visidata/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def getCell(self, row):
dispval = options.disp_error_val
return DisplayWrapper(cellval.val, error=exc.stacktrace,
text=dispval,
note=options.disp_note_getexc,
note=f'[:onclick error-cell]{options.disp_note_getexc}[:]',
notecolor='color_error')
elif typedval.val is None: # early out for strict None
return DisplayWrapper(None, text='', # force empty display for None
Expand All @@ -377,12 +377,12 @@ def getCell(self, row):
elif isinstance(typedval, TypedExceptionWrapper): # calc succeeded, type failed
return DisplayWrapper(typedval.val, text=str(cellval),
error=typedval.stacktrace,
note=options.disp_note_typeexc,
note=f'[:onclick error-cell]{options.disp_note_typeexc}[:]',
notecolor='color_warning')
else:
return DisplayWrapper(typedval.val, text=str(typedval.val),
error=['unknown'],
note=options.disp_note_typeexc,
note=f'[:onclick error-cell]{options.disp_note_typeexc}[:]',
notecolor='color_warning')

elif isinstance(typedval, threading.Thread):
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 173285c

Please sign in to comment.