-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stream_output): respect
FORCE_COLOR
(#343)
- Loading branch information
1 parent
aefc890
commit af5eb92
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ANSI coloring detection now respects a `FORCE_COLOR` environment variable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
|
||
from io import StringIO | ||
|
||
import pytest | ||
|
||
from cleo.io.outputs.stream_output import StreamOutput | ||
|
||
|
||
@pytest.fixture() | ||
def stream() -> StringIO: | ||
return StringIO() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["env", "is_decorated"], | ||
[ | ||
({"NO_COLOR": "1"}, False), | ||
({"FORCE_COLOR": "1"}, True), | ||
], | ||
) | ||
def test_is_decorated_respects_environment( | ||
stream: StringIO, environ: None, env: dict[str, str], is_decorated: bool | ||
) -> None: | ||
os.environ.update(env) | ||
|
||
output = StreamOutput(stream) | ||
output.write_line("<fg=blue>FooBar</>") | ||
stream.seek(0) | ||
|
||
assert output.is_decorated() == is_decorated | ||
expected = "\x1b[34mFooBar\x1b[39m\n" if is_decorated else "FooBar\n" | ||
assert stream.read() == expected |