Fixes issue #2606 by making color=True behavior agnostic of Operating System. #2731
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #2606 described a inconsistency in how color=True works between Operating Systems.
This is because ANSI styles can't always be applied to different terminals on windows. This did not cause issues when running it within the terminals because Colorama would change the ANSI style codes to escape codes for windows when it was required. However, if you were to pipe the
click.echo()
output to a file then theshould_strip_ansi
function would not work on Windows as the other operating systems.This is because the
auto_wrap_for_ansi
function was not being called with the color argument. After theauto_wrap_for_ansi
function is called, it defaultscolor=None
and will end up callingshould_strip_ansi
withcolor=None
which is different from the original call toshould_strip_ansi
that was called before the wrapper function.By passing color to
auto_wrap_for_ansi
, then the behavior ofshould_strip_ansi
becomes consistent.An additional change applied within the PR is to the tests in
test_utils.py
. This is to increase test coverage for the different cases ofclick.echo()
and removes the old version of the test. Instead of one test that mocksisatty()
, there are now three different tests. One that mocksisatty()=True
and_is_jupyter_kernel_output()=False
, another that mocksisatty()=False
and_is_jupyter_kernel_output()=True
, and the last one mocks bothisatty()=False
and_is_jupyter_kernel_output()=False
.fixes #2606
should fail without the change.