Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a ``clear`` command to the REPL. Patch by Pablo Galindo