Skip to content

Commit

Permalink
Can now look up the word: 'help' in dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Rider committed Apr 1, 2021
1 parent 0263a49 commit dbeb99a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
30 changes: 1 addition & 29 deletions plover_console_ui/commander.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from prompt_toolkit.buffer import Buffer

from .commands import Command, UnsupportedCommand
from .commands import UnsupportedCommand


def peek(list):
Expand All @@ -9,28 +8,12 @@ def peek(list):
return None


class Help(Command):
def __init__(self, commander) -> None:
self.commander = commander
super().__init__("help", commander.output)

def handle(self, words=None):
handler = self.commander.current_handler()
handler.describe()
return True


def build_meta_commands(commander):
return [Help(commander)]


class Commander:
def __init__(self, top_command, output) -> None:
self.top_command = top_command
self.output = output
self.on_exit_state = None
self.state = []
self.meta_commands = build_meta_commands(self)

def __call__(self, buff: Buffer):
try:
Expand Down Expand Up @@ -75,9 +58,6 @@ def handle_command(self, words):
self.state.pop()
return

if self.handled_meta_command(words):
return

local_state = self.state[:]
handler = self.current_handler()

Expand All @@ -99,13 +79,5 @@ def handle_command(self, words):
if not handler.handle(words):
self.state = local_state

def handled_meta_command(self, words):
possible_meta = peek(words)
for meta in self.meta_commands:
if meta.name.lower().startswith(possible_meta.lower()):
meta.handle(words)
return True
return False

def prompt(self):
return " ".join(self.state) + "> "
3 changes: 3 additions & 0 deletions plover_console_ui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def sub_commands(self):

def handle(self, words=[]):
if words:
if words[0].lower().startswith("help"):
self.describe()
return True
raise UnsupportedCommand()
else:
self.describe()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = plover_console_ui
version = 1.1.0
version = 1.1.1
description = Text User Interface for Plover
long_description = file: README.rst
author = Seth Rider
Expand Down

0 comments on commit dbeb99a

Please sign in to comment.