Exemplo n.º 1
0
def test_console_options_update():
    options = ConsoleOptions(min_width=10,
                             max_width=20,
                             is_terminal=False,
                             encoding="utf-8")
    options1 = options.update(width=15)
    assert options1.min_width == 15 and options1.max_width == 15

    options2 = options.update(min_width=5, max_width=15, justify="right")
    assert (options2.min_width == 5 and options2.max_width == 15
            and options2.justify == "right")

    options_copy = options.update()
    assert options_copy == options and options_copy is not options
Exemplo n.º 2
0
def test_console_options_update_height():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        max_height=25,
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    assert options.height is None
    render_options = options.update_height(12)
    assert options.height is None
    assert render_options.height == 12
    assert render_options.max_height == 12
Exemplo n.º 3
0
def test_box_substitute():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        legacy_windows=True,
        min_width=1,
        max_width=100,
        is_terminal=True,
        encoding="utf-8",
    )
    assert HEAVY.substitute(options) == SQUARE

    options.legacy_windows = False
    assert HEAVY.substitute(options) == HEAVY

    options.encoding = "ascii"
    assert HEAVY.substitute(options) == ASCII
Exemplo n.º 4
0
 def render(self, console: Console, options: ConsoleOptions) -> None:
     width = self.width or options.max_width or console.width
     options = options.update_dimensions(width, None)
     style = console.get_style(self.style)
     renderable = self.renderable
     if self.padding:
         renderable = Padding(renderable, self.padding)
     self._lines[:] = console.render_lines(renderable, options, style=style)
     self.size = Size(width, len(self._lines))
     self.page.emit_no_wait(PageUpdate(self.page))
Exemplo n.º 5
0
 def options(self) -> ConsoleOptions:
     return ConsoleOptions(
         max_height=self.size.height,
         size=self.size,
         legacy_windows=False,
         min_width=1,
         max_width=self.width,
         encoding='utf-8',
         is_terminal=False,
     )
Exemplo n.º 6
0
def test_console_options_update():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        max_height=25,
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    options1 = options.update(width=15)
    assert options1.min_width == 15 and options1.max_width == 15

    options2 = options.update(min_width=5, max_width=15, justify="right")
    assert (options2.min_width == 5 and options2.max_width == 15
            and options2.justify == "right")

    options_copy = options.update()
    assert options_copy == options and options_copy is not options
Exemplo n.º 7
0
def test_rich_console(live_render):
    options = ConsoleOptions(
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    rich_console = live_render.__rich_console__(Console(), options)
    assert [Segment("my string", Style.parse("none"))] == list(rich_console)
    live_render.style = "red"
    rich_console = live_render.__rich_console__(Console(), options)
    assert [Segment("my string", Style.parse("red"))] == list(rich_console)
Exemplo n.º 8
0
def test_rich_console():
    renderable = "test renderable"
    style = Style(color="red")
    options = ConsoleOptions(min_width=10,
                             max_width=20,
                             is_terminal=False,
                             encoding="utf-8")

    expected_outputs = [
        Segment(renderable, style=style),
        Segment(" " * (20 - len(renderable)), style=style),
        Segment("\n", style=None),
    ]
    padding_generator = Padding(renderable, style=style).__rich_console__(
        Console(), options)
    for output, expected in zip(padding_generator, expected_outputs):
        assert output == expected
Exemplo n.º 9
0
 def __rich_console__(self, console: Console,
                      options: ConsoleOptions) -> RenderResult:
     width = options.max_width
     height = options.height or 1
     yield from console.render(self.renderable,
                               options.update_dimensions(width, height))