Skip to content

Commit

Permalink
Add clear internal command to clear screen based on
Browse files Browse the repository at this point in the history
prompt-toolkit.shortcuts.clear function.
Add ability to create "callable" internal commands
  • Loading branch information
jm66 committed Sep 12, 2019
1 parent 2d78dc5 commit 92e6893
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion click_repl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.shortcuts import prompt, clear
import click
import click._bashcomplete
import click.parser
Expand Down Expand Up @@ -76,10 +76,15 @@ def _help_internal():
return formatter.getvalue()


def _clear_internal():
return clear


_register_internal_command(["q", "quit", "exit"], _exit_internal, "exits the repl")
_register_internal_command(
["?", "h", "help"], _help_internal, "displays general help information"
)
_register_internal_command(["c", "cls", "clear"], _clear_internal, "clears screen")


class ClickCompleter(Completer):
Expand Down Expand Up @@ -234,6 +239,9 @@ def get_command():
if isinstance(result, six.string_types):
click.echo(result)
continue
if callable(result):
result()
continue
except ExitReplException:
break

Expand Down

0 comments on commit 92e6893

Please sign in to comment.