yera.console.console_renderer

ConsoleRenderer: owns all console output — lifecycle panels and content blocks.

Handles all inter-block whitespace, lifecycle panel printing, and content block rendering so that the caller (stream_handler) never needs to call console.print() directly.

Symbols

class ConsoleRenderer — Owns all console output: lifecycle panels and content blocks.

ConsoleRenderer

Owns all console output: lifecycle panels and content blocks.

Uses type-based match on BlockData for dispatch. Returns collected user input (if any) so the caller can decide how to handle it — no event stream side effects.

Whitespace contract

  • Startup panel — printed first with no preceding whitespace.
  • App panel — preceded by a blank line (terminating any pending content line first) and followed by a blank line before content.
  • Between content blocks — a blank line is emitted whenever the block_id changes (i.e. a new block starts).
  • Markdown streaming — successive chunks with the same block_id are printed with end="" so they concatenate on one line.
  • Non-markdown informational blocks (tables, actions, …) — printed with the default end (newline) which terminates the line.
  • Await-user blocks — the prompt prints with end="" (the line is left unterminated), so _pending_newline is set to True.
  • Exit panel — :meth:print_exit terminates any pending content line, emits a blank separator, prints the panel, and adds a trailing blank line.

Methods

print_startup — Print the Startup panel. No surrounding whitespace — it is the first output.
print_app — Print the app Identity panel if the app has changed.
print_exit — Finalise content output and print the Exit panel with a trailing blank line.
print_event — Render an output event to the console.
finalise — Terminate any pending line and emit a blank line.

ConsoleRenderer.print_startup

print_startup(
    start_time: datetime,
    top_level_app_name: str | None = None,
) → None

Print the Startup panel. No surrounding whitespace — it is the first output.

ConsoleRenderer.print_app

print_app(
    app_id: str,
) → None

Print the app Identity panel if the app has changed.

No-op when called with the same app_id that is already current. Otherwise terminates any pending content line, emits a blank-line separator, prints the panel, then emits another blank line before subsequent content. Handles both the first-app case (after Startup) and subsequent-app transitions.

ConsoleRenderer.print_exit

print_exit(
    exit_data: ExitEventData,
    run_time_seconds: float,
    failing_app_name: str | None,
) → None

Finalise content output and print the Exit panel with a trailing blank line.

ConsoleRenderer.print_event

print_event(
    event: OutputEvent,
) → str | None

Render an output event to the console.

Handles between-block blank lines, markdown streaming (end="" so chunks stay on one line), and line termination for non-markdown blocks. The caller must not emit any extra newlines after calling this.

ConsoleRenderer.finalise

finalise() → None

Terminate any pending line and emit a blank line.

Called by :meth:print_exit before the Exit panel, or can be called directly if the caller needs to insert a gap after the last content block.