tartley / colorama

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

Windows use case? #387

Closed JPHutchins closed 4 months ago

JPHutchins commented 4 months ago

Since Windows Terminal supports ANSI escapes, I am curious if colorama disables itself in use cases where it is redundant? Like it would for Linux, for example.

What exactly are the terminals on Windows that still require colorama?

I want to make sure that my packages have good compatibility but I'm not thrilled to support every ancient Windows console!

Thanks, JP

njsmith commented 4 months ago

Does this section of the docs answer your question clearly? If not can you suggest edits that would make it clearer?

https://github.com/tartley/colorama?tab=readme-ov-file#initialisation

On Sun, Apr 14, 2024, 12:13 JP Hutchins @.***> wrote:

Since Windows Terminal supports ANSI escapes, I am curious if colorama disables itself in use cases where it is redundant? Like it would for Linux, for example.

What exactly are the terminals on Windows that still require colorama?

I want to make sure that my packages have good compatibility but I'm not thrilled to support every ancient Windows console!

Thanks, JP

— Reply to this email directly, view it on GitHub https://github.com/tartley/colorama/issues/387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEU42EVMY7Y3PTZGFXK5YTY5LINTAVCNFSM6AAAAABGGJEHQCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DEMZRHE4DOMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

JPHutchins commented 4 months ago

Yes, thank you! It seems that in most cases the code will follow the path eventually to enable_vt_processing:

https://github.com/tartley/colorama/blob/136808718af8b9583cb2eed1756ed6972eda4975/colorama/winterm.py#L178-L195

This calls the Windows API defined here: https://learn.microsoft.com/en-us/windows/console/setconsolemode

In the vast majority of (modern) cases this is basically a no op because the terminal already has the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag set and colorama will not impact expected ANSI processing.