From a9fb23aa2710633107d1778aa76dc2443ae4f393 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 27 Apr 2020 16:00:11 +0100 Subject: [PATCH] finish text tests --- rich/text.py | 11 +++-------- tests/test_text.py | 9 ++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rich/text.py b/rich/text.py index faf0d192..b5697f09 100644 --- a/rich/text.py +++ b/rich/text.py @@ -337,14 +337,11 @@ class Text: def __console__( self, console: "Console", options: "ConsoleOptions" ) -> Iterable[Segment]: - if self.tab_size is None: - tab_size = console.tab_size # type: ignore - else: - tab_size = self.tab_size + tab_size: int = console.tab_size or self.tab_size or 8 # type: ignore lines = self.wrap( options.max_width, justify=self.justify or options.justify, - tab_size=tab_size, + tab_size=tab_size or 8, ) all_lines = Text("\n").join(lines) 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()) 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. Args: @@ -414,8 +411,6 @@ class Text: stack_append(style_id) if next_offset > offset: yield _Segment(text[offset:next_offset], get_current_style()) - if end is None: - end = self.end if end: yield _Segment(end) diff --git a/tests/test_text.py b/tests/test_text.py index 523bba70..bf3f4f46 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -356,6 +356,14 @@ def test_fit(): 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(): console = Console(width=15, record=True) test = Text.from_markup( @@ -363,7 +371,6 @@ def test_render(): ) console.print(test) 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" assert output == expected