Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Unreleased
:issue:`2705`
- Show correct value for flag default when using ``default_map``.
:issue:`2632`
- Fix ``click.echo(color=...)`` passing ``color`` to coloroma so it can be
forced on Windows. :issue:`2606`.


Version 8.1.7
Expand Down
2 changes: 1 addition & 1 deletion src/click/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def echo(
out = strip_ansi(out)
elif WIN:
if auto_wrap_for_ansi is not None:
file = auto_wrap_for_ansi(file) # type: ignore
file = auto_wrap_for_ansi(file, color) # type: ignore
elif not color:
out = strip_ansi(out)

Expand Down
18 changes: 11 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def cli():


def test_echo_custom_file():
import io

f = io.StringIO()
f = StringIO()
click.echo("hello", file=f)
assert f.getvalue() == "hello\n"

Expand Down Expand Up @@ -209,7 +207,6 @@ def test_echo_via_pager(monkeypatch, capfd, cat, test):
assert out == expected_output


@pytest.mark.skipif(WIN, reason="Test does not make sense on Windows.")
def test_echo_color_flag(monkeypatch, capfd):
isatty = True
monkeypatch.setattr(click._compat, "isatty", lambda x: isatty)
Expand All @@ -232,9 +229,16 @@ def test_echo_color_flag(monkeypatch, capfd):
assert out == f"{styled_text}\n"

isatty = False
click.echo(styled_text)
out, err = capfd.readouterr()
assert out == f"{text}\n"
# Faking isatty() is not enough on Windows;
# the implementation caches the colorama wrapped stream
# so we have to use a new stream for each test
stream = StringIO()
click.echo(styled_text, file=stream)
assert stream.getvalue() == f"{text}\n"

stream = StringIO()
click.echo(styled_text, file=stream, color=True)
assert stream.getvalue() == f"{styled_text}\n"


def test_prompt_cast_default(capfd, monkeypatch):
Expand Down