https://github.com/python/cpython/commit/e3bac04c37f6823cebc74d97feae0e0c25818b31
commit: e3bac04c37f6823cebc74d97feae0e0c25818b31
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2024-05-25T16:15:54Z
summary:
gh-119548: Add a 'clear' command to the REPL (#119549)
files:
A Misc/NEWS.d/next/Core and
Builtins/2024-05-25-16-45-27.gh-issue-119548.pqF9Y6.rst
M Lib/_pyrepl/reader.py
M Lib/_pyrepl/simple_interact.py
diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index 81df0c925ee6cb..d2960bbb6121b3 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -238,6 +238,7 @@ class Reader:
cxy: tuple[int, int] = field(init=False)
lxy: tuple[int, int] = field(init=False)
calc_screen: CalcScreen = field(init=False)
+ scheduled_commands: list[str] = field(default_factory=list)
def __post_init__(self) -> None:
# Enable the use of `insert` without a `prepare` call - necessary to
@@ -557,6 +558,10 @@ def prepare(self) -> None:
self.restore()
raise
+ while self.scheduled_commands:
+ cmd = self.scheduled_commands.pop()
+ self.do_cmd((cmd, []))
+
def last_command_is(self, cls: type) -> bool:
if not self.last_command:
return False
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 8ab4dab757685e..975533a425be23 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -57,12 +57,17 @@ def _strip_final_indent(text: str) -> str:
return text
+def _clear_screen():
+ reader = _get_reader()
+ reader.scheduled_commands.append("clear_screen")
+
+
REPL_COMMANDS = {
"exit": _sitebuiltins.Quitter('exit', ''),
"quit": _sitebuiltins.Quitter('quit' ,''),
"copyright": _sitebuiltins._Printer('copyright', sys.copyright),
"help": "help",
- "clear": "clear_screen",
+ "clear": _clear_screen,
}
class InteractiveColoredConsole(code.InteractiveConsole):
diff --git a/Misc/NEWS.d/next/Core and
Builtins/2024-05-25-16-45-27.gh-issue-119548.pqF9Y6.rst b/Misc/NEWS.d/next/Core
and Builtins/2024-05-25-16-45-27.gh-issue-119548.pqF9Y6.rst
new file mode 100644
index 00000000000000..0318790d46f0a3
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and
Builtins/2024-05-25-16-45-27.gh-issue-119548.pqF9Y6.rst
@@ -0,0 +1 @@
+Add a ``clear`` command to the REPL. Patch by Pablo Galindo
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]