diff --git a/AUTHORS.rst b/AUTHORS.rst index 4b6474a..9ac6858 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -23,4 +23,5 @@ Contributors (chronological) - Tim Gates `@timgates42 `_ - Matan Rosenberg `@matan129 `_ - Matthias Maennich `@metti `_ +- Dvir Bechor `@DvirB10 `_ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fd15c7e..fecde7d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,10 @@ Changelog 5.0.0 (unreleased) ****************** +Features: + +* Ctrl-l clears the screen (:issue:`217`, :pr:`237`). Thanks :user:`Kaligule` for the suggestion and :user:`DvirB10` for the PR. + Support: * Drop support for Python 2 (:issue:`202`), Python 3.6, Python 3.7, IPython 5, IPython 6, IPython 7, and click<8. diff --git a/doitlive/keyboard.py b/doitlive/keyboard.py index f0b3dac..aa3314e 100644 --- a/doitlive/keyboard.py +++ b/doitlive/keyboard.py @@ -15,6 +15,7 @@ ESC = "\x1b" BACKSPACE = "\x7f" CTRLC = "\x03" +CTRLL = "\x0C" CTRLZ = "\x1a" TAB = "\x09" RETURNS = {"\r", "\n"} @@ -45,6 +46,11 @@ def magictype(text, prompt_template="default", speed=1): if in_char in {ESC, CTRLC}: echo(carriage_return=True) raise click.Abort() + elif in_char == CTRLL: + click.clear() + echo_prompt(prompt_template) + cursor_position = 0 + continue elif in_char == TAB: return_to_regular_type = True break @@ -145,6 +151,11 @@ def regulartype(prompt_template="default"): if in_char in {ESC, CTRLC}: echo(carriage_return=True) raise click.Abort() + elif in_char == CTRLL: + click.clear() + echo_prompt(prompt_template) + cursor_position = 0 + continue elif in_char == TAB: echo("\r", nl=True) return in_char