From 5b3f9bbfa88b384d3b161ca9884bb89fbcf46a13 Mon Sep 17 00:00:00 2001 From: Wasi Master Date: Tue, 22 Mar 2022 18:32:47 +0600 Subject: [PATCH 1/3] Add missing `end` keyword argument to `Text.from_markup` Closes https://github.com/Textualize/rich/issues/2054 --- CHANGELOG.md | 6 ++++++ rich/text.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 125435d72..3175ba86f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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] + +### Fixed + +- Add missing `end` keyword argument to `Text.from_markup` + ## [12.0.1] - 2022-03-22 ### Changed diff --git a/rich/text.py b/rich/text.py index d9ac2c0d6..f6b349d6a 100644 --- a/rich/text.py +++ b/rich/text.py @@ -253,6 +253,7 @@ def from_markup( emoji_variant: Optional[EmojiVariant] = None, justify: Optional["JustifyMethod"] = None, overflow: Optional["OverflowMethod"] = None, + end: str = "\n", ) -> "Text": """Create Text instance from markup. @@ -261,6 +262,7 @@ def from_markup( emoji (bool, optional): Also render emoji code. Defaults to True. justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. + end (str, optional): Character to end text with. Defaults to "\\\\n". Returns: Text: A Text instance with markup rendered. @@ -270,6 +272,7 @@ def from_markup( rendered_text = render(text, style, emoji=emoji, emoji_variant=emoji_variant) rendered_text.justify = justify rendered_text.overflow = overflow + rendered_text.end = end return rendered_text @classmethod From fc292780aa4e6d24386159490296ddbbc3443286 Mon Sep 17 00:00:00 2001 From: Wasi Master Date: Tue, 22 Mar 2022 20:13:30 +0600 Subject: [PATCH 2/3] Add test for the end parameter --- tests/test_text.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_text.py b/tests/test_text.py index d1d721bd4..8fe9fa889 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -1,7 +1,7 @@ from io import StringIO import pytest -from rich.console import Console +from rich.console import Console, Group from rich.text import Span, Text from rich.measure import Measurement from rich.style import Style @@ -297,6 +297,11 @@ def test_append_text(): assert str(test) == "foobar" assert test._spans == [Span(3, 6, "bold")] +def test_end(): + console = Console(width=20, file=StringIO()) + test = Group(Text.from_markup("foo", end=" "), Text.from_markup("bar")) + console.print(test) + assert console.file.getvalue() == "foo bar\n" def test_split(): test = Text() From f06da9b94c92b42bc267149a4a0af03931abe086 Mon Sep 17 00:00:00 2001 From: Wasi Master Date: Tue, 22 Mar 2022 20:17:21 +0600 Subject: [PATCH 3/3] Format with black --- tests/test_text.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_text.py b/tests/test_text.py index 8fe9fa889..811a801e4 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -297,11 +297,13 @@ def test_append_text(): assert str(test) == "foobar" assert test._spans == [Span(3, 6, "bold")] + def test_end(): console = Console(width=20, file=StringIO()) test = Group(Text.from_markup("foo", end=" "), Text.from_markup("bar")) console.print(test) - assert console.file.getvalue() == "foo bar\n" + assert console.file.getvalue() == "foo bar\n" + def test_split(): test = Text()