From 974756053c2d291a2c7321fa2c3c00d354e8d2b4 Mon Sep 17 00:00:00 2001 From: JM Lopez Date: Thu, 12 Sep 2019 13:20:43 -0400 Subject: [PATCH] Add clear internal command to clear screen based on prompt-toolkit.shortcuts.clear function. Add ability to create "callable" internal commands --- click_repl/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/click_repl/__init__.py b/click_repl/__init__.py index 5000020..8b7b0da 100644 --- a/click_repl/__init__.py +++ b/click_repl/__init__.py @@ -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 @@ -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): @@ -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