From 5f77e12e23aaae5582a97139e1943bf0ca40c2a5 Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Fri, 27 Oct 2023 20:54:20 -0700 Subject: [PATCH] [api] vd.queueCommand can take input,sheet,row,col kwargs #1681 --- visidata/_input.py | 8 -------- visidata/cmdlog.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/visidata/_input.py b/visidata/_input.py index 8c4e2dc68..2b95b72ee 100644 --- a/visidata/_input.py +++ b/visidata/_input.py @@ -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.' diff --git a/visidata/cmdlog.py b/visidata/cmdlog.py index f80ef05ea..7d2d0201e 100644 --- a/visidata/cmdlog.py +++ b/visidata/cmdlog.py @@ -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): @@ -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'), @@ -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