@@ -216,6 +216,45 @@ def set_terminal_title(title: str) -> None:
216216 pass
217217
218218
219+ def enable_windows_vt_mode () -> bool :
220+ """
221+ Enable Virtual Terminal Processing on Windows.
222+
223+ This allows ANSI escape codes to work in standard cmd.exe and PowerShell
224+ without needing an external library like colorama for every print.
225+ """
226+ if sys .platform != "win32" :
227+ return True
228+
229+ try :
230+ import ctypes
231+
232+ kernel32 = ctypes .windll .kernel32
233+
234+ # Get handle to stdout
235+ # STD_OUTPUT_HANDLE = -11
236+ handle = kernel32 .GetStdHandle (- 11 )
237+
238+ # Get current mode
239+ mode = ctypes .c_ulong ()
240+ if not kernel32 .GetConsoleMode (handle , ctypes .byref (mode )):
241+ return False
242+
243+ # Add ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x0004)
244+ enable_virtual_terminal_processing = 0x0004
245+ if not (mode .value & enable_virtual_terminal_processing ):
246+ if kernel32 .SetConsoleMode (
247+ handle , mode .value | enable_virtual_terminal_processing
248+ ):
249+ return True
250+ return False
251+
252+ return True
253+ except Exception :
254+ # If we can't enable it, functionality degrades gracefully
255+ return False
256+
257+
219258def setup_readline_history () -> Optional [Path ]:
220259 """
221260 Setup readline command history with persistence.
@@ -1282,6 +1321,9 @@ def run(self):
12821321
12831322def main ():
12841323 """Main entry point for the chat loop."""
1324+ # Ensure Windows console supports ANSI colors
1325+ enable_windows_vt_mode ()
1326+
12851327 parser = argparse .ArgumentParser (
12861328 description = (
12871329 "Interactive CLI for AI Agents with token tracking and rich features"
0 commit comments