Skip to content

Printable

Printable

Base class for all objects that can be pretty printed.

This class provides an interface for pretty printing objects. The print method is the entry point for the printing process. The print_impl method is the implementation of the printing process and should be implemented by the derived classes.

pager

pager(
    printer: Printer | None = None,
    **options: Unpack["_PrintOptions"]
) -> None

Pretty print the object with a pager.

Parameters:

Name Type Description Default
printer Printer

Printer object to use for printing. If None, a new Printer object will be created.

None

Other Parameters:

Name Type Description
console Console

The console to use for printing. If not provided, a new console will be created.

analysis dict[SSAValue, Printable]

Analysis results to use for printing. If None, no analysis results

show_indent_mark bool

Whether to show the indentation mark.

theme Theme | dict | str

The theme to use for printing, defaults to "dark".

Note

This function also accepts all other rich.console.Console options.

Source code in src/kirin/print/printable.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def pager(
    self,
    printer: Printer | None = None,
    **options: Unpack["_PrintOptions"],
) -> None:
    """Pretty print the object with a pager.

    Args:
        printer (Printer):
            `Printer` object to use for printing.
            If None, a new `Printer` object will be created.

    Keyword Args:
        console (rich.Console):
            The console to use for printing. If not provided, a new console
            will be created.
        analysis (dict[ir.SSAValue, Printable]):
            Analysis results to use for printing. If `None`, no analysis results
        show_indent_mark (bool):
            Whether to show the indentation mark.
        theme (Theme | dict | str):
            The theme to use for printing, defaults to "dark".

    !!! note
        This function also accepts all other `rich.console.Console` options.
    """
    printer = self.__get_printer(printer, **options)
    with printer.console.pager(styles=True, links=True):
        self.print(printer)

print

print(
    printer: Printer | None = None,
    end: str = "\n",
    **options: Unpack["_PrintOptions"]
) -> None

Entry point of the printing process.

Parameters:

Name Type Description Default
printer Printer

Printer object to use for printing. If None, a new Printer object will be created.

None

Other Parameters:

Name Type Description
console Console

The console to use for printing. If not provided, a new console will be created.

analysis dict[SSAValue, Printable]

Analysis results to use for printing. If None, no analysis results

show_indent_mark bool

Whether to show the indentation mark.

theme Theme | dict | str

The theme to use for printing, defaults to "dark".

Note

This function also accepts all other rich.console.Console options.

Source code in src/kirin/print/printable.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def print(
    self,
    printer: Printer | None = None,
    end: str = "\n",
    **options: Unpack["_PrintOptions"],
) -> None:
    """
    Entry point of the printing process.

    Args:
        printer (Printer):
            `Printer` object to use for printing.
            If None, a new `Printer` object will be created.

    Keyword Args:
        console (rich.Console):
            The console to use for printing. If not provided, a new console
            will be created.
        analysis (dict[ir.SSAValue, Printable]):
            Analysis results to use for printing. If `None`, no analysis results
        show_indent_mark (bool):
            Whether to show the indentation mark.
        theme (Theme | dict | str):
            The theme to use for printing, defaults to "dark".

    !!! note
        This function also accepts all other `rich.console.Console` options.
    """
    printer = self.__get_printer(printer, **options)
    self.print_impl(printer)
    printer.plain_print(end)

print_str

print_str(
    printer: Printer | None = None,
    end: str = "\n",
    **options: Unpack["_PrintOptions"]
) -> str

Print the object to a string.

Parameters:

Name Type Description Default
printer Printer

Printer object to use for printing. If None, a new Printer object will be created.

None

Other Parameters:

Name Type Description
console Console

The console to use for printing. If not provided, a new console will be created.

analysis dict[SSAValue, Printable]

Analysis results to use for printing. If None, no analysis results

show_indent_mark bool

Whether to show the indentation mark.

theme Theme | dict | str

The theme to use for printing, defaults to "dark".

Note

This function also accepts all other rich.console.Console options.

Source code in src/kirin/print/printable.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def print_str(
    self,
    printer: Printer | None = None,
    end: str = "\n",
    **options: Unpack["_PrintOptions"],
) -> str:
    """Print the object to a string.

    Args:
        printer (Printer):
            `Printer` object to use for printing.
            If None, a new `Printer` object will be created.

    Keyword Args:
        console (rich.Console):
            The console to use for printing. If not provided, a new console
            will be created.
        analysis (dict[ir.SSAValue, Printable]):
            Analysis results to use for printing. If `None`, no analysis results
        show_indent_mark (bool):
            Whether to show the indentation mark.
        theme (Theme | dict | str):
            The theme to use for printing, defaults to "dark".

    !!! note
        This function also accepts all other `rich.console.Console` options.
    """
    printer = self.__get_printer(printer, **options)
    with printer.string_io() as stream:
        self.print(printer, end=end, **options)
        return stream.getvalue()