Skip to content

pretty_print ¤

Classes:

  • Property

    A (property name, property value) pair

  • PropertyPrinter

    When you have (property name, property value) pairs

Property dataclass ¤

Property(
    name: str,
    value: Any,
    alt_value: Any = None,
    extra: str | list[str] = "",
    is_addr: bool = False,
    use_hex: bool = True,
)

A (property name, property value) pair with optional extra information.

Used by the PropertyPrinter.

Attributes:

name instance-attribute ¤

name: str

value instance-attribute ¤

value: Any

alt_value class-attribute instance-attribute ¤

alt_value: Any = None

extra class-attribute instance-attribute ¤

extra: str | list[str] = ''

is_addr class-attribute instance-attribute ¤

is_addr: bool = False

use_hex class-attribute instance-attribute ¤

use_hex: bool = True

PropertyPrinter ¤

PropertyPrinter(
    *,
    name_color_func: Callable[[str], str] | None = None,
    value_color_func: Callable[[str], str] | None = None,
    section_color_func: Callable[[str], str] | None = None,
    indent_size: int = 2,
)

When you have (property name, property value) pairs that you want to print, each on a new line.

Methods:

  • add

    Add a group of properties that should be aligned.

  • dump

    Return the built up string.

  • print

    Print the built up string.

  • clear

    Clear the built up string.

  • indent

    Increase indentation level by one.

  • unindent

    Decrease indentation level by one.

  • write

    Write raw string to the PropertyPrinter.

  • start_section

    Start a named section of properties that will have

  • end_section

    End a section.

  • set_padding

    Set the distance between the end of the longest

Attributes:

name_color_func instance-attribute ¤

name_color_func = name_color_func

value_color_func instance-attribute ¤

value_color_func = value_color_func

section_color_func instance-attribute ¤

section_color_func = section_color_func

indent_size instance-attribute ¤

indent_size = indent_size

indent_level instance-attribute ¤

indent_level = 0

padding instance-attribute ¤

padding = 2

text instance-attribute ¤

text = ''

add ¤

add(prop_group: list[Property]) -> None

Add a group of properties that should be aligned.

dump ¤

dump() -> str

Return the built up string.

print ¤

print() -> None

Print the built up string.

clear ¤

clear() -> None

Clear the built up string.

indent ¤

indent() -> None

Increase indentation level by one.

unindent ¤

unindent() -> None

Decrease indentation level by one.

write ¤

write(string: str) -> None

Write raw string to the PropertyPrinter.

start_section ¤

start_section(title: str, preamble: str = '') -> None

Start a named section of properties that will have increased indentation.

Don't forget to call end_section()!

end_section ¤

end_section() -> None

End a section.

set_padding ¤

set_padding(pad: int) -> None

Set the distance between the end of the longest property name and the start of the value column.