def print(self, message, code, stack_trace, vars, **kwargs): try: self.layout["left_body"].update(code) self.layout["up_footer"].update(Panel(vars, title="Locals")) self.layout["bottom_footer"].update( Panel(Lines(stack_trace), title="Stack", style="white on blue")) self.console.print(self.layout, **kwargs) self.console.print(message, **kwargs) except NotRenderableError: self.console.print(message, **kwargs)
def test_lines_justify(): console = Console() lines1 = Lines([Text("foo", style="b"), Text("test", style="b")]) lines1.justify(console, 10, justify="left") assert lines1._lines == [Text("foo "), Text("test ")] lines1.justify(console, 10, justify="center") assert lines1._lines == [Text(" foo "), Text(" test ")] lines1.justify(console, 10, justify="right") assert lines1._lines == [Text(" foo"), Text(" test")] lines2 = Lines([Text("foo bar", style="b"), Text("test", style="b")]) lines2.justify(console, 7, justify="full") print(repr(lines2._lines[0].spans)) assert lines2._lines == [ Text( "foo bar", spans=[Span(0, 3, "b"), Span(3, 4, Style.parse("bold")), Span(4, 7, "b")], ), Text("test"), ]
def test_lines_rich_console(): console = Console() lines = Lines([Text("foo")]) result = list(lines.__rich_console__(console, console.options)) assert result == [Text("foo")]
def test_lines_justify(): console = Console() lines1 = Lines([Text("foo"), Text("test")]) lines1.justify(console, 10, justify="left") assert lines1._lines == [Text("foo "), Text("test ")] lines1.justify(console, 10, justify="center") assert lines1._lines == [Text(" foo "), Text(" test ")] lines1.justify(console, 10, justify="right") assert lines1._lines == [Text(" foo"), Text(" test")] lines2 = Lines([Text("foo bar"), Text("test")]) lines2.justify(console, 7, justify="full") assert lines2._lines == [ Text( "foo bar", spans=[ Span(0, 3, ""), Span(3, 4, Style.parse("none")), Span(4, 7, "") ], ), Text("test"), ]