Skip to content

fix for is_terminal #2923

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

Merged
merged 3 commits into from
Apr 12, 2023
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [13.3.4] - 2023-04-12

### Fixed

- Fixed for `is_terminal` ignoring FORCE_COLOR https://github.com/Textualize/rich/pull/2923

## [13.3.3] - 2023-02-27

### Added
Expand Down Expand Up @@ -1930,6 +1936,8 @@ Major version bump for a breaking change to `Text.stylize signature`, which corr

- First official release, API still to be stabilized

[13.3.4]: https://github.com/textualize/rich/compare/v13.3.3...v13.3.4
[13.3.3]: https://github.com/textualize/rich/compare/v13.3.2...v13.3.3
[13.3.2]: https://github.com/textualize/rich/compare/v13.3.1...v13.3.2
[13.3.1]: https://github.com/textualize/rich/compare/v13.3.0...v13.3.1
[13.3.0]: https://github.com/textualize/rich/compare/v13.2.0...v13.3.0
Expand Down
2 changes: 1 addition & 1 deletion rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ def is_terminal(self) -> bool:
force_color = self._environ.get("FORCE_COLOR")
if force_color is not None:
self._force_terminal = True
return True

isatty: Optional[Callable[[], bool]] = getattr(self.file, "isatty", None)
try:
Expand Down Expand Up @@ -2000,7 +2001,6 @@ def _check_buffer(self) -> None:
self._record_buffer.extend(self._buffer[:])

if self._buffer_index == 0:

if self.is_jupyter: # pragma: no cover
from .jupyter import display

Expand Down
12 changes: 12 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,3 +979,15 @@ def test_force_color_jupyter():
file=io.StringIO(), _environ={"FORCE_COLOR": "1"}, force_jupyter=True
)
assert not console.is_terminal


def test_force_color():
console = Console(
file=io.StringIO(),
_environ={
"FORCE_COLOR": "1",
"TERM": "xterm-256color",
"COLORTERM": "truecolor",
},
)
assert console.color_system in ("truecolor", "windows")