Skip to content

Commit f95d63d

Browse files
authored
Merge pull request #2095 from wasi-master/fix-text-from-markup-end-param
Add missing `end` keyword argument to `Text.from_markup`
2 parents 2d3152a + f06da9b commit f95d63d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Add missing `end` keyword argument to `Text.from_markup`
13+
814
## [12.0.1] - 2022-03-22
915

1016
### Changed

rich/text.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def from_markup(
253253
emoji_variant: Optional[EmojiVariant] = None,
254254
justify: Optional["JustifyMethod"] = None,
255255
overflow: Optional["OverflowMethod"] = None,
256+
end: str = "\n",
256257
) -> "Text":
257258
"""Create Text instance from markup.
258259
@@ -261,6 +262,7 @@ def from_markup(
261262
emoji (bool, optional): Also render emoji code. Defaults to True.
262263
justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
263264
overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
265+
end (str, optional): Character to end text with. Defaults to "\\\\n".
264266
265267
Returns:
266268
Text: A Text instance with markup rendered.
@@ -270,6 +272,7 @@ def from_markup(
270272
rendered_text = render(text, style, emoji=emoji, emoji_variant=emoji_variant)
271273
rendered_text.justify = justify
272274
rendered_text.overflow = overflow
275+
rendered_text.end = end
273276
return rendered_text
274277

275278
@classmethod

tests/test_text.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from io import StringIO
22
import pytest
33

4-
from rich.console import Console
4+
from rich.console import Console, Group
55
from rich.text import Span, Text
66
from rich.measure import Measurement
77
from rich.style import Style
@@ -298,6 +298,13 @@ def test_append_text():
298298
assert test._spans == [Span(3, 6, "bold")]
299299

300300

301+
def test_end():
302+
console = Console(width=20, file=StringIO())
303+
test = Group(Text.from_markup("foo", end=" "), Text.from_markup("bar"))
304+
console.print(test)
305+
assert console.file.getvalue() == "foo bar\n"
306+
307+
301308
def test_split():
302309
test = Text()
303310
test.append("foo", "red")

0 commit comments

Comments
 (0)