command: partials

Support partial commands in console.command, use it to keybind "i" for
intercept, which prompts the user with ":set intercept=".
This commit is contained in:
Aldo Cortesi
2017-04-28 11:24:28 +12:00
parent 8a07059cf4
commit ce01cb9c09
4 changed files with 8 additions and 16 deletions

View File

@@ -56,7 +56,7 @@ def safecall():
try:
with contextlib.redirect_stdout(stdout_replacement):
yield
except exceptions.AddonHalt:
except (exceptions.AddonHalt, exceptions.OptionsError):
raise
except Exception as e:
etype, value, tb = sys.exc_info()

View File

@@ -83,9 +83,9 @@ class ConsoleCommands:
def __init__(self, master):
self.master = master
def command(self) -> None:
def command(self, partial: str) -> None:
"""Prompt for a command."""
signals.status_prompt_command.send()
signals.status_prompt_command.send(partial=partial)
def view_commands(self) -> None:
"""View the commands list."""
@@ -120,12 +120,13 @@ class ConsoleCommands:
def default_keymap(km):
km.add(":", "console.command")
km.add(":", "console.command ''")
km.add("?", "console.view.help")
km.add("C", "console.view.commands")
km.add("O", "console.view.options")
km.add("Q", "console.exit")
km.add("q", "console.view.pop")
km.add("i", "console.command 'set intercept='")
class ConsoleMaster(master.Master):

View File

@@ -82,15 +82,4 @@ class Window(urwid.Frame):
def keypress(self, size, k):
k = super().keypress(size, k)
k = self.master.keymap.handle("", k)
if not k:
return
elif k == "i":
signals.status_prompt.send(
self,
prompt = "Intercept filter",
text = self.master.options.intercept,
callback = self.master.options.setter("intercept")
)
else:
return k
return self.master.keymap.handle("", k)

View File

@@ -7,6 +7,8 @@ import pytest
def test_set():
sa = core.Core()
with taddons.context() as tctx:
tctx.master.addons.add(sa)
assert not tctx.master.options.anticomp
tctx.command(sa.set, "anticomp")
assert tctx.master.options.anticomp