special case for Text

This commit is contained in:
Will McGugan 2021-11-16 14:41:30 +00:00
parent a6a54d0bd2
commit 3c811afa91
3 changed files with 21 additions and 0 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Allowed `__rich__` to work recursively
- Allowed Text classes to work with sep in print https://github.com/willmcgugan/rich/issues/1689
## [10.13.0] - 2021-11-07

View File

@ -1448,6 +1448,8 @@ class Console:
renderable, emoji=emoji, markup=markup, highlighter=_highlighter
)
)
elif isinstance(renderable, Text):
append_text(renderable)
elif isinstance(renderable, ConsoleRenderable):
check_text()
append(renderable)

View File

@ -117,6 +117,24 @@ def test_print():
assert console.file.getvalue() == "foo\n"
def test_print_multiple():
console = Console(file=io.StringIO(), color_system="truecolor")
console.print("foo", "bar")
assert console.file.getvalue() == "foo bar\n"
def test_print_text():
console = Console(file=io.StringIO(), color_system="truecolor")
console.print(Text("foo", style="bold"))
assert console.file.getvalue() == "\x1B[1mfoo\x1B[0m\n"
def test_print_text_multiple():
console = Console(file=io.StringIO(), color_system="truecolor")
console.print(Text("foo", style="bold"), Text("bar"), "baz")
assert console.file.getvalue() == "\x1B[1mfoo\x1B[0m bar baz\n"
def test_print_json():
console = Console(file=io.StringIO(), color_system="truecolor")
console.print_json('[false, true, null, "foo"]', indent=4)