Skip to content

Commit 3c811af

Browse files
committed
special case for Text
1 parent a6a54d0 commit 3c811af

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
### Changed
2323

2424
- Allowed `__rich__` to work recursively
25+
- Allowed Text classes to work with sep in print https://github.com/willmcgugan/rich/issues/1689
2526

2627
## [10.13.0] - 2021-11-07
2728

rich/console.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ def check_text() -> None:
14481448
renderable, emoji=emoji, markup=markup, highlighter=_highlighter
14491449
)
14501450
)
1451+
elif isinstance(renderable, Text):
1452+
append_text(renderable)
14511453
elif isinstance(renderable, ConsoleRenderable):
14521454
check_text()
14531455
append(renderable)

tests/test_console.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ def test_print():
117117
assert console.file.getvalue() == "foo\n"
118118

119119

120+
def test_print_multiple():
121+
console = Console(file=io.StringIO(), color_system="truecolor")
122+
console.print("foo", "bar")
123+
assert console.file.getvalue() == "foo bar\n"
124+
125+
126+
def test_print_text():
127+
console = Console(file=io.StringIO(), color_system="truecolor")
128+
console.print(Text("foo", style="bold"))
129+
assert console.file.getvalue() == "\x1B[1mfoo\x1B[0m\n"
130+
131+
132+
def test_print_text_multiple():
133+
console = Console(file=io.StringIO(), color_system="truecolor")
134+
console.print(Text("foo", style="bold"), Text("bar"), "baz")
135+
assert console.file.getvalue() == "\x1B[1mfoo\x1B[0m bar baz\n"
136+
137+
120138
def test_print_json():
121139
console = Console(file=io.StringIO(), color_system="truecolor")
122140
console.print_json('[false, true, null, "foo"]', indent=4)

0 commit comments

Comments
 (0)