Skip to content

Commit d2eab6f

Browse files
committed
feat: add clear_all function that clears screen and scrollback
1 parent fc0305a commit d2eab6f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Lib/_pyrepl/unix_console.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ def clear(self):
561561
self.posxy = 0, 0
562562
self.screen = []
563563

564+
def clear_all(self) -> None:
565+
"""Clear screen and scrollback buffer."""
566+
self.__write("\x1b[3J\x1b[2J\x1b[H")
567+
self.clear()
568+
564569
@property
565570
def input_hook(self):
566571
# avoid inline imports here so the repl doesn't get flooded

Lib/_pyrepl/windows_console.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, err: int | None, descr: str | None = None) -> None:
111111
MOVE_UP = "\x1b[{}A"
112112
MOVE_DOWN = "\x1b[{}B"
113113
CLEAR = "\x1b[H\x1b[J"
114+
CLEAR_ALL= "\x1b[3J\x1b[2J\x1b[H"
114115

115116
# State of control keys: https://learn.microsoft.com/en-us/windows/console/key-event-record-str
116117
ALT_ACTIVE = 0x01 | 0x02
@@ -516,6 +517,12 @@ def clear(self) -> None:
516517
self.posxy = 0, 0
517518
self.screen = [""]
518519

520+
521+
def clear_all(self) -> None:
522+
"""Clear screen and scrollback buffer."""
523+
self.__write(CLEAR_ALL)
524+
self.clear()
525+
519526
def finish(self) -> None:
520527
"""Move the cursor to the end of the display and otherwise get
521528
ready for end. XXX could be merged with restore? Hmm."""

0 commit comments

Comments
 (0)