Skip to main content

Module ui

Module ui 

Source
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 stdout

The three public entry points cover the common call sites:

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:

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§

HelpChromeSettings
User-configurable settings for rendering CLI output.
RenderRuntime
Runtime terminal characteristics used when resolving render behavior.
RenderRuntimeBuilder
Builder for RenderRuntime.
RenderSettings
User-configurable settings for rendering CLI output.
RenderSettingsBuilder
Builder for RenderSettings.
ResolvedRenderSettings
Fully resolved rendering settings used by the document renderer.

Enums§

GuideDefaultFormat
Default output format to use when guide rendering is not explicitly requested.
HelpTableChrome
Border style override for help tables.
RenderBackend
Rendering backend selected for the current output pass.
TableBorderStyle
Border style applied to rendered tables.
TableOverflow
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.