Skip to content

Commit

Permalink
[errors-] make ErrorSheet/ErrorsSheet into singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Jan 16, 2025
1 parent 70699c1 commit 6a70257
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions visidata/textsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def sysopen_error(self, col, row):
vd.launchEditor(match.group(1), f'+{match.group(2)}')
return

def reload(self):
if vd.lastErrors:
self.rows = list(enumerate(vd.lastErrors[-1]))

class ErrorCellSheet(ErrorSheet):
columns = [
Expand All @@ -102,23 +105,22 @@ class ErrorsSheet(Sheet):
ColumnItem('lastline', -1)
]
def reload(self):
self.rows = self.source
self.rows = vd.lastErrors

def openRow(self, row):
return ErrorSheet(source=self.cursorRow)

@VisiData.property
@VisiData.lazy_property
def allErrorsSheet(self):
return ErrorsSheet("errors_all", source=vd.lastErrors)
return ErrorsSheet("errors_all")

@VisiData.property
@VisiData.lazy_property
def recentErrorsSheet(self):
error = vd.lastErrors[-1] if vd.lastErrors else ''
return ErrorSheet("errors_recent", source=error)
return ErrorSheet("errors_recent")



BaseSheet.addCommand('^E', 'error-recent', 'vd.push(recentErrorsSheet) if vd.lastErrors else status("no error")', 'view traceback for most recent error')
BaseSheet.addCommand('^E', 'error-recent', 'recentErrorsSheet.reload(); vd.push(recentErrorsSheet) if vd.lastErrors else 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('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')
Expand Down

0 comments on commit 6a70257

Please sign in to comment.