Skip to content

Commit

Permalink
[vdrepl] touch up for newer vd versions
Browse files Browse the repository at this point in the history
- Add `onlySelectedRows` to the set of dummy locals to avoid some
  exceptions

- Avoid shadowing `vd` inside `openRepl`
  • Loading branch information
ajkerrigan committed Feb 7, 2024
1 parent bb0c8e6 commit 6821fb4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions plugins/vdrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@
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:
"""Hacks to patch sheet-local variables that we want the REPL to ignore."""

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:
Expand All @@ -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)
Expand Down

0 comments on commit 6821fb4

Please sign in to comment.