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

Force color #2449

Merged
merged 8 commits into from Aug 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,8 +5,13 @@ 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).


## [Unreleased]

### Added

- Add support for `FORCE_COLOR` env var https://github.com/Textualize/rich/pull/2449

### Fixed

- Fix NO_COLOR support on legacy Windows https://github.com/Textualize/rich/pull/2458
Expand Down
7 changes: 6 additions & 1 deletion rich/console.py
Expand Up @@ -697,7 +697,12 @@ def __init__(
self._height = height

self._color_system: Optional[ColorSystem]
self._force_terminal = force_terminal

if force_terminal is not None:
self._force_terminal = force_terminal
else:
self._force_terminal = self._environ.get("FORCE_COLOR") is not None

self._file = file
self.quiet = quiet
self.stderr = stderr
Expand Down
8 changes: 8 additions & 0 deletions tests/test_console.py
Expand Up @@ -895,3 +895,11 @@ def test_render_lines_height_minus_vertical_pad_is_negative():

# Ensuring that no exception is raised...
console.render_lines(Padding("hello", pad=(1, 0)), options=options)


@mock.patch.dict(os.environ, {"FORCE_COLOR": "anything"})
def test_force_color():
# Even though we use a non-tty file, the presence of FORCE_COLOR env var
# means is_terminal returns True.
console = Console(file=io.StringIO())
assert console.is_terminal