Skip to content

topmark.cli.console.click_console

topmark / cli / console / click_console

Click-backed console implementation for TopMark CLI output.

This module provides the primary concrete console used by CLI commands for user-facing output. It is intentionally separate from the logging subsystem.

ClickStyleKwargs

Bases: TypedDict

Documented subset of keyword arguments accepted by click.style().

Console

Console(*, enable_color=True, out=None, err=None)

Bases: ConsoleProtocol

Program-output console, independent from the logger.

Parameters:

Name Type Description Default
enable_color bool

If True, enables ANSI color codes in the output. Otherwise, all output is plain text.

True
out TextIO | None

The text stream to use for standard output. Defaults to sys.stdout.

None
err TextIO | None

The text stream to use for error output. Defaults to sys.stderr.

None

Attributes:

Name Type Description
enable_color bool

Whether to emit ANSI color codes.

out TextIO | None

Stream for standard output (defaults to sys.stdout).

err TextIO | None

Stream for error output (defaults to sys.stderr).

Source code in src/topmark/cli/console/click_console.py
def __init__(
    self,
    *,
    enable_color: bool = True,
    out: TextIO | None = None,
    err: TextIO | None = None,
) -> None:
    self.enable_color = enable_color
    self.out = out or sys.stdout
    self.err = err or sys.stderr

print

print(text='', *, nl=True)

Write a message to stdout.

Parameters:

Name Type Description Default
text str

Message text.

''
nl bool

If True, append a newline.

True
Source code in src/topmark/cli/console/click_console.py
def print(self, text: str = "", *, nl: bool = True) -> None:
    """Write a message to stdout.

    Args:
        text: Message text.
        nl: If True, append a newline.
    """
    click.echo(text, nl=nl, file=self.out, color=self.enable_color)

warn

warn(text, *, nl=True)

Write a warning message to stderr.

Parameters:

Name Type Description Default
text str

Warning text.

required
nl bool

If True, append a newline.

True
Source code in src/topmark/cli/console/click_console.py
def warn(self, text: str, *, nl: bool = True) -> None:
    """Write a warning message to stderr.

    Args:
        text: Warning text.
        nl: If True, append a newline.
    """
    click.secho(text, nl=nl, file=self.err, color=self.enable_color, fg="yellow")

error

error(text, *, nl=True)

Write an error message to stderr.

Parameters:

Name Type Description Default
text str

Error text.

required
nl bool

If True, append a newline.

True
Source code in src/topmark/cli/console/click_console.py
def error(self, text: str, *, nl: bool = True) -> None:
    """Write an error message to stderr.

    Args:
        text: Error text.
        nl: If True, append a newline.
    """
    click.secho(text, nl=nl, file=self.err, color=self.enable_color, fg="bright_red")