Esempio n. 1
0
def test_screen_update():
    console = Console(width=20,
                      height=4,
                      color_system="truecolor",
                      force_terminal=True,
                      _environ={})
    with console.capture() as capture:
        with console.screen() as screen:
            screen.update("foo", style="blue")
            screen.update("bar")
            screen.update()
    result = capture.get()
    print(repr(result))
    expected = "\x1b[?1049h\x1b[H\x1b[?25l\x1b[34mfoo\x1b[0m\x1b[34m                 \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\x1b[34mbar\x1b[0m\x1b[34m                 \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\x1b[34mbar\x1b[0m\x1b[34m                 \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\n\x1b[34m                    \x1b[0m\x1b[?1049l\x1b[?25h"
    assert result == expected
Esempio n. 2
0
def test_reset_height():
    """Test height is reset when rendering complex renderables."""
    # https://github.com/Textualize/rich/issues/2042
    class Panels:
        def __rich_console__(self, console, options):
            yield Panel("foo")
            yield Panel("bar")

    console = Console(
        force_terminal=True,
        color_system="truecolor",
        width=20,
        height=40,
        legacy_windows=False,
    )

    with console.capture() as capture:
        console.print(Panel(Panels()), height=12)
    result = capture.get()
    print(repr(result))
    expected = "╭──────────────────╮\n│ ╭──────────────╮ │\n│ │ foo          │ │\n│ ╰──────────────╯ │\n│ ╭──────────────╮ │\n│ │ bar          │ │\n│ ╰──────────────╯ │\n│                  │\n│                  │\n│                  │\n│                  │\n╰──────────────────╯\n"

    assert result == expected
Esempio n. 3
0
def test_print_width_zero():
    console = Console()
    with console.capture() as capture:
        console.print("Hello", width=0)
    assert capture.get() == ""
Esempio n. 4
0
def print_to_string(x, format):
    console = rich.console.Console(color_system=None)
    with console.capture() as capture: 
        console.print(x)
    return capture.get()