Printer

source: bluebase/core/printer.py


class Printer(stream: TextIO, attrs: Sequence[tuple[str | None, str]], max_width: int = 16)[source]

Bases: object

A printer for result tables.

Rows are buffered internally and printed together when flush is called.

Variables:
  • stream (TextIO) – the output stream

  • max_width (int) – the maximum width of a column

  • columns (list[tuple[str, int]]) – the list of columns

  • rows (list[tuple[Any, ...]]) – the rows currently in the buffer

Raises:

ValueError – if the maximum width is too small

MIN_WIDTH: ClassVar[int] = 3

The minimum width of a column.

append(row: tuple[Any, ...]) → None[source]

Append a row to the buffer.

Raises:

ValueError – if the number of values in the row does not match the number of attributes

flush() → None[source]

Print all buffered rows and clear the buffer.