From c391684e8fa041452189adbd1330c29595382f9a Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 1 Dec 2020 17:03:26 +0000 Subject: [PATCH] fix log jusify --- CHANGELOG.md | 1 + rich/_log_render.py | 8 ++++++++ rich/console.py | 2 +- tests/test_log.py | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9bdd9ce..a5d1be52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed redirecting of stderr in Progress - Fixed broken expanded tuple of one https://github.com/willmcgugan/rich/issues/445 +- Fixed justify argument not working in console.log https://github.com/willmcgugan/rich/issues/460 ## [9.2.0] - 2020-11-08 diff --git a/rich/_log_render.py b/rich/_log_render.py index 5d2e05c4..74f671b5 100644 --- a/rich/_log_render.py +++ b/rich/_log_render.py @@ -72,3 +72,11 @@ class LogRender: output.add_row(*row) return output + + +if __name__ == "__main__": # pragma: no cover + from rich.console import Console + + c = Console() + c.print("[on blue]Hello", justify="right") + c.log("[on blue]hello", justify="right") \ No newline at end of file diff --git a/rich/console.py b/rich/console.py index d1771b63..59ceacd6 100644 --- a/rich/console.py +++ b/rich/console.py @@ -967,7 +967,7 @@ class Console: def check_text() -> None: if text: - sep_text = Text(sep, end=end) + sep_text = Text(sep, justify=justify, end=end) append(sep_text.join(text)) del text[:] diff --git a/tests/test_log.py b/tests/test_log.py index 5728f0fb..82dbfe28 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -45,6 +45,14 @@ def test_log(): assert rendered == expected +def test_justify(): + console = Console(width=20, log_path=False, log_time=False, color_system=None) + console.begin_capture() + console.log("foo", justify="right") + result = console.end_capture() + assert result == " foo\n" + + if __name__ == "__main__": render = render_log() print(render)