Skip to content

Commit 9747560

Browse files
committed
Add clear internal command to clear screen based on
prompt-toolkit.shortcuts.clear function. Add ability to create "callable" internal commands
1 parent 2051d5f commit 9747560

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

click_repl/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import defaultdict
22
from prompt_toolkit.completion import Completer, Completion
33
from prompt_toolkit.history import InMemoryHistory
4-
from prompt_toolkit.shortcuts import prompt
4+
from prompt_toolkit.shortcuts import prompt, clear
55
import click
66
import click._bashcomplete
77
import click.parser
@@ -76,10 +76,15 @@ def _help_internal():
7676
return formatter.getvalue()
7777

7878

79+
def _clear_internal():
80+
return clear
81+
82+
7983
_register_internal_command(["q", "quit", "exit"], _exit_internal, "exits the repl")
8084
_register_internal_command(
8185
["?", "h", "help"], _help_internal, "displays general help information"
8286
)
87+
_register_internal_command(["c", "cls", "clear"], _clear_internal, "clears screen")
8388

8489

8590
class ClickCompleter(Completer):
@@ -234,6 +239,9 @@ def get_command():
234239
if isinstance(result, six.string_types):
235240
click.echo(result)
236241
continue
242+
if callable(result):
243+
result()
244+
continue
237245
except ExitReplException:
238246
break
239247

0 commit comments

Comments
 (0)