Skip to content

fancy_repr

A widget to wrap objects supporting the fancy_repr protocol.

FancyReprWidget

Bases: Widget

A widget that wraps objects supporting the fancy_repr protocol.

Source code in pytermgui/widgets/fancy_repr.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class FancyReprWidget(Widget):
    """A widget that wraps objects supporting the `fancy_repr` protocol."""

    def __init__(
        self, target: SupportsFancyRepr, starts_at: int = 0, **attrs: Any
    ) -> None:
        self.target = target
        self.starts_at = starts_at

        super().__init__(**attrs)

    def get_lines(self) -> list[str]:
        """Builds fancy repr of target and returns it."""

        start = self.starts_at
        lines = [
            tim.parse(line)
            for line in build_fancy_repr(self.target).splitlines()[start:]
        ]

        self.width = max(len(line) for line in lines)
        self.height = len(lines)

        return lines

get_lines()

Builds fancy repr of target and returns it.

Source code in pytermgui/widgets/fancy_repr.py
25
26
27
28
29
30
31
32
33
34
35
36
37
def get_lines(self) -> list[str]:
    """Builds fancy repr of target and returns it."""

    start = self.starts_at
    lines = [
        tim.parse(line)
        for line in build_fancy_repr(self.target).splitlines()[start:]
    ]

    self.width = max(len(line) for line in lines)
    self.height = len(lines)

    return lines