Skip to content

Decorators API

Visual decorator patterns for print output.

Decorator Classes

Line

pyreprint.core.decorators.Line(char='=', width=0) dataclass

A horizontal line decorator.

Parameters:

Name Type Description Default
char str

Character to repeat for the line.

'='
width int

Width of the line (0 = auto-detect terminal width).

0
Example

line = Line('=', 40) print(line) ========================================

pyreprint.core.decorators.Header(text, char='=', width=0, above=False) dataclass

A header with text and underline.

Parameters:

Name Type Description Default
text str

The header text.

required
char str

Character for the underline.

'='
width int

Width of the underline (0 = match text length).

0
above bool

Whether to include a line above the text.

False
Example

header = Header("My Section", char='=') print(header) My Section ==========

Box

pyreprint.core.decorators.Box(text, char='|', corner='+', horizontal='-', padding=1, width=0) dataclass

A box around text content.

Parameters:

Name Type Description Default
text str

The text to box.

required
char str

Character for vertical borders.

'|'
corner str

Character for corners.

'+'
horizontal str

Character for horizontal borders.

'-'
padding int

Padding inside the box.

1
width int

Width of the box (0 = auto-fit to text).

0
Example

box = Box("Hello World") print(box) +-------------+ | Hello World | +-------------+

pyreprint.core.decorators.Banner(text, char='*', width=0, padding_lines=0) dataclass

A full-width banner with centered text.

Parameters:

Name Type Description Default
text str

The banner text.

required
char str

Character for the border.

'*'
width int

Width of the banner (0 = auto-detect terminal width).

0
padding_lines int

Number of empty lines above/below text.

0
Example

banner = Banner("WELCOME", char='*', width=30) print(banner)


  • WELCOME *

Convenience Functions

line

pyreprint.core.decorators.line(char='=', width=0)

Create a horizontal line.

Parameters:

Name Type Description Default
char str

Character to repeat.

'='
width int

Width of the line (0 = auto-detect terminal width).

0

Returns:

Type Description
str

The line as a string.

Example

>>> print(line('=', 40))

Source code in pyreprint/core/decorators.py
def line(char: str = "=", width: int = 0) -> str:
    """Create a horizontal line.

    Args:
        char: Character to repeat.
        width: Width of the line (0 = auto-detect terminal width).

    Returns:
        The line as a string.

    Example:
        >>> print(line('=', 40))
        ========================================
    """
    return str(Line(char=char, width=width))

header

pyreprint.core.decorators.header(text, char='=', width=0, above=False)

Create a header with underline.

Parameters:

Name Type Description Default
text str

The header text.

required
char str

Character for the underline.

'='
width int

Width of the underline (0 = match text length).

0
above bool

Whether to include a line above the text.

False

Returns:

Type Description
str

The header as a string.

Example

print(header("My Section")) My Section ==========

Source code in pyreprint/core/decorators.py
def header(
    text: str,
    char: str = "=",
    width: int = 0,
    above: bool = False,
) -> str:
    """Create a header with underline.

    Args:
        text: The header text.
        char: Character for the underline.
        width: Width of the underline (0 = match text length).
        above: Whether to include a line above the text.

    Returns:
        The header as a string.

    Example:
        >>> print(header("My Section"))
        My Section
        ==========
    """
    return str(Header(text=text, char=char, width=width, above=above))

box

pyreprint.core.decorators.box(text, char='|', corner='+', horizontal='-', padding=1, width=0)

Create a box around text.

Parameters:

Name Type Description Default
text str

The text to box.

required
char str

Character for vertical borders.

'|'
corner str

Character for corners.

'+'
horizontal str

Character for horizontal borders.

'-'
padding int

Padding inside the box.

1
width int

Width of the box (0 = auto-fit to text).

0

Returns:

Type Description
str

The boxed text as a string.

Example

print(box("Hello")) +-------+ | Hello | +-------+

Source code in pyreprint/core/decorators.py
def box(
    text: str,
    char: str = "|",
    corner: str = "+",
    horizontal: str = "-",
    padding: int = 1,
    width: int = 0,
) -> str:
    """Create a box around text.

    Args:
        text: The text to box.
        char: Character for vertical borders.
        corner: Character for corners.
        horizontal: Character for horizontal borders.
        padding: Padding inside the box.
        width: Width of the box (0 = auto-fit to text).

    Returns:
        The boxed text as a string.

    Example:
        >>> print(box("Hello"))
        +-------+
        | Hello |
        +-------+
    """
    return str(
        Box(
            text=text,
            char=char,
            corner=corner,
            horizontal=horizontal,
            padding=padding,
            width=width,
        )
    )

pyreprint.core.decorators.banner(text, char='*', width=0, padding_lines=0)

Create a full-width banner with centered text.

Parameters:

Name Type Description Default
text str

The banner text.

required
char str

Character for the border.

'*'
width int

Width of the banner (0 = auto-detect terminal width).

0
padding_lines int

Number of empty lines above/below text.

0

Returns:

Type Description
str

The banner as a string.

Example

print(banner("WELCOME", width=30))


  • WELCOME *

Source code in pyreprint/core/decorators.py
def banner(
    text: str,
    char: str = "*",
    width: int = 0,
    padding_lines: int = 0,
) -> str:
    """Create a full-width banner with centered text.

    Args:
        text: The banner text.
        char: Character for the border.
        width: Width of the banner (0 = auto-detect terminal width).
        padding_lines: Number of empty lines above/below text.

    Returns:
        The banner as a string.

    Example:
        >>> print(banner("WELCOME", width=30))
        ******************************
        *          WELCOME           *
        ******************************
    """
    return str(Banner(text=text, char=char, width=width, padding_lines=padding_lines))