mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
gh-119548: Add a 'clear' command to the REPL (#119549)
This commit is contained in:
parent
a531fd7fdb
commit
e3bac04c37
3 changed files with 12 additions and 1 deletions
|
@ -238,6 +238,7 @@ class Reader:
|
||||||
cxy: tuple[int, int] = field(init=False)
|
cxy: tuple[int, int] = field(init=False)
|
||||||
lxy: tuple[int, int] = field(init=False)
|
lxy: tuple[int, int] = field(init=False)
|
||||||
calc_screen: CalcScreen = field(init=False)
|
calc_screen: CalcScreen = field(init=False)
|
||||||
|
scheduled_commands: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
# Enable the use of `insert` without a `prepare` call - necessary to
|
# Enable the use of `insert` without a `prepare` call - necessary to
|
||||||
|
@ -557,6 +558,10 @@ class Reader:
|
||||||
self.restore()
|
self.restore()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
while self.scheduled_commands:
|
||||||
|
cmd = self.scheduled_commands.pop()
|
||||||
|
self.do_cmd((cmd, []))
|
||||||
|
|
||||||
def last_command_is(self, cls: type) -> bool:
|
def last_command_is(self, cls: type) -> bool:
|
||||||
if not self.last_command:
|
if not self.last_command:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -57,12 +57,17 @@ def _strip_final_indent(text: str) -> str:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def _clear_screen():
|
||||||
|
reader = _get_reader()
|
||||||
|
reader.scheduled_commands.append("clear_screen")
|
||||||
|
|
||||||
|
|
||||||
REPL_COMMANDS = {
|
REPL_COMMANDS = {
|
||||||
"exit": _sitebuiltins.Quitter('exit', ''),
|
"exit": _sitebuiltins.Quitter('exit', ''),
|
||||||
"quit": _sitebuiltins.Quitter('quit' ,''),
|
"quit": _sitebuiltins.Quitter('quit' ,''),
|
||||||
"copyright": _sitebuiltins._Printer('copyright', sys.copyright),
|
"copyright": _sitebuiltins._Printer('copyright', sys.copyright),
|
||||||
"help": "help",
|
"help": "help",
|
||||||
"clear": "clear_screen",
|
"clear": _clear_screen,
|
||||||
}
|
}
|
||||||
|
|
||||||
class InteractiveColoredConsole(code.InteractiveConsole):
|
class InteractiveColoredConsole(code.InteractiveConsole):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add a ``clear`` command to the REPL. Patch by Pablo Galindo
|
Loading…
Add table
Add a link
Reference in a new issue