Skip to content

Commit f88c250

Browse files
fix: resolve Windows terminal corruption after Ctrl+C interrupts
- Reorder reset operations to restore console mode before sending ANSI sequences - Add terminal reset at the start of each interactive loop iteration - Fix ANSI escape codes being printed as literal text on Windows - Ensure ENABLE_VIRTUAL_TERMINAL_PROCESSING is enabled before ANSI reset - Add detailed comments explaining critical ordering requirements for Windows terminal state
1 parent 4dc2c6b commit f88c250

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

code_puppy/cli_runner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non
421421
current_agent_task = None
422422

423423
while True:
424+
# Windows-specific: Aggressively reset terminal at the start of every loop
425+
# This fixes terminal corruption after Ctrl+C, especially when running via uvx
426+
reset_windows_terminal_full()
427+
424428
from code_puppy.agents.agent_manager import get_current_agent
425429
from code_puppy.messaging import emit_info
426430

code_puppy/terminal_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,20 @@ def reset_windows_console_mode() -> None:
8787

8888

8989
def reset_windows_terminal_full() -> None:
90-
"""Perform a full Windows terminal reset (ANSI + console mode).
90+
"""Perform a full Windows terminal reset (console mode + ANSI).
9191
92-
Combines both ANSI reset and console mode reset for complete
92+
Combines both console mode reset and ANSI reset for complete
9393
terminal state restoration after interrupts.
94+
95+
IMPORTANT: Console mode must be reset FIRST to re-enable
96+
ENABLE_VIRTUAL_TERMINAL_PROCESSING, otherwise the ANSI escape
97+
sequences will be printed as literal text (e.g., '[0m').
9498
"""
9599
if platform.system() != "Windows":
96100
return
97101

98-
reset_windows_terminal_ansi()
99-
reset_windows_console_mode()
102+
reset_windows_console_mode() # Must be first! Enables ANSI processing
103+
reset_windows_terminal_ansi() # Now ANSI escapes will be interpreted
100104

101105

102106
def reset_unix_terminal() -> None:

0 commit comments

Comments
 (0)