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

Use new API for Windows: colorama.just_fix_windows_console() #1394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

njsmith
Copy link

@njsmith njsmith commented Nov 21, 2022

tqdm uses colorama to enable proper ANSI support on Windows. Traditionally, it's done this by calling colorama.init. But this API is pretty awkward: it tries to do too much (e.g. guessing whether you have ANSI support and if not then installing sys.stdout/stderr filters that remove all ANSI codes from output -- even if the system actually does support ANSI!), and it isn't idempotent, so if multiple libraries all call colorama.init then you can get brokenness (in particular, it can trigger the situation where colorama thinks ANSI is unavailable, when it actually is!).

To solve this, colorama 0.4.6 added a new API,
colorama.just_fix_windows_console:
tartley/colorama#352

The advantage of this is that it does what it says: it just fixes the Windows console, without any strange side-effects, and it's safe to call multiple times. The colorama maintainers are
recommending that everyone switch to it.

tqdm uses colorama to enable proper ANSI support on Windows.
Traditionally, it's done this by calling `colorama.init`. But this API
is pretty awkward: it tries to do too much (e.g. guessing whether you
have ANSI support and if not then installing sys.stdout/stderr filters
that remove all ANSI codes from output -- even if the system actually
does support ANSI!), and it isn't idempotent, so if multiple libraries
all call `colorama.init` then you can get brokenness (in particular, it
can trigger the situation where colorama thinks ANSI is unavailable,
when it actually is!).

To solve this, colorama 0.4.6 added a new API,
`colorama.just_fix_windows_console`:
tartley/colorama#352

The advantage of this is that it does what it says: it just fixes the
Windows console, without any strange side-effects, and it's safe to call
multiple times.
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 this pull request may close these issues.

None yet

1 participant