diff --git a/CHANGELOG.md b/CHANGELOG.md index d81b5c46e..971f8103f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed table style taking precedence over row style https://github.com/willmcgugan/rich/issues/1129 - Fixed incorrect measurement of Text with new lines and whitespace https://github.com/willmcgugan/rich/issues/1133 - Made type annotations consistent for various `total` keyword arguments in `rich.progress` and rich.`progress_bar` - +- Disabled Progress no longer displays itself when starting https://github.com/willmcgugan/rich/pull/1125 ## [9.13.0] - 2021-03-06 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7f318fee2..4d66ed70d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,6 +6,7 @@ The following people have contributed to the development of Rich: - [Oleksis Fraga](https://github.com/oleksis) - [Finn Hughes](https://github.com/finnhughes) +- [Josh Karpel](https://github.com/JoshKarpel) - [Hedy Li](https://github.com/hedythedev) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) diff --git a/rich/progress.py b/rich/progress.py index 6b05456de..e050fef4f 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -634,7 +634,8 @@ def finished(self) -> bool: def start(self) -> None: """Start the progress display.""" - self.live.start(refresh=True) + if not self.disable: + self.live.start(refresh=True) def stop(self) -> None: """Stop the progress display.""" diff --git a/tests/test_progress.py b/tests/test_progress.py index cca4ad6fd..046912052 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -434,6 +434,44 @@ def get_time() -> float: ) +def test_live_is_started_if_progress_is_enabled() -> None: + progress = Progress(auto_refresh=False, disable=False) + + with progress: + assert progress.live._started + + +def test_live_is_not_started_if_progress_is_disabled() -> None: + progress = Progress(auto_refresh=False, disable=True) + + with progress: + assert not progress.live._started + + +def test_no_output_if_progress_is_disabled() -> None: + console = Console( + file=io.StringIO(), + force_terminal=True, + width=60, + color_system="truecolor", + legacy_windows=False, + _environ={}, + ) + progress = Progress( + console=console, + disable=True, + ) + test = ["foo", "bar", "baz"] + expected_values = iter(test) + with progress: + for value in progress.track(test, description="test"): + assert value == next(expected_values) + result = console.file.getvalue() + print(repr(result)) + expected = "" + assert result == expected + + if __name__ == "__main__": _render = render_progress() print(_render)