Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleo fails to detect ANSI support in Windows when run under a VT-native environment #104

Closed
TBBle opened this issue Aug 13, 2021 · 0 comments · Fixed by #313
Closed

cleo fails to detect ANSI support in Windows when run under a VT-native environment #104

TBBle opened this issue Aug 13, 2021 · 0 comments · Fixed by #313
Milestone

Comments

@TBBle
Copy link

TBBle commented Aug 13, 2021

This is a replication of sdispater/clikit#35, as the faulty code moved from clikit to cleo.

The current final test of StreamOutput._has_color_support on Windows: https://github.com/sdispater/cleo/blob/7ebf50b4c85e0eca2d9f295588150527c95c84de/cleo/io/outputs/stream_output.py#L141-L147

returns False if ENABLE_VIRTUAL_TERMINAL_PROCESSING is already enabled, as is the case for Windows Terminal.

It should return True, since if ENABLE_VIRTUAL_TERMINAL_PROCESSING is already enabled, then we clearly have ANSI.

I suggest flipping the logic to look like

 if (mode.value & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0: 
     return True

 return kernel32.SetConsoleMode( 
      h, mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING 
  ) != 0

so that if ENABLE_VIRTUAL_TERMINAL_PROCESSING is already set, the output stream is seen as ANSI-enabled, and otherwise, only report ANSI-enabled if successfully able to change modes.

This also fixes the issue that the return value of kernel32.SetConsoleMode is not being checked, although I'm not aware of a situation that would reject that particular call.

The user-visible behaviour issue is python-poetry/poetry#3354

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants