From 3e79dba7ed5a4b9d8e692f79b1100849813d638e Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Tue, 4 Aug 2020 23:56:49 +0000 Subject: [PATCH 01/20] feat (WIP): multiple characters for rule.py --- rich/rule.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index 5c8918ca5..f9c784f7e 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -12,7 +12,7 @@ class Rule(JupyterMixin): Args: title (Union[str, Text], optional): Text to render in the rule. Defaults to "". - character (str, optional): Character used to draw the line. Defaults to "─". + characters (str, optional): Character(s) used to draw the line. Defaults to "─". style (StyleType, optional): Style of Rule. Defaults to "rule.line". end (str, optional): Character at end of Rule. defaults to "\\n" """ @@ -21,29 +21,29 @@ def __init__( self, title: Union[str, Text] = "", *, - character: str = None, + characters: str = None, style: Union[str, Style] = "rule.line", end: str = "\n", ) -> None: - if character and cell_len(character) != 1: - raise ValueError("'character' argument must have a cell width of 1") + if cell_len(characters) < 1: + raise ValueError("'character' argument must at least have a cell width of 1") self.title = title - self.character = character + self.characters = characters self.style = style self.end = end def __repr__(self) -> str: - return f"Rule({self.title!r}, {self.character!r})" + return f"Rule({self.title!r}, {self.characters!r})" def __rich_console__( self, console: Console, options: ConsoleOptions ) -> RenderResult: width = options.max_width - character = self.character or "─" + characters = self.characters or "─" if not self.title: - yield Text(character * width, self.style) + yield Text(characters * (width//len(characters)), self.style) else: if isinstance(self.title, Text): title_text = self.title @@ -56,12 +56,12 @@ def __rich_console__( title_text.plain = title_text.plain.replace("\n", " ") title_text = title_text.tabs_to_spaces() rule_text = Text(end=self.end) - center = (width - cell_len(title_text.plain)) // 2 - rule_text.append(character * (center - 1) + " ", self.style) + side_width = (width - cell_len(title_text.plain)) // 2 + side = Text(characters * side_width) + side.truncate(side_width - 1) + rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) - rule_text.append( - " " + character * (width - cell_len(rule_text.plain) - 1), self.style - ) + rule_text.append(" " + str(side), self.style) yield rule_text @@ -72,6 +72,6 @@ def __rich_console__( try: text = sys.argv[1] except IndexError: - text = "Hello, World" + text = "Hello" console = Console() - console.print(Rule(text)) + console.print(Rule(text, characters="-*+")) From ae8d80acb78514ed3891dc14a019cd8b5fed537e Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 01:31:36 +0000 Subject: [PATCH 02/20] optimise side_width --- rich/rule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index f9c784f7e..f85611e18 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -57,7 +57,7 @@ def __rich_console__( title_text = title_text.tabs_to_spaces() rule_text = Text(end=self.end) side_width = (width - cell_len(title_text.plain)) // 2 - side = Text(characters * side_width) + side = Text(characters * (side_width // (cell_len(characters) - 1))) side.truncate(side_width - 1) rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) @@ -74,4 +74,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console() - console.print(Rule(text, characters="-*+")) + console.print(Rule(text, characters="1234567890")) From 328b76cf5455b4e96030c4159945f1d805ff0b2d Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 04:44:53 +0000 Subject: [PATCH 03/20] optimise side_width construction --- rich/console.py | 6 +++--- rich/rule.py | 12 ++++++++---- tests/test_rule.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rich/console.py b/rich/console.py index de5c2ab85..9411b1cd3 100644 --- a/rich/console.py +++ b/rich/console.py @@ -795,18 +795,18 @@ def rule( self, title: str = "", *, - character: str = "─", + characters: str = "─", style: Union[str, Style] = "rule.line", ) -> None: """Draw a line with optional centered title. Args: title (str, optional): Text to render over the rule. Defaults to "". - character (str, optional): Character to form the line. Defaults to "─". + characters (str, optional): Character(s) to form the line. Defaults to "─". """ from .rule import Rule - rule = Rule(title=title, character=character, style=style) + rule = Rule(title=title, characters=characters, style=style) self.print(rule) def control(self, control_codes: Union["Control", str]) -> None: diff --git a/rich/rule.py b/rich/rule.py index f85611e18..0c3b33be1 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -21,7 +21,7 @@ def __init__( self, title: Union[str, Text] = "", *, - characters: str = None, + characters: str = "─", style: Union[str, Style] = "rule.line", end: str = "\n", ) -> None: @@ -57,7 +57,10 @@ def __rich_console__( title_text = title_text.tabs_to_spaces() rule_text = Text(end=self.end) side_width = (width - cell_len(title_text.plain)) // 2 - side = Text(characters * (side_width // (cell_len(characters) - 1))) + if cell_len(characters) == 1: + side = Text(characters * side_width) + else: + side = Text(characters * (side_width // (cell_len(characters) - 1))) side.truncate(side_width - 1) rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) @@ -73,5 +76,6 @@ def __rich_console__( text = sys.argv[1] except IndexError: text = "Hello" - console = Console() - console.print(Rule(text, characters="1234567890")) + console = Console(width=16) + console.print(Rule(title="foo")) + #console.print("." * 16) diff --git a/tests/test_rule.py b/tests/test_rule.py index 22c53ab37..e91f8352b 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -41,4 +41,4 @@ def test_repr(): def test_error(): with pytest.raises(ValueError): - Rule(character="bar") + Rule(characters="") From 43232f9ba1edd3265c830487fd6ad7fefe899268 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 04:54:20 +0000 Subject: [PATCH 04/20] format with black --- rich/rule.py | 8 +++++--- tests/_card_render.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index 0c3b33be1..de8f137f5 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -26,7 +26,9 @@ def __init__( end: str = "\n", ) -> None: if cell_len(characters) < 1: - raise ValueError("'character' argument must at least have a cell width of 1") + raise ValueError( + "'character' argument must at least have a cell width of 1" + ) self.title = title self.characters = characters self.style = style @@ -43,7 +45,7 @@ def __rich_console__( characters = self.characters or "─" if not self.title: - yield Text(characters * (width//len(characters)), self.style) + yield Text(characters * (width // len(characters)), self.style) else: if isinstance(self.title, Text): title_text = self.title @@ -78,4 +80,4 @@ def __rich_console__( text = "Hello" console = Console(width=16) console.print(Rule(title="foo")) - #console.print("." * 16) + # console.print("." * 16) diff --git a/tests/_card_render.py b/tests/_card_render.py index 320a7e7af..1f02e9f47 100644 --- a/tests/_card_render.py +++ b/tests/_card_render.py @@ -1 +1 @@ -expected='\x1b[3m Rich features \x1b[0m\n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Colors\x1b[0m\x1b[1;31m \x1b[0m\x1b[1;33m256\x1b[0m colors or \x1b[1;32m16.7 million\x1b[0m colors \x1b[34m(if supported by your terminal)\x1b[0m. \n \n \x1b[48;5;16m \x1b[0m\x1b[48;5;17m \x1b[0m\x1b[48;5;18m \x1b[0m\x1b[48;5;19m \x1b[0m\x1b[48;5;20m \x1b[0m\x1b[48;5;21m \x1b[0m\x1b[48;5;52m \x1b[0m\x1b[48;5;53m \x1b[0m\x1b[48;5;54m \x1b[0m\x1b[48;5;55m \x1b[0m\x1b[48;5;56m \x1b[0m\x1b[48;5;57m \x1b[0m\x1b[48;5;88m \x1b[0m\x1b[48;5;89m \x1b[0m\x1b[48;5;90m \x1b[0m\x1b[48;5;91m \x1b[0m\x1b[48;5;92m \x1b[0m\x1b[48;5;93m \x1b[0m\x1b[48;5;124m \x1b[0m\x1b[48;5;125m \x1b[0m\x1b[48;5;126m \x1b[0m\x1b[48;5;127m \x1b[0m\x1b[48;5;128m \x1b[0m\x1b[48;5;129m \x1b[0m\x1b[48;5;160m \x1b[0m\x1b[48;5;161m \x1b[0m\x1b[48;5;162m \x1b[0m\x1b[48;5;163m \x1b[0m\x1b[48;5;164m \x1b[0m\x1b[48;5;165m \x1b[0m\x1b[48;5;196m \x1b[0m\x1b[48;5;197m \x1b[0m\x1b[48;5;198m \x1b[0m\x1b[48;5;199m \x1b[0m\x1b[48;5;200m \x1b[0m\x1b[48;5;201m \x1b[0m \n \x1b[48;5;22m \x1b[0m\x1b[48;5;23m \x1b[0m\x1b[48;5;24m \x1b[0m\x1b[48;5;25m \x1b[0m\x1b[48;5;26m \x1b[0m\x1b[48;5;27m \x1b[0m\x1b[48;5;58m \x1b[0m\x1b[48;5;59m \x1b[0m\x1b[48;5;60m \x1b[0m\x1b[48;5;61m \x1b[0m\x1b[48;5;62m \x1b[0m\x1b[48;5;63m \x1b[0m\x1b[48;5;94m \x1b[0m\x1b[48;5;95m \x1b[0m\x1b[48;5;96m \x1b[0m\x1b[48;5;97m \x1b[0m\x1b[48;5;98m \x1b[0m\x1b[48;5;99m \x1b[0m\x1b[48;5;130m \x1b[0m\x1b[48;5;131m \x1b[0m\x1b[48;5;132m \x1b[0m\x1b[48;5;133m \x1b[0m\x1b[48;5;134m \x1b[0m\x1b[48;5;135m \x1b[0m\x1b[48;5;166m \x1b[0m\x1b[48;5;167m \x1b[0m\x1b[48;5;168m \x1b[0m\x1b[48;5;169m \x1b[0m\x1b[48;5;170m \x1b[0m\x1b[48;5;171m \x1b[0m\x1b[48;5;202m \x1b[0m\x1b[48;5;203m \x1b[0m\x1b[48;5;204m \x1b[0m\x1b[48;5;205m \x1b[0m\x1b[48;5;206m \x1b[0m\x1b[48;5;207m \x1b[0m \n \x1b[48;5;28m \x1b[0m\x1b[48;5;29m \x1b[0m\x1b[48;5;30m \x1b[0m\x1b[48;5;31m \x1b[0m\x1b[48;5;32m \x1b[0m\x1b[48;5;33m \x1b[0m\x1b[48;5;64m \x1b[0m\x1b[48;5;65m \x1b[0m\x1b[48;5;66m \x1b[0m\x1b[48;5;67m \x1b[0m\x1b[48;5;68m \x1b[0m\x1b[48;5;69m \x1b[0m\x1b[48;5;100m \x1b[0m\x1b[48;5;101m \x1b[0m\x1b[48;5;102m \x1b[0m\x1b[48;5;103m \x1b[0m\x1b[48;5;104m \x1b[0m\x1b[48;5;105m \x1b[0m\x1b[48;5;136m \x1b[0m\x1b[48;5;137m \x1b[0m\x1b[48;5;138m \x1b[0m\x1b[48;5;139m \x1b[0m\x1b[48;5;140m \x1b[0m\x1b[48;5;141m \x1b[0m\x1b[48;5;172m \x1b[0m\x1b[48;5;173m \x1b[0m\x1b[48;5;174m \x1b[0m\x1b[48;5;175m \x1b[0m\x1b[48;5;176m \x1b[0m\x1b[48;5;177m \x1b[0m\x1b[48;5;208m \x1b[0m\x1b[48;5;209m \x1b[0m\x1b[48;5;210m \x1b[0m\x1b[48;5;211m \x1b[0m\x1b[48;5;212m \x1b[0m\x1b[48;5;213m \x1b[0m \n \x1b[48;5;34m \x1b[0m\x1b[48;5;35m \x1b[0m\x1b[48;5;36m \x1b[0m\x1b[48;5;37m \x1b[0m\x1b[48;5;38m \x1b[0m\x1b[48;5;39m \x1b[0m\x1b[48;5;70m \x1b[0m\x1b[48;5;71m \x1b[0m\x1b[48;5;72m \x1b[0m\x1b[48;5;73m \x1b[0m\x1b[48;5;74m \x1b[0m\x1b[48;5;75m \x1b[0m\x1b[48;5;106m \x1b[0m\x1b[48;5;107m \x1b[0m\x1b[48;5;108m \x1b[0m\x1b[48;5;109m \x1b[0m\x1b[48;5;110m \x1b[0m\x1b[48;5;111m \x1b[0m\x1b[48;5;142m \x1b[0m\x1b[48;5;143m \x1b[0m\x1b[48;5;144m \x1b[0m\x1b[48;5;145m \x1b[0m\x1b[48;5;146m \x1b[0m\x1b[48;5;147m \x1b[0m\x1b[48;5;178m \x1b[0m\x1b[48;5;179m \x1b[0m\x1b[48;5;180m \x1b[0m\x1b[48;5;181m \x1b[0m\x1b[48;5;182m \x1b[0m\x1b[48;5;183m \x1b[0m\x1b[48;5;214m \x1b[0m\x1b[48;5;215m \x1b[0m\x1b[48;5;216m \x1b[0m\x1b[48;5;217m \x1b[0m\x1b[48;5;218m \x1b[0m\x1b[48;5;219m \x1b[0m \n \x1b[48;5;40m \x1b[0m\x1b[48;5;41m \x1b[0m\x1b[48;5;42m \x1b[0m\x1b[48;5;43m \x1b[0m\x1b[48;5;44m \x1b[0m\x1b[48;5;45m \x1b[0m\x1b[48;5;76m \x1b[0m\x1b[48;5;77m \x1b[0m\x1b[48;5;78m \x1b[0m\x1b[48;5;79m \x1b[0m\x1b[48;5;80m \x1b[0m\x1b[48;5;81m \x1b[0m\x1b[48;5;112m \x1b[0m\x1b[48;5;113m \x1b[0m\x1b[48;5;114m \x1b[0m\x1b[48;5;115m \x1b[0m\x1b[48;5;116m \x1b[0m\x1b[48;5;117m \x1b[0m\x1b[48;5;148m \x1b[0m\x1b[48;5;149m \x1b[0m\x1b[48;5;150m \x1b[0m\x1b[48;5;151m \x1b[0m\x1b[48;5;152m \x1b[0m\x1b[48;5;153m \x1b[0m\x1b[48;5;184m \x1b[0m\x1b[48;5;185m \x1b[0m\x1b[48;5;186m \x1b[0m\x1b[48;5;187m \x1b[0m\x1b[48;5;188m \x1b[0m\x1b[48;5;189m \x1b[0m\x1b[48;5;220m \x1b[0m\x1b[48;5;221m \x1b[0m\x1b[48;5;222m \x1b[0m\x1b[48;5;223m \x1b[0m\x1b[48;5;224m \x1b[0m\x1b[48;5;225m \x1b[0m \n \x1b[48;5;46m \x1b[0m\x1b[48;5;47m \x1b[0m\x1b[48;5;48m \x1b[0m\x1b[48;5;49m \x1b[0m\x1b[48;5;50m \x1b[0m\x1b[48;5;51m \x1b[0m\x1b[48;5;82m \x1b[0m\x1b[48;5;83m \x1b[0m\x1b[48;5;84m \x1b[0m\x1b[48;5;85m \x1b[0m\x1b[48;5;86m \x1b[0m\x1b[48;5;87m \x1b[0m\x1b[48;5;118m \x1b[0m\x1b[48;5;119m \x1b[0m\x1b[48;5;120m \x1b[0m\x1b[48;5;121m \x1b[0m\x1b[48;5;122m \x1b[0m\x1b[48;5;123m \x1b[0m\x1b[48;5;154m \x1b[0m\x1b[48;5;155m \x1b[0m\x1b[48;5;156m \x1b[0m\x1b[48;5;157m \x1b[0m\x1b[48;5;158m \x1b[0m\x1b[48;5;159m \x1b[0m\x1b[48;5;190m \x1b[0m\x1b[48;5;191m \x1b[0m\x1b[48;5;192m \x1b[0m\x1b[48;5;193m \x1b[0m\x1b[48;5;194m \x1b[0m\x1b[48;5;195m \x1b[0m\x1b[48;5;226m \x1b[0m\x1b[48;5;227m \x1b[0m\x1b[48;5;228m \x1b[0m\x1b[48;5;229m \x1b[0m\x1b[48;5;230m \x1b[0m\x1b[48;5;231m \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Styles\x1b[0m\x1b[1;31m \x1b[0mAll ansi styles: \x1b[1mbold\x1b[0m, \x1b[2mdim\x1b[0m, \x1b[3mitalic\x1b[0m, \x1b[4munderline\x1b[0m, \x1b[9mstrikethrough\x1b[0m, \x1b[7mreverse\x1b[0m, and \n even \x1b[5mblink\x1b[0m. \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Text\x1b[0m\x1b[1;31m \x1b[0mWord wrap text. Justify \x1b[32mleft\x1b[0m, \x1b[33mcenter\x1b[0m, \x1b[34mright\x1b[0m or \x1b[31mfull\x1b[0m. \n \n \x1b[32mLorem ipsum dolor \x1b[0m \x1b[33mLorem ipsum dolor \x1b[0m \x1b[34m Lorem ipsum dolor\x1b[0m \x1b[31mLorem\x1b[0m\x1b[31m \x1b[0m\x1b[31mipsum\x1b[0m\x1b[31m \x1b[0m\x1b[31mdolor\x1b[0m \n \x1b[32msit amet, \x1b[0m \x1b[33m sit amet, \x1b[0m \x1b[34m sit amet,\x1b[0m \x1b[31msit\x1b[0m\x1b[31m \x1b[0m\x1b[31mamet,\x1b[0m \n \x1b[32mconsectetur \x1b[0m \x1b[33m consectetur \x1b[0m \x1b[34m consectetur\x1b[0m \x1b[31mconsectetur\x1b[0m \n \x1b[32madipiscing elit. \x1b[0m \x1b[33m adipiscing elit. \x1b[0m \x1b[34m adipiscing elit.\x1b[0m \x1b[31madipiscing\x1b[0m\x1b[31m \x1b[0m\x1b[31melit.\x1b[0m \n \x1b[32mQuisque in metus \x1b[0m \x1b[33m Quisque in metus \x1b[0m \x1b[34m Quisque in metus\x1b[0m \x1b[31mQuisque\x1b[0m\x1b[31m \x1b[0m\x1b[31min\x1b[0m\x1b[31m \x1b[0m\x1b[31mmetus\x1b[0m \n \x1b[32msed sapien \x1b[0m \x1b[33m sed sapien \x1b[0m \x1b[34m sed sapien\x1b[0m \x1b[31msed\x1b[0m\x1b[31m \x1b[0m\x1b[31msapien\x1b[0m \n \x1b[32multricies pretium a\x1b[0m \x1b[33multricies pretium \x1b[0m \x1b[34multricies pretium a\x1b[0m \x1b[31multricies\x1b[0m\x1b[31m \x1b[0m\x1b[31mpretium\x1b[0m\x1b[31m \x1b[0m\x1b[31ma\x1b[0m \n \x1b[32mat justo. Maecenas \x1b[0m \x1b[33m a at justo. \x1b[0m \x1b[34m at justo. Maecenas\x1b[0m \x1b[31mat\x1b[0m\x1b[31m \x1b[0m\x1b[31mjusto.\x1b[0m\x1b[31m \x1b[0m\x1b[31mMaecenas\x1b[0m \n \x1b[32mluctus velit et \x1b[0m \x1b[33m Maecenas luctus \x1b[0m \x1b[34m luctus velit et\x1b[0m \x1b[31mluctus\x1b[0m\x1b[31m \x1b[0m\x1b[31mvelit\x1b[0m\x1b[31m \x1b[0m\x1b[31met\x1b[0m \n \x1b[32mauctor maximus. \x1b[0m \x1b[33m velit et auctor \x1b[0m \x1b[34m auctor maximus.\x1b[0m \x1b[31mauctor\x1b[0m\x1b[31m \x1b[0m\x1b[31mmaximus.\x1b[0m \n \x1b[32mDonec faucibus vel \x1b[0m \x1b[33m maximus. Donec \x1b[0m \x1b[34m Donec faucibus vel\x1b[0m \x1b[31mDonec\x1b[0m\x1b[31m \x1b[0m\x1b[31mfaucibus\x1b[0m\x1b[31m \x1b[0m\x1b[31mvel\x1b[0m \n \x1b[32marcu id pretium. \x1b[0m \x1b[33mfaucibus vel arcu \x1b[0m \x1b[34m arcu id pretium.\x1b[0m \x1b[31marcu id pretium.\x1b[0m \n \x1b[33m id pretium. \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m CJK support\x1b[0m\x1b[1;31m \x1b[0m\x1b[31m╔══════════════════════════════╗\x1b[0m \n \x1b[31m║\x1b[0m该库支持中文,日文和韩文文本!\x1b[31m║\x1b[0m \n \x1b[31m╚══════════════════════════════╝\x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Emoji\x1b[0m\x1b[1;31m \x1b[0mRender emoji code: :+1: :apple: :ant: Render emoji code: 👍 🍎 🐜 🐻 🥖 🚌 \n :bear: :baguette_bread: :bus: \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Console markup\x1b[0m\x1b[1;31m \x1b[0m[bold magenta]Rich[/] supports a \x1b[1;35mRich\x1b[0m supports a simple \x1b[3mbbcode\x1b[0m like \n simple [i]bbcode[/i] like \x1b[1mmarkup\x1b[0m, you can use to insert \x1b[33mcolor\x1b[0m \n [b]markup[/b], you can use to insert and \x1b[4mstyle\x1b[0m. \n [yellow]color[/] and \n [underline]style[/]. \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Tables\x1b[0m\x1b[1;31m \x1b[0m\x1b[3m Star Wars box office \x1b[0m \n ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓ \n ┃\x1b[1;35m \x1b[0m\x1b[1;35mDate \x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35mTitle \x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35mProduction Budget\x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35m Box Office\x1b[0m\x1b[1;35m \x1b[0m┃ \n ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩ \n │\x1b[2m \x1b[0m\x1b[2mDec 20, 2019\x1b[0m\x1b[2m \x1b[0m│ Star Wars: The Rise of │ $275,000,000 │ $375,126,118 │ \n │ │ Skywalker │ │ │ \n │\x1b[2m \x1b[0m\x1b[2mMay 25, 2018\x1b[0m\x1b[2m \x1b[0m│ \x1b[31mSolo\x1b[0m: A Star Wars │ $275,000,000 │ $393,151,347 │ \n │ │ Story │ │ │ \n │\x1b[2m \x1b[0m\x1b[2mDec 15, 2017\x1b[0m\x1b[2m \x1b[0m│ Star Wars Ep. VIII: │ $262,000,000 │ \x1b[1m$1,332,539,889\x1b[0m │ \n │ │ The Last Jedi │ │ │ \n └──────────────┴────────────────────────┴───────────────────┴────────────────┘ \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31mSyntax highlighting\x1b[0m\x1b[1;31m \x1b[0m\x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 1 \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mdef\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;166;226;46;48;2;39;40;34miter_last\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalues\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mIterable\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mT\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m-\x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m>\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mIterable\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mTuple\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mbool\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mT\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 2 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;230;219;116;48;2;39;40;34m"""Iterate and generate a tuple with a flag for last value."""\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 3 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalues\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 4 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mtry\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 5 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mnext\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 6 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mexcept\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;166;226;46;48;2;39;40;34mStopIteration\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 7 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mreturn\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 8 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mfor\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalue\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34min\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 9 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34myield\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mFalse\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m10 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalue\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m11 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34myield\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mTrue\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Markdown\x1b[0m\x1b[1;31m \x1b[0m# Markdown ╔════════════════════════════════════╗ \n ║ \x1b[1mMarkdown\x1b[0m ║ \n Supports much of the *markdown*, ╚════════════════════════════════════╝ \n __syntax__! \n Supports much of the \x1b[3mmarkdown\x1b[0m, \x1b[1msyntax\x1b[0m! \n - Headers \n - Basic formatting: **bold**, \x1b[1;33m • \x1b[0mHeaders \n *italic*, `code` \x1b[1;33m • \x1b[0mBasic formatting: \x1b[1mbold\x1b[0m, \x1b[3mitalic\x1b[0m, \n - Block quotes \x1b[1;33m \x1b[0m\x1b[97;40mcode\x1b[0m \n - Lists, and more... \x1b[1;33m • \x1b[0mBlock quotes \n \x1b[1;33m • \x1b[0mLists, and more... \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m And more\x1b[0m\x1b[1;31m \x1b[0mProgress bars, styled logging handler, tracebacks, etc... \n\x1b[1;31m \x1b[0m \n' \ No newline at end of file +expected = '\x1b[3m Rich features \x1b[0m\n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Colors\x1b[0m\x1b[1;31m \x1b[0m\x1b[1;33m256\x1b[0m colors or \x1b[1;32m16.7 million\x1b[0m colors \x1b[34m(if supported by your terminal)\x1b[0m. \n \n \x1b[48;5;16m \x1b[0m\x1b[48;5;17m \x1b[0m\x1b[48;5;18m \x1b[0m\x1b[48;5;19m \x1b[0m\x1b[48;5;20m \x1b[0m\x1b[48;5;21m \x1b[0m\x1b[48;5;52m \x1b[0m\x1b[48;5;53m \x1b[0m\x1b[48;5;54m \x1b[0m\x1b[48;5;55m \x1b[0m\x1b[48;5;56m \x1b[0m\x1b[48;5;57m \x1b[0m\x1b[48;5;88m \x1b[0m\x1b[48;5;89m \x1b[0m\x1b[48;5;90m \x1b[0m\x1b[48;5;91m \x1b[0m\x1b[48;5;92m \x1b[0m\x1b[48;5;93m \x1b[0m\x1b[48;5;124m \x1b[0m\x1b[48;5;125m \x1b[0m\x1b[48;5;126m \x1b[0m\x1b[48;5;127m \x1b[0m\x1b[48;5;128m \x1b[0m\x1b[48;5;129m \x1b[0m\x1b[48;5;160m \x1b[0m\x1b[48;5;161m \x1b[0m\x1b[48;5;162m \x1b[0m\x1b[48;5;163m \x1b[0m\x1b[48;5;164m \x1b[0m\x1b[48;5;165m \x1b[0m\x1b[48;5;196m \x1b[0m\x1b[48;5;197m \x1b[0m\x1b[48;5;198m \x1b[0m\x1b[48;5;199m \x1b[0m\x1b[48;5;200m \x1b[0m\x1b[48;5;201m \x1b[0m \n \x1b[48;5;22m \x1b[0m\x1b[48;5;23m \x1b[0m\x1b[48;5;24m \x1b[0m\x1b[48;5;25m \x1b[0m\x1b[48;5;26m \x1b[0m\x1b[48;5;27m \x1b[0m\x1b[48;5;58m \x1b[0m\x1b[48;5;59m \x1b[0m\x1b[48;5;60m \x1b[0m\x1b[48;5;61m \x1b[0m\x1b[48;5;62m \x1b[0m\x1b[48;5;63m \x1b[0m\x1b[48;5;94m \x1b[0m\x1b[48;5;95m \x1b[0m\x1b[48;5;96m \x1b[0m\x1b[48;5;97m \x1b[0m\x1b[48;5;98m \x1b[0m\x1b[48;5;99m \x1b[0m\x1b[48;5;130m \x1b[0m\x1b[48;5;131m \x1b[0m\x1b[48;5;132m \x1b[0m\x1b[48;5;133m \x1b[0m\x1b[48;5;134m \x1b[0m\x1b[48;5;135m \x1b[0m\x1b[48;5;166m \x1b[0m\x1b[48;5;167m \x1b[0m\x1b[48;5;168m \x1b[0m\x1b[48;5;169m \x1b[0m\x1b[48;5;170m \x1b[0m\x1b[48;5;171m \x1b[0m\x1b[48;5;202m \x1b[0m\x1b[48;5;203m \x1b[0m\x1b[48;5;204m \x1b[0m\x1b[48;5;205m \x1b[0m\x1b[48;5;206m \x1b[0m\x1b[48;5;207m \x1b[0m \n \x1b[48;5;28m \x1b[0m\x1b[48;5;29m \x1b[0m\x1b[48;5;30m \x1b[0m\x1b[48;5;31m \x1b[0m\x1b[48;5;32m \x1b[0m\x1b[48;5;33m \x1b[0m\x1b[48;5;64m \x1b[0m\x1b[48;5;65m \x1b[0m\x1b[48;5;66m \x1b[0m\x1b[48;5;67m \x1b[0m\x1b[48;5;68m \x1b[0m\x1b[48;5;69m \x1b[0m\x1b[48;5;100m \x1b[0m\x1b[48;5;101m \x1b[0m\x1b[48;5;102m \x1b[0m\x1b[48;5;103m \x1b[0m\x1b[48;5;104m \x1b[0m\x1b[48;5;105m \x1b[0m\x1b[48;5;136m \x1b[0m\x1b[48;5;137m \x1b[0m\x1b[48;5;138m \x1b[0m\x1b[48;5;139m \x1b[0m\x1b[48;5;140m \x1b[0m\x1b[48;5;141m \x1b[0m\x1b[48;5;172m \x1b[0m\x1b[48;5;173m \x1b[0m\x1b[48;5;174m \x1b[0m\x1b[48;5;175m \x1b[0m\x1b[48;5;176m \x1b[0m\x1b[48;5;177m \x1b[0m\x1b[48;5;208m \x1b[0m\x1b[48;5;209m \x1b[0m\x1b[48;5;210m \x1b[0m\x1b[48;5;211m \x1b[0m\x1b[48;5;212m \x1b[0m\x1b[48;5;213m \x1b[0m \n \x1b[48;5;34m \x1b[0m\x1b[48;5;35m \x1b[0m\x1b[48;5;36m \x1b[0m\x1b[48;5;37m \x1b[0m\x1b[48;5;38m \x1b[0m\x1b[48;5;39m \x1b[0m\x1b[48;5;70m \x1b[0m\x1b[48;5;71m \x1b[0m\x1b[48;5;72m \x1b[0m\x1b[48;5;73m \x1b[0m\x1b[48;5;74m \x1b[0m\x1b[48;5;75m \x1b[0m\x1b[48;5;106m \x1b[0m\x1b[48;5;107m \x1b[0m\x1b[48;5;108m \x1b[0m\x1b[48;5;109m \x1b[0m\x1b[48;5;110m \x1b[0m\x1b[48;5;111m \x1b[0m\x1b[48;5;142m \x1b[0m\x1b[48;5;143m \x1b[0m\x1b[48;5;144m \x1b[0m\x1b[48;5;145m \x1b[0m\x1b[48;5;146m \x1b[0m\x1b[48;5;147m \x1b[0m\x1b[48;5;178m \x1b[0m\x1b[48;5;179m \x1b[0m\x1b[48;5;180m \x1b[0m\x1b[48;5;181m \x1b[0m\x1b[48;5;182m \x1b[0m\x1b[48;5;183m \x1b[0m\x1b[48;5;214m \x1b[0m\x1b[48;5;215m \x1b[0m\x1b[48;5;216m \x1b[0m\x1b[48;5;217m \x1b[0m\x1b[48;5;218m \x1b[0m\x1b[48;5;219m \x1b[0m \n \x1b[48;5;40m \x1b[0m\x1b[48;5;41m \x1b[0m\x1b[48;5;42m \x1b[0m\x1b[48;5;43m \x1b[0m\x1b[48;5;44m \x1b[0m\x1b[48;5;45m \x1b[0m\x1b[48;5;76m \x1b[0m\x1b[48;5;77m \x1b[0m\x1b[48;5;78m \x1b[0m\x1b[48;5;79m \x1b[0m\x1b[48;5;80m \x1b[0m\x1b[48;5;81m \x1b[0m\x1b[48;5;112m \x1b[0m\x1b[48;5;113m \x1b[0m\x1b[48;5;114m \x1b[0m\x1b[48;5;115m \x1b[0m\x1b[48;5;116m \x1b[0m\x1b[48;5;117m \x1b[0m\x1b[48;5;148m \x1b[0m\x1b[48;5;149m \x1b[0m\x1b[48;5;150m \x1b[0m\x1b[48;5;151m \x1b[0m\x1b[48;5;152m \x1b[0m\x1b[48;5;153m \x1b[0m\x1b[48;5;184m \x1b[0m\x1b[48;5;185m \x1b[0m\x1b[48;5;186m \x1b[0m\x1b[48;5;187m \x1b[0m\x1b[48;5;188m \x1b[0m\x1b[48;5;189m \x1b[0m\x1b[48;5;220m \x1b[0m\x1b[48;5;221m \x1b[0m\x1b[48;5;222m \x1b[0m\x1b[48;5;223m \x1b[0m\x1b[48;5;224m \x1b[0m\x1b[48;5;225m \x1b[0m \n \x1b[48;5;46m \x1b[0m\x1b[48;5;47m \x1b[0m\x1b[48;5;48m \x1b[0m\x1b[48;5;49m \x1b[0m\x1b[48;5;50m \x1b[0m\x1b[48;5;51m \x1b[0m\x1b[48;5;82m \x1b[0m\x1b[48;5;83m \x1b[0m\x1b[48;5;84m \x1b[0m\x1b[48;5;85m \x1b[0m\x1b[48;5;86m \x1b[0m\x1b[48;5;87m \x1b[0m\x1b[48;5;118m \x1b[0m\x1b[48;5;119m \x1b[0m\x1b[48;5;120m \x1b[0m\x1b[48;5;121m \x1b[0m\x1b[48;5;122m \x1b[0m\x1b[48;5;123m \x1b[0m\x1b[48;5;154m \x1b[0m\x1b[48;5;155m \x1b[0m\x1b[48;5;156m \x1b[0m\x1b[48;5;157m \x1b[0m\x1b[48;5;158m \x1b[0m\x1b[48;5;159m \x1b[0m\x1b[48;5;190m \x1b[0m\x1b[48;5;191m \x1b[0m\x1b[48;5;192m \x1b[0m\x1b[48;5;193m \x1b[0m\x1b[48;5;194m \x1b[0m\x1b[48;5;195m \x1b[0m\x1b[48;5;226m \x1b[0m\x1b[48;5;227m \x1b[0m\x1b[48;5;228m \x1b[0m\x1b[48;5;229m \x1b[0m\x1b[48;5;230m \x1b[0m\x1b[48;5;231m \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Styles\x1b[0m\x1b[1;31m \x1b[0mAll ansi styles: \x1b[1mbold\x1b[0m, \x1b[2mdim\x1b[0m, \x1b[3mitalic\x1b[0m, \x1b[4munderline\x1b[0m, \x1b[9mstrikethrough\x1b[0m, \x1b[7mreverse\x1b[0m, and \n even \x1b[5mblink\x1b[0m. \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Text\x1b[0m\x1b[1;31m \x1b[0mWord wrap text. Justify \x1b[32mleft\x1b[0m, \x1b[33mcenter\x1b[0m, \x1b[34mright\x1b[0m or \x1b[31mfull\x1b[0m. \n \n \x1b[32mLorem ipsum dolor \x1b[0m \x1b[33mLorem ipsum dolor \x1b[0m \x1b[34m Lorem ipsum dolor\x1b[0m \x1b[31mLorem\x1b[0m\x1b[31m \x1b[0m\x1b[31mipsum\x1b[0m\x1b[31m \x1b[0m\x1b[31mdolor\x1b[0m \n \x1b[32msit amet, \x1b[0m \x1b[33m sit amet, \x1b[0m \x1b[34m sit amet,\x1b[0m \x1b[31msit\x1b[0m\x1b[31m \x1b[0m\x1b[31mamet,\x1b[0m \n \x1b[32mconsectetur \x1b[0m \x1b[33m consectetur \x1b[0m \x1b[34m consectetur\x1b[0m \x1b[31mconsectetur\x1b[0m \n \x1b[32madipiscing elit. \x1b[0m \x1b[33m adipiscing elit. \x1b[0m \x1b[34m adipiscing elit.\x1b[0m \x1b[31madipiscing\x1b[0m\x1b[31m \x1b[0m\x1b[31melit.\x1b[0m \n \x1b[32mQuisque in metus \x1b[0m \x1b[33m Quisque in metus \x1b[0m \x1b[34m Quisque in metus\x1b[0m \x1b[31mQuisque\x1b[0m\x1b[31m \x1b[0m\x1b[31min\x1b[0m\x1b[31m \x1b[0m\x1b[31mmetus\x1b[0m \n \x1b[32msed sapien \x1b[0m \x1b[33m sed sapien \x1b[0m \x1b[34m sed sapien\x1b[0m \x1b[31msed\x1b[0m\x1b[31m \x1b[0m\x1b[31msapien\x1b[0m \n \x1b[32multricies pretium a\x1b[0m \x1b[33multricies pretium \x1b[0m \x1b[34multricies pretium a\x1b[0m \x1b[31multricies\x1b[0m\x1b[31m \x1b[0m\x1b[31mpretium\x1b[0m\x1b[31m \x1b[0m\x1b[31ma\x1b[0m \n \x1b[32mat justo. Maecenas \x1b[0m \x1b[33m a at justo. \x1b[0m \x1b[34m at justo. Maecenas\x1b[0m \x1b[31mat\x1b[0m\x1b[31m \x1b[0m\x1b[31mjusto.\x1b[0m\x1b[31m \x1b[0m\x1b[31mMaecenas\x1b[0m \n \x1b[32mluctus velit et \x1b[0m \x1b[33m Maecenas luctus \x1b[0m \x1b[34m luctus velit et\x1b[0m \x1b[31mluctus\x1b[0m\x1b[31m \x1b[0m\x1b[31mvelit\x1b[0m\x1b[31m \x1b[0m\x1b[31met\x1b[0m \n \x1b[32mauctor maximus. \x1b[0m \x1b[33m velit et auctor \x1b[0m \x1b[34m auctor maximus.\x1b[0m \x1b[31mauctor\x1b[0m\x1b[31m \x1b[0m\x1b[31mmaximus.\x1b[0m \n \x1b[32mDonec faucibus vel \x1b[0m \x1b[33m maximus. Donec \x1b[0m \x1b[34m Donec faucibus vel\x1b[0m \x1b[31mDonec\x1b[0m\x1b[31m \x1b[0m\x1b[31mfaucibus\x1b[0m\x1b[31m \x1b[0m\x1b[31mvel\x1b[0m \n \x1b[32marcu id pretium. \x1b[0m \x1b[33mfaucibus vel arcu \x1b[0m \x1b[34m arcu id pretium.\x1b[0m \x1b[31marcu id pretium.\x1b[0m \n \x1b[33m id pretium. \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m CJK support\x1b[0m\x1b[1;31m \x1b[0m\x1b[31m╔══════════════════════════════╗\x1b[0m \n \x1b[31m║\x1b[0m该库支持中文,日文和韩文文本!\x1b[31m║\x1b[0m \n \x1b[31m╚══════════════════════════════╝\x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Emoji\x1b[0m\x1b[1;31m \x1b[0mRender emoji code: :+1: :apple: :ant: Render emoji code: 👍 🍎 🐜 🐻 🥖 🚌 \n :bear: :baguette_bread: :bus: \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Console markup\x1b[0m\x1b[1;31m \x1b[0m[bold magenta]Rich[/] supports a \x1b[1;35mRich\x1b[0m supports a simple \x1b[3mbbcode\x1b[0m like \n simple [i]bbcode[/i] like \x1b[1mmarkup\x1b[0m, you can use to insert \x1b[33mcolor\x1b[0m \n [b]markup[/b], you can use to insert and \x1b[4mstyle\x1b[0m. \n [yellow]color[/] and \n [underline]style[/]. \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Tables\x1b[0m\x1b[1;31m \x1b[0m\x1b[3m Star Wars box office \x1b[0m \n ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓ \n ┃\x1b[1;35m \x1b[0m\x1b[1;35mDate \x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35mTitle \x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35mProduction Budget\x1b[0m\x1b[1;35m \x1b[0m┃\x1b[1;35m \x1b[0m\x1b[1;35m Box Office\x1b[0m\x1b[1;35m \x1b[0m┃ \n ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩ \n │\x1b[2m \x1b[0m\x1b[2mDec 20, 2019\x1b[0m\x1b[2m \x1b[0m│ Star Wars: The Rise of │ $275,000,000 │ $375,126,118 │ \n │ │ Skywalker │ │ │ \n │\x1b[2m \x1b[0m\x1b[2mMay 25, 2018\x1b[0m\x1b[2m \x1b[0m│ \x1b[31mSolo\x1b[0m: A Star Wars │ $275,000,000 │ $393,151,347 │ \n │ │ Story │ │ │ \n │\x1b[2m \x1b[0m\x1b[2mDec 15, 2017\x1b[0m\x1b[2m \x1b[0m│ Star Wars Ep. VIII: │ $262,000,000 │ \x1b[1m$1,332,539,889\x1b[0m │ \n │ │ The Last Jedi │ │ │ \n └──────────────┴────────────────────────┴───────────────────┴────────────────┘ \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31mSyntax highlighting\x1b[0m\x1b[1;31m \x1b[0m\x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 1 \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mdef\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;166;226;46;48;2;39;40;34miter_last\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalues\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mIterable\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mT\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m-\x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m>\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mIterable\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mTuple\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m[\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mbool\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mT\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m]\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 2 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;230;219;116;48;2;39;40;34m"""Iterate and generate a tuple with a flag for last value."""\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 3 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalues\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 4 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mtry\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 5 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mnext\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 6 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mexcept\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;166;226;46;48;2;39;40;34mStopIteration\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 7 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mreturn\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 8 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mfor\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalue\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34min\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34miter_values\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m:\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m 9 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34myield\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mFalse\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m10 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;249;38;114;48;2;39;40;34m=\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mvalue\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n \x1b[1;38;2;227;227;221;48;2;39;40;34m \x1b[0m\x1b[38;2;101;102;96;48;2;39;40;34m11 \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34myield\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;102;217;239;48;2;39;40;34mTrue\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m,\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprevious_value\x1b[0m\x1b[48;2;39;40;34m \x1b[0m \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m Markdown\x1b[0m\x1b[1;31m \x1b[0m# Markdown ╔════════════════════════════════════╗ \n ║ \x1b[1mMarkdown\x1b[0m ║ \n Supports much of the *markdown*, ╚════════════════════════════════════╝ \n __syntax__! \n Supports much of the \x1b[3mmarkdown\x1b[0m, \x1b[1msyntax\x1b[0m! \n - Headers \n - Basic formatting: **bold**, \x1b[1;33m • \x1b[0mHeaders \n *italic*, `code` \x1b[1;33m • \x1b[0mBasic formatting: \x1b[1mbold\x1b[0m, \x1b[3mitalic\x1b[0m, \n - Block quotes \x1b[1;33m \x1b[0m\x1b[97;40mcode\x1b[0m \n - Lists, and more... \x1b[1;33m • \x1b[0mBlock quotes \n \x1b[1;33m • \x1b[0mLists, and more... \n\x1b[1;31m \x1b[0m \n\x1b[1;31m \x1b[0m\x1b[1;31m And more\x1b[0m\x1b[1;31m \x1b[0mProgress bars, styled logging handler, tracebacks, etc... \n\x1b[1;31m \x1b[0m \n' From ce2af5fc76275d1a51508570d4e3dfba6d08307a Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 05:07:46 +0000 Subject: [PATCH 05/20] fix for ending space --- rich/rule.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index de8f137f5..df215c696 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -67,6 +67,8 @@ def __rich_console__( rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) rule_text.append(" " + str(side), self.style) + if len(rule_text) < width: + rule_text.append(characters[0], self.style) yield rule_text @@ -79,5 +81,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="foo")) - # console.print("." * 16) + console.print(Rule(title="欢迎!")) From e386a669fc5d068138b63a2311f6c1b60b2e0653 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 08:50:15 +0000 Subject: [PATCH 06/20] fix tests --- rich/rule.py | 2 +- tests/test_rule.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index df215c696..f7a187641 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -81,4 +81,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="欢迎!")) + console.print(Rule(title="foo")) diff --git a/tests/test_rule.py b/tests/test_rule.py index e91f8352b..ff7712b24 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -11,13 +11,16 @@ def test_rule(): console = Console( width=16, file=io.StringIO(), force_terminal=True, legacy_windows=False ) - console.rule() - console.rule("foo") + console.print(Rule()) + console.print(Rule("foo")) console.rule(Text("foo", style="bold")) console.rule("foobarbazeggfoobarbazegg") - expected = "\x1b[92m────────────────\x1b[0m\n\x1b[92m───── \x1b[0mfoo\x1b[92m ──────\x1b[0m\n\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n" + expected = "\x1b[92m────────────────\x1b[0m\n" + expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + expected += "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n" + result = console.file.getvalue() - print(repr(result)) assert result == expected From c90a543b6fcdeb02a8019e0e2f3f22334648475c Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 08:51:24 +0000 Subject: [PATCH 07/20] format with black --- tests/test_rule.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_rule.py b/tests/test_rule.py index ff7712b24..d9d119039 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -17,7 +17,9 @@ def test_rule(): console.rule("foobarbazeggfoobarbazegg") expected = "\x1b[92m────────────────\x1b[0m\n" expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" - expected += "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + expected += ( + "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + ) expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n" result = console.file.getvalue() From f7ab2afa1fcdb9d3b2cda4bd1f4a8c8c7035f296 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 09:20:00 +0000 Subject: [PATCH 08/20] attempt at supporting emoji --- rich/rule.py | 17 ++++++++++++----- tests/test_rule.py | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index f7a187641..8a2ba93bc 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -1,6 +1,6 @@ from typing import Union -from .cells import cell_len +from .cells import cell_len, get_character_cell_size as get_char_size from .console import Console, ConsoleOptions, RenderResult from .jupyter import JupyterMixin from .style import Style @@ -44,8 +44,15 @@ def __rich_console__( characters = self.characters or "─" + if cell_len(characters) == 1: + chars_len = get_char_size(characters) + else: + chars_len = 0 + for i in list(characters): + chars_len += get_char_size(i) + print(chars_len) if not self.title: - yield Text(characters * (width // len(characters)), self.style) + yield Text(characters * (width // chars_len), self.style) else: if isinstance(self.title, Text): title_text = self.title @@ -59,10 +66,10 @@ def __rich_console__( title_text = title_text.tabs_to_spaces() rule_text = Text(end=self.end) side_width = (width - cell_len(title_text.plain)) // 2 - if cell_len(characters) == 1: + if chars_len == 1: side = Text(characters * side_width) else: - side = Text(characters * (side_width // (cell_len(characters) - 1))) + side = Text(characters * (side_width // (chars_len - 1))) side.truncate(side_width - 1) rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) @@ -81,4 +88,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="foo")) + console.print(Rule(title="foo", characters="😊😊")) diff --git a/tests/test_rule.py b/tests/test_rule.py index d9d119039..9c570cb56 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -26,6 +26,7 @@ def test_rule(): assert result == expected +# doesn't work for now def test_rule_cjk(): console = Console( width=16, From b698b8d6d29c2e5d184e9526cf92828d0a0ce768 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 09:32:26 +0000 Subject: [PATCH 09/20] better ValueError msg --- rich/rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/rule.py b/rich/rule.py index 8a2ba93bc..3a844f51a 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -27,7 +27,7 @@ def __init__( ) -> None: if cell_len(characters) < 1: raise ValueError( - "'character' argument must at least have a cell width of 1" + "'characters' argument must have at least a cell width of 1" ) self.title = title self.characters = characters From e0066e34c2e68ee6503152ab28edfc194bf4cff6 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 09:38:02 +0000 Subject: [PATCH 10/20] add tests (rule.py coverage 100% now) --- tests/test_rule.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/test_rule.py b/tests/test_rule.py index 9c570cb56..08274932c 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -27,7 +27,20 @@ def test_rule(): # doesn't work for now -def test_rule_cjk(): +# def test_rule_cjk(): +# console = Console( +# width=16, +# file=io.StringIO(), +# force_terminal=True, +# color_system=None, +# legacy_windows=False, +# ) +# console.rule("欢迎!") +# expected = "──── 欢迎! ────\n" +# assert console.file.getvalue() == expected + + +def test_characters(): console = Console( width=16, file=io.StringIO(), @@ -35,8 +48,10 @@ def test_rule_cjk(): color_system=None, legacy_windows=False, ) - console.rule("欢迎!") - expected = "──── 欢迎! ────\n" + console.rule(characters="+*") + console.rule("foo", characters="+*") + expected = "+*+*+*+*+*+*+*+*\n" + expected += "+*+*+ foo +*+*++\n" assert console.file.getvalue() == expected From c534209203912a56d0d653de92602e16a64f3727 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 09:58:45 +0000 Subject: [PATCH 11/20] remove print() for debugging --- rich/rule.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index 3a844f51a..22c2ed4e9 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -50,7 +50,6 @@ def __rich_console__( chars_len = 0 for i in list(characters): chars_len += get_char_size(i) - print(chars_len) if not self.title: yield Text(characters * (width // chars_len), self.style) else: @@ -88,4 +87,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="foo", characters="😊😊")) + console.print(Rule(title="fo", characters="=.")) From d84753786a0ba0c9a05eaf80d0957362c8e728e9 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 09:59:14 +0000 Subject: [PATCH 12/20] remove print() for debugging --- rich/rule.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rich/rule.py b/rich/rule.py index 22c2ed4e9..d5ff115b9 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -69,6 +69,7 @@ def __rich_console__( side = Text(characters * side_width) else: side = Text(characters * (side_width // (chars_len - 1))) + print(side) side.truncate(side_width - 1) rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) From fd76eba52604ed3261bc6f3185293b2056900b30 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 20:26:56 +0800 Subject: [PATCH 13/20] remove print and modify console.print --- rich/rule.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index 3a844f51a..91a9a2ca0 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -50,7 +50,6 @@ def __rich_console__( chars_len = 0 for i in list(characters): chars_len += get_char_size(i) - print(chars_len) if not self.title: yield Text(characters * (width // chars_len), self.style) else: @@ -88,4 +87,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="foo", characters="😊😊")) + console.print(Rule(title="foo", characters="好")) From a04200b1edd6e47240a91bb8e95d79ef28ae1a26 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Wed, 5 Aug 2020 20:31:57 +0800 Subject: [PATCH 14/20] add more tests --- tests/test_rule.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_rule.py b/tests/test_rule.py index 08274932c..1deef26c5 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -50,8 +50,10 @@ def test_characters(): ) console.rule(characters="+*") console.rule("foo", characters="+*") + console.print(Rule(characters=".,")) expected = "+*+*+*+*+*+*+*+*\n" expected += "+*+*+ foo +*+*++\n" + expected += ".,.,.,.,.,.,.,.,\n" assert console.file.getvalue() == expected From 465a56f465385b6d3187f27e4b9f8de89e23df4e Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Fri, 7 Aug 2020 01:04:19 +0000 Subject: [PATCH 15/20] fix cjk i think --- rich/rule.py | 6 +++--- tests/test_rule.py | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index f6359406a..8cd1e2e66 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -1,6 +1,6 @@ from typing import Union -from .cells import cell_len, get_character_cell_size as get_char_size +from .cells import cell_len, get_character_cell_size as get_char_size, set_cell_size from .console import Console, ConsoleOptions, RenderResult from .jupyter import JupyterMixin from .style import Style @@ -69,13 +69,13 @@ def __rich_console__( side = Text(characters * side_width) else: side = Text(characters * (side_width // (chars_len - 1))) - print(side) side.truncate(side_width - 1) rule_text.append(str(side) + " ", self.style) rule_text.append(title_text) rule_text.append(" " + str(side), self.style) if len(rule_text) < width: rule_text.append(characters[0], self.style) + rule_text.plain = set_cell_size(rule_text.plain, width) yield rule_text @@ -88,4 +88,4 @@ def __rich_console__( except IndexError: text = "Hello" console = Console(width=16) - console.print(Rule(title="foo", characters="好")) + console.print(Rule(title="好", characters="+-")) diff --git a/tests/test_rule.py b/tests/test_rule.py index 1deef26c5..9c799e1ed 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -26,18 +26,17 @@ def test_rule(): assert result == expected -# doesn't work for now -# def test_rule_cjk(): -# console = Console( -# width=16, -# file=io.StringIO(), -# force_terminal=True, -# color_system=None, -# legacy_windows=False, -# ) -# console.rule("欢迎!") -# expected = "──── 欢迎! ────\n" -# assert console.file.getvalue() == expected +def test_rule_cjk(): + console = Console( + width=16, + file=io.StringIO(), + force_terminal=True, + color_system=None, + legacy_windows=False, + ) + console.rule("欢迎!") + expected = "──── 欢迎! ────\n" + assert console.file.getvalue() == expected def test_characters(): From 572cae35d2d823827438eb4dbd503484a1a55c0b Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Fri, 7 Aug 2020 01:06:38 +0000 Subject: [PATCH 16/20] restore main code --- rich/rule.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index 8cd1e2e66..efad41b24 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -86,6 +86,6 @@ def __rich_console__( try: text = sys.argv[1] except IndexError: - text = "Hello" - console = Console(width=16) - console.print(Rule(title="好", characters="+-")) + text = "Hello, World" + console = Console() + console.print(Rule(title=text)) From f8886b2779903c9a96d5587eac343b2f16942666 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Sat, 8 Aug 2020 00:06:58 +0000 Subject: [PATCH 17/20] improve no title and cell len logic --- rich/rule.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index efad41b24..c5499c4b6 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -1,6 +1,6 @@ from typing import Union -from .cells import cell_len, get_character_cell_size as get_char_size, set_cell_size +from .cells import cell_len, set_cell_size from .console import Console, ConsoleOptions, RenderResult from .jupyter import JupyterMixin from .style import Style @@ -44,14 +44,10 @@ def __rich_console__( characters = self.characters or "─" - if cell_len(characters) == 1: - chars_len = get_char_size(characters) - else: - chars_len = 0 - for i in list(characters): - chars_len += get_char_size(i) + chars_len = cell_len(characters) if not self.title: - yield Text(characters * (width // chars_len), self.style) + rule_text = Text(characters * ((width // chars_len) + 1), self.style) + rule_text.truncate(width) else: if isinstance(self.title, Text): title_text = self.title @@ -76,7 +72,7 @@ def __rich_console__( if len(rule_text) < width: rule_text.append(characters[0], self.style) rule_text.plain = set_cell_size(rule_text.plain, width) - yield rule_text + yield rule_text if __name__ == "__main__": # pragma: no cover From 311b677d36fa43a8ffad9931afe09f969a6d3822 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Sat, 8 Aug 2020 02:39:14 +0000 Subject: [PATCH 18/20] construct left and right rule separately --- rich/rule.py | 16 +++++++--------- tests/test_rule.py | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/rich/rule.py b/rich/rule.py index c5499c4b6..381ae41a4 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -61,16 +61,14 @@ def __rich_console__( title_text = title_text.tabs_to_spaces() rule_text = Text(end=self.end) side_width = (width - cell_len(title_text.plain)) // 2 - if chars_len == 1: - side = Text(characters * side_width) - else: - side = Text(characters * (side_width // (chars_len - 1))) - side.truncate(side_width - 1) - rule_text.append(str(side) + " ", self.style) + left = Text(characters * (side_width // chars_len + 1)) + left.truncate(side_width - 1) + right_length = width - cell_len(left.plain) - cell_len(title_text.plain) + right = Text(characters * (side_width // chars_len + 1)) + right.truncate(right_length) + rule_text.append(left.plain + " ", self.style) rule_text.append(title_text) - rule_text.append(" " + str(side), self.style) - if len(rule_text) < width: - rule_text.append(characters[0], self.style) + rule_text.append(" " + right.plain, self.style) rule_text.plain = set_cell_size(rule_text.plain, width) yield rule_text diff --git a/tests/test_rule.py b/tests/test_rule.py index 9c799e1ed..5acf7ad36 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -16,9 +16,9 @@ def test_rule(): console.rule(Text("foo", style="bold")) console.rule("foobarbazeggfoobarbazegg") expected = "\x1b[92m────────────────\x1b[0m\n" - expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ──────\x1b[0m\n" expected += ( - "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n" + "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n" ) expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n" @@ -51,7 +51,7 @@ def test_characters(): console.rule("foo", characters="+*") console.print(Rule(characters=".,")) expected = "+*+*+*+*+*+*+*+*\n" - expected += "+*+*+ foo +*+*++\n" + expected += "+*+*+ foo +*+*+*\n" expected += ".,.,.,.,.,.,.,.,\n" assert console.file.getvalue() == expected From 0d90d99b5ed304ec06f4b7f92cce8b60aa6b50c5 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Sat, 8 Aug 2020 02:39:35 +0000 Subject: [PATCH 19/20] format with black --- tests/test_rule.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_rule.py b/tests/test_rule.py index 5acf7ad36..1d6300e76 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -17,9 +17,7 @@ def test_rule(): console.rule("foobarbazeggfoobarbazegg") expected = "\x1b[92m────────────────\x1b[0m\n" expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ──────\x1b[0m\n" - expected += ( - "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n" - ) + expected += "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n" expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n" result = console.file.getvalue() From 4391f61b317bb1b5eb018559daa6924d99345ae8 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Fri, 14 Aug 2020 03:22:44 +0000 Subject: [PATCH 20/20] add deprecation warning --- rich/console.py | 4 ++++ rich/rule.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/rich/console.py b/rich/console.py index 9411b1cd3..d690e4a9a 100644 --- a/rich/console.py +++ b/rich/console.py @@ -795,6 +795,7 @@ def rule( self, title: str = "", *, + character: Optional[str] = None, characters: str = "─", style: Union[str, Style] = "rule.line", ) -> None: @@ -802,10 +803,13 @@ def rule( Args: title (str, optional): Text to render over the rule. Defaults to "". + character: Will be deprecated in v6.0.0, please use characters argument instead. characters (str, optional): Character(s) to form the line. Defaults to "─". """ from .rule import Rule + if character: + characters = character rule = Rule(title=title, characters=characters, style=style) self.print(rule) diff --git a/rich/rule.py b/rich/rule.py index 381ae41a4..73599421e 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -12,6 +12,7 @@ class Rule(JupyterMixin): Args: title (Union[str, Text], optional): Text to render in the rule. Defaults to "". + character: Will be deprecated in v6.0.0, please use characters argument instead. characters (str, optional): Character(s) used to draw the line. Defaults to "─". style (StyleType, optional): Style of Rule. Defaults to "rule.line". end (str, optional): Character at end of Rule. defaults to "\\n" @@ -21,10 +22,14 @@ def __init__( self, title: Union[str, Text] = "", *, + character: Union[str, None] = None, characters: str = "─", style: Union[str, Style] = "rule.line", end: str = "\n", ) -> None: + if character: + characters = character + if cell_len(characters) < 1: raise ValueError( "'characters' argument must have at least a cell width of 1"