animedex.render.tty

TTY renderer: human-friendly tables with explicit source markers.

The TTY path always shows the [src: <backend>] annotation per plans/03 §5 because the human reader cannot inspect a JSON _source field. render_for_stream() is the auto-switching entry point used by the CLI: it picks render_tty() when the destination is a terminal and the JSON renderer otherwise so piped output remains parseable.

is_terminal

animedex.render.tty.is_terminal(stream: Any) bool[source]

Return True when stream is connected to a terminal.

Parameters:

stream (Any) – Anything with an isatty method (typically sys.stdout in production, a fake stream in tests).

Returns:

True when the stream reports it is a TTY.

Return type:

bool

render_tty

animedex.render.tty.render_tty(model: AnimedexModel, *, stream: Any = None) str[source]

Render a model into the human-friendly TTY form.

Dispatches on type: Anime, Character, Staff, Studio, TraceHit, and TraceQuota each get a multi-line block. Other models fall back to a default representation that still carries the source marker.

Parameters:
  • model (AnimedexModel) – The AnimedexModel instance to render.

  • stream (Any) – Optional destination stream used to pick terminal glyphs that the stream can encode.

Returns:

The TTY-friendly string.

Return type:

str

render_for_stream

animedex.render.tty.render_for_stream(model: AnimedexModel, stream: Any) str[source]

Render the way the CLI does for a given stream.

When stream is a TTY, returns the TTY-friendly output; otherwise returns source-attributed JSON. This is the single entry point CLI commands call so the “TTY vs pipe” decision lives in one place.

Parameters:
  • model (AnimedexModel) – The AnimedexModel instance to render.

  • stream (Any) – Destination stream (typically sys.stdout).

Returns:

Rendered payload.

Return type:

str

selftest

animedex.render.tty.selftest() bool[source]

Smoke-test the TTY renderer and the auto-switch.

Returns:

True on success.

Return type:

bool