mirror of https://github.com/Textualize/rich.git
finish text tests
This commit is contained in:
parent
44a1df182d
commit
a9fb23aa27
11
rich/text.py
11
rich/text.py
|
@ -337,14 +337,11 @@ class Text:
|
||||||
def __console__(
|
def __console__(
|
||||||
self, console: "Console", options: "ConsoleOptions"
|
self, console: "Console", options: "ConsoleOptions"
|
||||||
) -> Iterable[Segment]:
|
) -> Iterable[Segment]:
|
||||||
if self.tab_size is None:
|
tab_size: int = console.tab_size or self.tab_size or 8 # type: ignore
|
||||||
tab_size = console.tab_size # type: ignore
|
|
||||||
else:
|
|
||||||
tab_size = self.tab_size
|
|
||||||
lines = self.wrap(
|
lines = self.wrap(
|
||||||
options.max_width,
|
options.max_width,
|
||||||
justify=self.justify or options.justify,
|
justify=self.justify or options.justify,
|
||||||
tab_size=tab_size,
|
tab_size=tab_size or 8,
|
||||||
)
|
)
|
||||||
all_lines = Text("\n").join(lines)
|
all_lines = Text("\n").join(lines)
|
||||||
yield from all_lines.render(console, end=self.end)
|
yield from all_lines.render(console, end=self.end)
|
||||||
|
@ -357,7 +354,7 @@ class Text:
|
||||||
min_text_width = max(cell_len(word) for word in text.split())
|
min_text_width = max(cell_len(word) for word in text.split())
|
||||||
return Measurement(min_text_width, max_text_width)
|
return Measurement(min_text_width, max_text_width)
|
||||||
|
|
||||||
def render(self, console: "Console", end: str = None) -> Iterable["Segment"]:
|
def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
|
||||||
"""Render the text as Segments.
|
"""Render the text as Segments.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -414,8 +411,6 @@ class Text:
|
||||||
stack_append(style_id)
|
stack_append(style_id)
|
||||||
if next_offset > offset:
|
if next_offset > offset:
|
||||||
yield _Segment(text[offset:next_offset], get_current_style())
|
yield _Segment(text[offset:next_offset], get_current_style())
|
||||||
if end is None:
|
|
||||||
end = self.end
|
|
||||||
if end:
|
if end:
|
||||||
yield _Segment(end)
|
yield _Segment(end)
|
||||||
|
|
||||||
|
|
|
@ -356,6 +356,14 @@ def test_fit():
|
||||||
assert str(lines[1]) == "Wor"
|
assert str(lines[1]) == "Wor"
|
||||||
|
|
||||||
|
|
||||||
|
def test_wrap_tabs():
|
||||||
|
test = Text("foo\tbar")
|
||||||
|
lines = test.wrap(4)
|
||||||
|
assert len(lines) == 2
|
||||||
|
assert str(lines[0]) == "foo "
|
||||||
|
assert str(lines[1]) == "bar "
|
||||||
|
|
||||||
|
|
||||||
def test_render():
|
def test_render():
|
||||||
console = Console(width=15, record=True)
|
console = Console(width=15, record=True)
|
||||||
test = Text.from_markup(
|
test = Text.from_markup(
|
||||||
|
@ -363,7 +371,6 @@ def test_render():
|
||||||
)
|
)
|
||||||
console.print(test)
|
console.print(test)
|
||||||
output = console.export_text(styles=True)
|
output = console.export_text(styles=True)
|
||||||
print(repr(output))
|
|
||||||
expected = "\x1b[1;4mWhere\x1b[0m\x1b[4m there is \x1b[0m\n\x1b[4ma \x1b[0m\x1b[3;4mWill\x1b[0m\x1b[4m, there \x1b[0m\n\x1b[4mis a Way.\x1b[0m\n"
|
expected = "\x1b[1;4mWhere\x1b[0m\x1b[4m there is \x1b[0m\n\x1b[4ma \x1b[0m\x1b[3;4mWill\x1b[0m\x1b[4m, there \x1b[0m\n\x1b[4mis a Way.\x1b[0m\n"
|
||||||
assert output == expected
|
assert output == expected
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue