Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@VisiData.global_api
def warning(vd, s):
vd.status(s, priority=1)
@VisiData.lazy_property
def statusHistory(vd):
return list() # list of [priority, statusmsg, repeats] for all status messages ever
@VisiData.property
def allErrorsSheet(self):
return ErrorSheet("errors_all", lines=sum(vd.lastErrors, []))
@VisiData.api
def addcol_expr(vd, sheet, colidx):
try:
c = sheet.addColumn(ColumnExpr("", width=options.default_width), index=colidx)
oldidx = sheet.cursorVisibleColIndex
sheet.cursorVisibleColIndex = sheet.visibleCols.index(c)
expr = sheet.editCell(sheet.cursorVisibleColIndex, -1,
completer=CompleteExpr(sheet),
updater=lambda val,col=c: col.updateExpr(val))
c.expr = expr or fail("no expr")
c.name = expr
c.width = None
except (Exception, EscapeException):
sheet.columns.remove(c)
sheet.cursorVisibleColIndex = oldidx
@VisiData.api
def __call__(vd):
'Deprecated; use plain "vd"'
return vd
@VisiData.global_api
def confirm(vd, prompt, exc=ExpectedException):
yn = vd.input(prompt, value='no', record=False)[:1]
if not yn or yn not in 'Yy':
if exc:
raise exc('disconfirmed')
warning('disconfirmed')
return False
return True
@VisiData.lazy_property
def allSheetsSheet(vd):
return SheetsSheet("sheets_all", source=vd.allSheets)
@VisiData.api
def addUndoSetValues(vd, cols, rows):
oldvals = [(c, r, c.getValue(r)) for c,r in itertools.product(cols, vd.Progress(rows, gerund='doing'))]
def _undo():
for c, r, v in oldvals:
c.setValue(r, v)
vd.addUndo(_undo)
@VisiData.api
def getSheet(vd, sheetname):
matchingSheets = [x for x in vd.sheets if x.name == sheetname]
if matchingSheets:
if len(matchingSheets) > 1:
vd.status('more than one sheet named "%s"' % sheetname)
return matchingSheets[0]
try:
sheetidx = int(sheetname)
return vd.sheets[sheetidx]
except ValueError:
pass
if sheetname == 'options':
vs = self.optionsSheet
vs.reload()
@VisiData.api
def draw(self, scr, *sheets):
'Redraw full screen.'
for sheet in sheets:
sheet._scr = scr
try:
sheet.draw(scr)
except Exception as e:
self.exceptionCaught(e)
self.drawLeftStatus(scr, sheets[0])
self.drawRightStatus(scr, sheets[0]) # visible during this getkeystroke