From 6821fb430cad8952b5e1449929ff05d4b204674a Mon Sep 17 00:00:00 2001 From: AJ Kerrigan Date: Wed, 7 Feb 2024 01:03:06 -0500 Subject: [PATCH] [vdrepl] touch up for newer vd versions - Add `onlySelectedRows` to the set of dummy locals to avoid some exceptions - Avoid shadowing `vd` inside `openRepl` --- plugins/vdrepl.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/vdrepl.py b/plugins/vdrepl.py index 0a7e03b..c37b1bf 100644 --- a/plugins/vdrepl.py +++ b/plugins/vdrepl.py @@ -5,7 +5,7 @@ from pathlib import Path from ptpython.ipython import InteractiveShellEmbed, embed -from visidata import LazyChainMap, Sheet, SuspendCurses, VisiData, vd +from visidata import LazyChainMap, Sheet, SuspendCurses, VisiData class Dummy: @@ -13,18 +13,15 @@ class Dummy: replayStatus = "dummy" someSelectedRows = "dummy" + onlySelectedRows = "dummy" @VisiData.api -def openRepl(self): +def openRepl(vd): """Open a ptipython-based REPL that inherits VisiData's context.""" - try: - # Provide local top-level access to VisiData global and sheet-local - # variables, similar to VisiData's `execCommand` context. - new_locals = LazyChainMap(Dummy(), vd, vd.sheet) - locals().update(new_locals) - except Exception as e: - vd.exceptionCaught(e) + + def configure(python_input): + python_input.title = "VisiData IPython REPL (ptipython)" with SuspendCurses(): try: @@ -35,12 +32,12 @@ def openRepl(self): / "history" ) Path.mkdir(history_file.parent, parents=True, exist_ok=True) + locals().update(dict(LazyChainMap(Dummy(), vd.sheet, locals=vd.getGlobals()))) shell = InteractiveShellEmbed.instance( history_filename=str(history_file), vi_mode=True, + configure=configure, ) - shell.python_input.title = "VisiData IPython REPL (ptipython)" - shell.python_input.show_exit_confirmation = False embed() except Exception as e: vd.exceptionCaught(e)