Skip to content

Commit

Permalink
[api] vd.queueCommand can take input,sheet,row,col kwargs #1681
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 28, 2023
1 parent e9e2d69 commit 5f77e12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 0 additions & 8 deletions visidata/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@
class AcceptInput(Exception):
'*args[0]* is the input to be accepted'

visidata.vd._nextCommands = [] # for vd.queueCommand

vd._injectedInput = None # for vd.injectInput


@VisiData.api
def queueCommand(vd, longname): #, input=None, sheet=None, col=None, row=None):
'Add *longname* to queue of next commands to execute.'
vd._nextCommands.append(longname)


@VisiData.api
def injectInput(vd, x):
'Use *x* as input to next command.'
Expand Down
13 changes: 11 additions & 2 deletions visidata/cmdlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
vd.option('cmdlog_histfile', '', 'file to autorecord each cmdlog action to', sheettype=None)

vd.activeCommand = UNLOADED
vd._nextCommands = [] # list[str|CommandLogRow] for vd.queueCommand

CommandLogRow = namedlist('CommandLogRow', 'sheet col row longname input keystrokes comment undofuncs'.split())

@VisiData.api
def queueCommand(vd, longname, input=None, sheet=None, col=None, row=None):
'Add command to queue of next commands to execute.'
vd._nextCommands.append(CommandLogRow(longname=longname, input=input, sheet=sheet, col=col, row=row))


@VisiData.api
def open_vd(vd, p):
Expand Down Expand Up @@ -134,7 +143,7 @@ class CommandLogBase:
'Log of commands for current session.'
rowtype = 'logged commands'
precious = False
_rowtype = namedlist('CommandLogRow', 'sheet col row longname input keystrokes comment undofuncs'.split())
_rowtype = CommandLogRow
columns = [
ColumnAttr('sheet'),
ColumnAttr('col'),
Expand Down Expand Up @@ -469,7 +478,7 @@ def repeat_for_selected(cmdlog, r):
CommandLog.options.encoding = 'utf-8'
CommandLogJsonl.options.json_sort_keys = False

vd.addGlobals({"CommandLogBase": CommandLogBase})
vd.addGlobals(CommandLogBase=CommandLogBase, CommandLogRow=CommandLogRow)

vd.addMenuItems('''
View > Command log > this sheet > cmdlog-sheet
Expand Down

0 comments on commit 5f77e12

Please sign in to comment.