Skip to content

Commit ec24349

Browse files
committed
Suspend REPL colorizing when in a REPL interactive command
1 parent 800d37f commit ec24349

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/_pyrepl/reader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ def suspend(self) -> SimpleContextManager:
619619
setattr(self, arg, prev_state[arg])
620620
self.prepare()
621621

622+
@contextmanager
623+
def suspend_colorization(self) -> SimpleContextManager:
624+
try:
625+
old_can_colorize = self.can_colorize
626+
self.can_colorize = False
627+
yield
628+
finally:
629+
self.can_colorize = old_can_colorize
630+
631+
622632
def finish(self) -> None:
623633
"""Called when a command signals that we're finished."""
624634
pass

Lib/_pyrepl/simple_interact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def maybe_run_command(statement: str) -> bool:
125125
command = REPL_COMMANDS[statement]
126126
if callable(command):
127127
# Make sure that history does not change because of commands
128-
with reader.suspend_history():
128+
with reader.suspend_history(), reader.suspend_colorization():
129129
command()
130130
return True
131131
return False

0 commit comments

Comments
 (0)