diff --git a/CHANGELOG.md b/CHANGELOG.md index 72c18cfe7..8cb38c28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +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 - Parse ANSI escape sequences in pretty repr https://github.com/Textualize/rich/pull/2470 +- Add support for `FORCE_COLOR` env var https://github.com/Textualize/rich/pull/2449 ### Fixed diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 83125eab7..766654b9f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -34,6 +34,7 @@ The following people have contributed to the development of Rich: - [Kylian Point](https://github.com/p0lux) - [Kyle Pollina](https://github.com/kylepollina) - [Sebastián Ramírez](https://github.com/tiangolo) +- [Felipe Guedes](https://github.com/guedesfelipe) - [Clément Robert](https://github.com/neutrinoceros) - [Brian Rutledge](https://github.com/bhrutledge) - [Tushar Sadhwani](https://github.com/tusharsadhwani) diff --git a/rich/console.py b/rich/console.py index 4f4675b10..4a3ebb559 100644 --- a/rich/console.py +++ b/rich/console.py @@ -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 diff --git a/rich/progress.py b/rich/progress.py index ac1c11f21..679731a15 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -129,7 +129,7 @@ def track( refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". - finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.done". + finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1. disable (bool, optional): Disable display of progress. @@ -315,7 +315,7 @@ def wrap_file( refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". - finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.done". + finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". disable (bool, optional): Disable display of progress. Returns: @@ -440,7 +440,7 @@ def open( refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". - finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.done". + finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". disable (bool, optional): Disable display of progress. encoding (str, optional): The encoding to use when reading in text mode. @@ -634,7 +634,7 @@ class BarColumn(ProgressColumn): bar_width (Optional[int], optional): Width of bar or None for full width. Defaults to 40. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". - finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.done". + finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". """ diff --git a/rich/progress_bar.py b/rich/progress_bar.py index 9c3a4f25a..67361df2e 100644 --- a/rich/progress_bar.py +++ b/rich/progress_bar.py @@ -25,7 +25,7 @@ class ProgressBar(JupyterMixin): pulse (bool, optional): Enable pulse effect. Defaults to False. Will pulse if a None total was passed. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". - finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.done". + finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". animation_time (Optional[float], optional): Time in seconds to use for animation, or None to use system time. """ diff --git a/tests/test_console.py b/tests/test_console.py index 2db88af0b..07692f198 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -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