Expand description
Rendering, theming, and structured output helpers. The UI module turns structured output into predictable terminal text while keeping rendering decisions separate from business logic.
Data changes shape four times on the way from DSL output to terminal text:
OutputResult { items: Rows([{uid:"alice", cn:"Alice"},...]), meta }
│
▼ RenderSettings::resolve_render_plan(output)
│ selects format: explicit > metadata hint > shape-inference
│ Groups → Table
│ single-value rows → Value
│ 1 row → Mreg (key/value pairs)
│ many rows → Table
│
ResolvedRenderPlan {
format: Table,
render: ResolvedRenderSettings { backend: Rich|Plain, color, width, theme, … },
guide: ResolvedGuideRenderSettings,
mreg: ResolvedMregRenderSettings,
}
│
▼ format::build_document_from_output_plan(output, plan)
│ dispatches by format into typed block variants
│ Table/Markdown → Block::Table(TableBlock { headers, rows: Vec<Vec<Value>>, align })
│ Json → Block::Json(JsonBlock { value })
│ Mreg → Block::Mreg(MregBlock { rows: Vec<MregRow> })
│ Value → Block::Value(ValueBlock { values: Vec<String> })
│ Guide → Block::Panel + Block::Table + Block::Line …
│
Document { blocks: Vec<Block> }
│
▼ renderer::render_document(document, resolved_settings)
│ precomputes LayoutContext once (width, unicode, margin)
│ renders each block: Rich = color + box-drawing; Plain = ASCII only
│
String ← terminal text ready for stdoutThe three public entry points cover the common call sites:
crate::ui::render_output— full pipeline fromOutputResulttoStringcrate::ui::render_rows— convenience wrapper when you already haveVec<Row>crate::ui::render_document— skip straight to rendering a pre-builtDocument
Minimal direct-render path:
use osp_cli::core::output::OutputFormat;
use osp_cli::row;
use osp_cli::ui::{RenderSettings, render_rows};
let rendered = render_rows(
&[row! { "uid" => "alice" }],
&RenderSettings::test_plain(OutputFormat::Json),
);
assert!(rendered.contains("\"uid\": \"alice\""));Each has a _for_copy sibling that forces Plain backend and strips
box-drawing/ANSI for clipboard-safe output.
Debugging tip: keep “document shaping” and “terminal rendering” separate.
If output looks structurally wrong (missing columns, wrong format), the
bug is in format. If it looks semantically right but visually garbled
(bad color, wrong width), the bug is in the renderer or settings resolution.
Contract:
- UI code may depend on structured output and render settings
- it should not own config precedence, command execution, or provider I/O
- terminal styling decisions should stay here rather than leaking into the rest of the app
Public API shape:
- semantic payloads like
crate::ui::Documentstay direct and cheap to inspect crate::ui::RenderRuntimeBuilderandcrate::ui::RenderSettingsBuilderare the guided construction path for the heavier rendering configuration surfacescrate::ui::ResolvedRenderSettingsstays a derived value, not another mutable configuration object- guided render configuration follows the crate-wide naming rule:
builder(...)returns*Builder, builder setters usewith_*, andbuild()is the terminal step - callers that only need a stable default baseline can use
crate::ui::RenderSettings::builder,crate::ui::RenderRuntime::builder, orcrate::ui::RenderSettings::test_plain
Re-exports§
pub use chrome::RuledSectionPolicy;pub use chrome::SectionFrameStyle;pub use chrome::SectionRenderContext;pub use chrome::SectionStyleTokens;pub use chrome::render_section_block_with_overrides;pub use chrome::render_section_divider_with_overrides;pub use clipboard::ClipboardError;pub use clipboard::ClipboardService;pub use document::Block;pub use document::CodeBlock;pub use document::Document;pub use document::JsonBlock;pub use document::LineBlock;pub use document::LinePart;pub use document::MregBlock;pub use document::MregEntry;pub use document::MregRow;pub use document::MregValue;pub use document::PanelBlock;pub use document::PanelRules;pub use document::TableAlign;pub use document::TableBlock;pub use document::TableStyle;pub use document::ValueBlock;pub use inline::line_from_inline;pub use inline::parts_from_inline;pub use inline::render_inline;pub use interactive::Interactive;pub use interactive::InteractiveResult;pub use interactive::InteractiveRuntime;pub use interactive::Spinner;pub use messages::GroupedRenderOptions;pub use messages::MessageBuffer;pub use messages::MessageLayout;pub use messages::MessageLevel;pub use messages::UiMessage;pub use messages::adjust_verbosity;pub use style::StyleOverrides;pub use style::StyleToken;pub use theme::DEFAULT_THEME_NAME;pub use theme::ThemeDefinition;pub use theme::ThemeOverrides;pub use theme::ThemePalette;pub use theme::all_themes;pub use theme::available_theme_names;pub use theme::builtin_themes;pub use theme::display_name_from_id;pub use theme::find_builtin_theme;pub use theme::find_theme;pub use theme::is_known_theme;pub use theme::normalize_theme_name;pub use theme::resolve_theme;
Modules§
- chrome
- Reusable section chrome helpers for messages, help, and guide rendering.
- clipboard
- Clipboard integration helpers for copy-safe output flows.
- document
- Structured display blocks used as the boundary between formatting and terminal rendering.
- inline
- Lightweight inline-markup parsing and rendering helpers.
- interactive
- Interactive terminal helpers for prompts and transient status UI.
- messages
- Buffered user-facing messages and their rendering helpers.
- style
- Semantic style tokens and explicit style overrides layered over the theme.
- theme
- Built-in theme definitions and theme lookup helpers.
Structs§
- Help
Chrome Settings - User-configurable settings for rendering CLI output.
- Render
Runtime - Runtime terminal characteristics used when resolving render behavior.
- Render
Runtime Builder - Builder for
RenderRuntime. - Render
Settings - User-configurable settings for rendering CLI output.
- Render
Settings Builder - Builder for
RenderSettings. - Resolved
Render Settings - Fully resolved rendering settings used by the document renderer.
Enums§
- Guide
Default Format - Default output format to use when guide rendering is not explicitly requested.
- Help
Table Chrome - Border style override for help tables.
- Render
Backend - Rendering backend selected for the current output pass.
- Table
Border Style - Border style applied to rendered tables.
- Table
Overflow - Overflow strategy for table cell content.
Functions§
- copy_
output_ to_ clipboard - Copies rendered output to the configured clipboard service.
- copy_
rows_ to_ clipboard - Copies rendered rows to the configured clipboard service.
- render_
document - Renders a document directly with the resolved UI settings.
- render_
document_ for_ copy - Renders a document in plain copy-safe form.
- render_
output - Renders a structured output result using the configured output format.
- render_
output_ for_ copy - Renders an output result in plain copy-safe form.
- render_
rows - Renders rows using the configured output format.
- render_
rows_ for_ copy - Renders rows in plain copy-safe form.