Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing end keyword argument to Text.from_markup #2095

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
7 changes: 6 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 @@ -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()
Expand Down