Skip to content

Commit

Permalink
Merge pull request #2095 from wasi-master/fix-text-from-markup-end-param
Browse files Browse the repository at this point in the history
Add missing `end` keyword argument to `Text.from_markup`
  • Loading branch information
willmcgugan committed Mar 22, 2022
2 parents 2d3152a + f06da9b commit f95d63d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions rich/text.py
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion 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
Expand Down Expand Up @@ -298,6 +298,13 @@ def test_append_text():
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()
test.append("foo", "red")
Expand Down

0 comments on commit f95d63d

Please sign in to comment.