Skip to content

Commit

Permalink
Clearing the screen using the ctrl-L keyboard shortcut instead of 'cl…
Browse files Browse the repository at this point in the history
…ear' (#237)

* Clearing the screen using the ctrl-L keyboard shortcut instead of 'clear'

Signed-off-by: Dvir Bechor <[email protected]>

* Update authors and changelog

---------

Signed-off-by: Dvir Bechor <[email protected]>
Co-authored-by: Steven Loria <[email protected]>
  • Loading branch information
DvirB10 and sloria authored Jan 9, 2024
1 parent f764f6b commit e0dde32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Contributors (chronological)
- Tim Gates `@timgates42 <https://github.com/timgates42>`_
- Matan Rosenberg `@matan129 <https://github.com/matan129>`_
- Matthias Maennich `@metti <https://github.com/metti>`_
- Dvir Bechor `@DvirB10 <https://github.com/DvirB10>`_

4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions doitlive/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ESC = "\x1b"
BACKSPACE = "\x7f"
CTRLC = "\x03"
CTRLL = "\x0C"
CTRLZ = "\x1a"
TAB = "\x09"
RETURNS = {"\r", "\n"}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e0dde32

Please sign in to comment.