How to use the visidata.Sheet.api function in visidata

To help you get started, we’ve selected a few visidata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saulpw / visidata / plugins / defermods.py View on Github external
@Sheet.api
def putChanges(sheet, path, adds, changes, deletes):
    'Commit changes to path.  adds/changes/deletes are a diffset to apply to the last load from or commit to path.  By default this overwrites completely, saving as filetype to path, with filetype from path ext.'
    sheet.commitAdds()
    sheet.commitMods()
    sheet.commitDeletes()
    if sheet.defermods:
        saveSheets(path, sheet, confirm_overwrite=False)
    else:
        saveSheets(inputPath("save to: ", value=sheet.getDefaultSaveName()), sheet, confirm_overwrite=options.confirm_overwrite)

    # clear after save, to ensure cstr (in commit()) is aware of deletes
    # specifically, for the case where deletes are committed automatically (defermods = False)
    sheet._deferredDels.clear()
github saulpw / visidata / plugins / defermods.py View on Github external
@Sheet.api
def _dm_reset(sheet, *rows):
    sheet._deferredAdds.clear()
    sheet._deferredMods.clear()
    sheet._deferredDels.clear()
github saulpw / visidata / plugins / defermods.py View on Github external
@Sheet.api
def addSourceRow(self, row):
    'Add given row to source. row has already been added to .rows'
    pass
github saulpw / visidata / visidata / saving.py View on Github external
@Sheet.api
def deleteSourceRow(self, row):
    'Delete given row from source. row has already been removed from .rows'
    pass
github saulpw / visidata / visidata / sort.py View on Github external
@Sheet.api
@asyncthread
def sort(self):
    'Sort rows according to the current self._ordering.'
    try:
        with Progress(gerund='sorting', total=self.nRows) as prog:
            def sortkey(r):
                ret = []
                for col, reverse in self._ordering:
                    if isinstance(col, str):
                        col = self.column(col)
                    val = col.getTypedValue(r)
                    ret.append(Reversor(val) if reverse else val)

                prog.addProgress(1)
                return ret
github saulpw / visidata / visidata / saving.py View on Github external
@Sheet.api
def deleteRows(self, rows):
    for r in rows:
        self.markDeleted(r)

    if not self.defer:
        self.commitDeletes()
github saulpw / visidata / plugins / geocoding.py View on Github external
@Sheet.api
def geocode_col(sheet, vcolidx):
    col = sheet.visibleCols[vcolidx]

    for c in [
        Column('geocodes',
            origCol=col, # contract-col will replace with origCol
            cache='async',  # may take an indefinite time, so calc async and cache
            getter=lambda c,r: geocode(c.origCol.getDisplayValue(r))),

        # async caching above means dependent columns below should not cache (or they will cache in-progress errors)
        ColumnExpr('lat', origCol=col, cache=False, expr='geocodes[0]["latitude"]'),
        ColumnExpr('long', origCol=col, cache=False, expr='geocodes[0]["longitude"]'),
            ]:
        sheet.addColumn(c, index=vcolidx+1)
github saulpw / visidata / plugins / defermods.py View on Github external
@Sheet.api
def undoMod(self, row):
    rowid = self.rowid(row)

    if rowid in self._deferredMods:
        del col._deferredMods[rowid]

    if rowid in self._deferredDels:
        del self._deferredDels[rowid]

    if rowid in self._deferredAdds:
        del self._deferredAdds[rowid]
github saulpw / visidata / visidata / _input.py View on Github external
@Sheet.api
def editCell(self, vcolidx=None, rowidx=None, value=None, **kwargs):
    'Call `editText` at its place on the screen.  Returns the new value, properly typed'

    if vcolidx is None:
        vcolidx = self.cursorVisibleColIndex
    x, w = self.visibleColLayout.get(vcolidx, (0, 0))

    col = self.visibleCols[vcolidx]
    if rowidx is None:
        rowidx = self.cursorRowIndex

    if rowidx < 0:  # header
        y = 0
        value = value or col.name
    else:
        y, h = self.rowLayout.get(rowidx, (0, 0))
github saulpw / visidata / plugins / defermods.py View on Github external
@Sheet.api
def commitAdds(self):
    nadded = 0
    for row in self._deferredAdds.values():
        try:
            self.addSourceRow(row)
            nadded += 1
        except Exception as e:
            exceptionCaught(e)

    if nadded:
        status('added %s %s' % (nadded, self.rowtype))

    self._deferredAdds.clear()
    return nadded