craft_cli.printer module

The output (for different destinations) handler and helper functions.

class craft_cli.printer.Printer(log_filepath: pathlib.Path)[source]

Bases: object

Handle writing the different messages to the different outputs (out, err and log).

If TESTMODE is True, this class changes its behaviour: the spinner is never started, so there is no thread polluting messages when running tests if they take too long to run.

set_terminal_prefix(prefix: str) None[source]

Set the string to be prepended to every message shown to the terminal.

spin(message: _MessageInfo, spintext: str) None[source]

Write a line message including a spin text, only to a terminal.

show(stream: TextIO | None, text: str, *, ephemeral: bool = False, use_timestamp: bool = False, end_line: bool = False, avoid_logging: bool = False) None[source]

Show a text to the given stream if not stopped.

progress_bar(stream: TextIO | None, text: str, *, progress: float, total: float, use_timestamp: bool) None[source]

Show a progress bar to the given stream.

stop() None[source]

Stop the printing infrastructure.

In detail: - stop the spinner - add a new line to the screen (if needed) - close the log file

set_secrets(secrets: list[str]) None[source]

Set the list of strings that should be masked out in all outputs.