Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Print ANSI Color reset on finish and restore
  • Loading branch information
edvilme committed Jun 24, 2026
commit 19fd3226d199a5fe938875dd401962dd78475ea4
4 changes: 4 additions & 0 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from fcntl import ioctl
from typing import TYPE_CHECKING, overload

from Lib._colorize import ANSIColors

from . import terminfo
from .console import Console, Event
from .fancy_termios import tcgetattr, tcsetattr, TermState
Expand Down Expand Up @@ -517,6 +519,7 @@ def restore(self) -> None:
Restore the console to the default state
"""
trace("unix.restore")
self.__write(ANSIColors.RESET)
self.__disable_bracketed_paste()
self.__maybe_write_code(self._rmkx)
self.flushoutput()
Expand Down Expand Up @@ -654,6 +657,7 @@ def finish(self):
while y >= 0 and not rendered_lines[y].text:
y -= 1
self.__move(0, min(y, self.height + self.__offset - 1))
self.__write(ANSIColors.RESET)
Comment thread
edvilme marked this conversation as resolved.
self.__write("\n\r")
self.flushoutput()

Expand Down
4 changes: 4 additions & 0 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
)
from ctypes import Structure, POINTER, Union
from typing import TYPE_CHECKING

from Lib._colorize import ANSIColors
from .console import Event, Console
from .render import (
EMPTY_RENDER_LINE,
Expand Down Expand Up @@ -480,6 +482,7 @@ def prepare(self) -> None:
def restore(self) -> None:
trace("windows.restore")
if self.__vt_support:
self.__write(ANSIColors.RESET)
# Recover to original mode before running REPL
self._disable_bracketed_paste()
if not SetConsoleMode(InHandle, self.__original_input_mode):
Expand Down Expand Up @@ -647,6 +650,7 @@ def finish(self) -> None:
while y >= 0 and not rendered_lines[y].text:
y -= 1
self._move_relative(0, min(y, self.height + self.__offset - 1))
self.__write(ANSIColors.RESET)
self.__write("\r\n")

def flushoutput(self) -> None:
Expand Down
Loading