tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.51k stars 249 forks source link

Support python-2.7 in enable_vt_processing #364

Closed donkopotamus closed 1 year ago

donkopotamus commented 1 year ago

This fixes an issue present in colorama-0.4.6 when run in python-2.7 on msys or git-bash terminals (such as mintty). In such a case the following error has been observed

  File "C:\...\.venv\lib\site-packages\click\core.py", line 950, in show_help
    echo(ctx.get_help(), color=ctx.color)
  File "C:\...\.venv\lib\site-packages\click\utils.py", line 267, in echo
    file = auto_wrap_for_ansi(file)
  File "C:\...\.venv\lib\site-packages\click\_compat.py", line 704, in auto_wrap_for_ansi
    ansi_wrapper = colorama.AnsiToWin32(stream, strip=strip)
  File "C:\...\.venv\lib\site-packages\colorama\ansitowin32.py", line 101, in __init__
    system_has_native_ansi = not on_windows or enable_vt_processing(fd)
  File "C:\...\.venv\lib\site-packages\colorama\winterm.py", line 183, in enable_vt_processing
    handle = get_osfhandle(fd)
IOError: [Errno 9] Bad file descriptor

Note that this does not occur in python-3, as in such a case an IOError is really an OSError and is then caught.

njsmith commented 1 year ago

Doh, I forgot about that. Thanks for the catch!