Skip to content

topmark.cli.console.utils

topmark / cli / console / utils

Small terminal-layout helpers for CLI console output.

get_console_line_width

get_console_line_width(*, default=80, max_width=100)

Return a safe line width for human-facing console rendering.

Parameters:

Name Type Description Default
default int

Fallback terminal width when no terminal size is available.

80
max_width int

Upper bound applied to wide terminals to keep output readable.

100

Returns:

Type Description
int

The smaller of the detected terminal width and max_width. If terminal

int

size detection fails, default is used.

Source code in src/topmark/cli/console/utils.py
def get_console_line_width(
    *,
    default: int = 80,
    max_width: int = 100,
) -> int:
    """Return a safe line width for human-facing console rendering.

    Args:
        default: Fallback terminal width when no terminal size is available.
        max_width: Upper bound applied to wide terminals to keep output readable.

    Returns:
        The smaller of the detected terminal width and `max_width`. If terminal
        size detection fails, `default` is used.
    """
    try:
        columns, _ = shutil.get_terminal_size(fallback=(default, 24))
    except OSError:
        columns: int = default
    return min(columns, max_width)