Skip to content

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

Closed

Description

@TBBle

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

Activity

  1. added this to the 2.1 milestone on Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions