Skip to content

Commit

Permalink
Merge pull request #2449 from Textualize/force-color
Browse files Browse the repository at this point in the history
Force color
  • Loading branch information
willmcgugan committed Aug 17, 2022
2 parents 5d3f600 + 193266c commit b8a2cf0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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

0 comments on commit b8a2cf0

Please sign in to comment.