Skip to main content

Module render

Module render 

Source
Expand description

Renderer split formalization (A8).

The CLI is already structure-first: every verb builds a #[derive(Serialize)] output struct, then routes through should_output_json to either serde_json::to_writer or a hand-written text renderer. This module codifies that pattern as a trait, plus an emit helper, so future verbs can’t drift back to println! at call sites.

Adding a new verb: define struct FooOutput { ... } deriving Serialize, impl RenderOutput for FooOutput { fn render_text(...) }, then call emit(&cli, repo.config(), &output) from the handler.

Structs§

RenderOpts
Optional knobs the text renderer respects. New options append at the tail; defaults stay backwards-compatible.
RepositoryContextInfo
RepositoryPresentation

Traits§

RenderOutput
Contract every CLI output type implements. The Serialize super-trait is what powers --output json; render_text is the human view. The same underlying value powers both — there is no separate “text-mode” code path that could drift from JSON.

Functions§

actor_display
Format an actor payload (provider, model) into a one-line display. Suppresses the literal “unknown” placeholder. Returns None when neither side carries a real value — callers should suppress the Actor: line entirely in that case.
emit
Resolve the format decision (JSON vs text) and emit accordingly.
emit_with_opts
Same as emit but lets the caller pass non-default render options (e.g. RenderOpts { short: true, .. } for log --oneline).
git_only_branch_summary
preview_list
Format a truncated one-line preview of an ordered string list for inclusion in a status / advice / blocker message. Used by every verb that would otherwise dump a 50+ item csv onto a single line: branch lists in status/log/show/diagnose, heavy-impact path lists in status/snapshot/thread/merge, and the Heavy-impact change: blocker built in repo::thread_advice.
real_or_none
Treat the harness “unknown” placeholder and empty/whitespace strings as absent so renderers don’t surface them as literal text. Mirrors the discipline in snapshot::clean_attribution_value — the harness writes “unknown” when it can’t identify provider/model from argv/env, and rendering that literally as anthropic/unknown is worse than just showing the meaningful side.
repository_mode_label
Human-facing repository mode label. JSON keeps the exact repository_capability / storage_model values; text output uses product language instead of storage implementation names.
repository_presentation
Presentation-only repository identity. This deliberately leaves Repository::capability_label() untouched: an isolated checkout that shares a Git-overlay object store is still technically opened through the native Heddle storage path, but user-facing status should say what the checkout is managed by.
shell_quote
POSIX-shell-quote a path for inclusion in a copy-pasteable command.
write_json_stdout
Write a single JSON value plus trailing newline to stdout.
write_stdout
Write text to stdout, treating BrokenPipe as a normal shell outcome.