Expand description
§Standout - Non-Interactive CLI Framework
Standout is a CLI output framework that decouples your application logic from terminal presentation. It provides:
- Template rendering with MiniJinja + styled output
- Adaptive themes for named style definitions with light/dark mode support
- Automatic terminal capability detection (TTY, CLICOLOR, etc.)
- Output mode control (Auto/Term/Text/TermDebug)
- Help topics system for extended documentation
- Pager support for long content
This crate is CLI-agnostic at its core - it doesn’t care how you parse arguments.
For clap integration, see the cli module.
§Core Concepts
Theme: Named collection of adaptive styles that respond to light/dark modeColorMode: Light or dark color mode enumOutputMode: Control output formatting (Auto/Term/Text/TermDebug)topics: Help topics system for extended documentation- Style syntax: Tag-based styling
[name]content[/name] Renderer: Pre-compile templates for repeated renderingvalidate_template: Check templates for unknown style tags
§Quick Start
use standout::{render, Theme};
use console::Style;
use serde::Serialize;
#[derive(Serialize)]
struct Summary {
title: String,
total: usize,
}
let theme = Theme::new()
.add("title", Style::new().bold())
.add("count", Style::new().cyan());
let template = r#"
[title]{{ title }}[/title]
---------------------------
Total items: [count]{{ total }}[/count]
"#;
let output = render(
template,
&Summary { title: "Report".into(), total: 3 },
&theme,
).unwrap();
println!("{}", output);§Tag-Based Styling
Use tag syntax [name]content[/name] for styling both static and dynamic content:
use standout::{render_with_output, Theme, OutputMode};
use console::Style;
use serde::Serialize;
#[derive(Serialize)]
struct Data { name: String, count: usize }
let theme = Theme::new()
.add("title", Style::new().bold())
.add("count", Style::new().cyan());
let template = r#"[title]Report[/title]: [count]{{ count }}[/count] items by {{ name }}"#;
let output = render_with_output(
template,
&Data { name: "Alice".into(), count: 42 },
&theme,
OutputMode::Text,
).unwrap();
assert_eq!(output, "Report: 42 items by Alice");Unknown tags show a ? marker in terminal output: [unknown?]text[/unknown?].
Use validate_template to catch typos during development.
§Adaptive Themes (Light & Dark)
Themes are inherently adaptive. Individual styles can define mode-specific variations that are automatically selected based on the user’s OS color mode.
use standout::Theme;
use console::Style;
let theme = Theme::new()
// Non-adaptive style (same in all modes)
.add("header", Style::new().bold().cyan())
// Adaptive style with light/dark variants
.add_adaptive(
"panel",
Style::new(), // Base
Some(Style::new().fg(console::Color::Black)), // Light mode
Some(Style::new().fg(console::Color::White)), // Dark mode
);
// Rendering automatically detects OS color mode
let output = standout::render(
r#"[panel]active[/panel]"#,
&serde_json::json!({}),
&theme,
).unwrap();§YAML-Based Themes
Themes can also be loaded from YAML files, which is convenient for UI designers who may not be Rust programmers.
use standout::Theme;
let theme = Theme::from_yaml(r#"
header:
fg: cyan
bold: true
panel:
fg: gray
light:
fg: black
dark:
fg: white
title: header
"#).unwrap();§Rendering Strategy
- Build a
Themeusing the fluent builder API or YAML. - Load/define templates using regular MiniJinja syntax (
{{ value }},{% for %}, etc.) with tag-based styling ([name]content[/name]). - Call
renderfor ad-hoc rendering or create aRendererif you have many templates. - Standout processes style tags, auto-detects colors, and returns the final string.
Everything from the theme inward is pure Rust data: no code outside Standout needs to touch stdout/stderr or ANSI escape sequences directly.
§More Examples
use standout::{Renderer, Theme};
use console::Style;
use serde::Serialize;
#[derive(Serialize)]
struct Entry { label: String, value: i32 }
let theme = Theme::new()
.add("label", Style::new().bold())
.add("value", Style::new().green());
let mut renderer = Renderer::new(theme).unwrap();
renderer.add_template("row", "[label]{{ label }}[/label]: [value]{{ value }}[/value]").unwrap();
let rendered = renderer.render("row", &Entry { label: "Count".into(), value: 42 }).unwrap();
assert_eq!(rendered, "Count: 42");§Help Topics System
The topics module provides a help topics system for extended documentation:
use standout::topics::{Topic, TopicRegistry, TopicType, render_topic};
// Create and populate a registry
let mut registry = TopicRegistry::new();
registry.add_topic(Topic::new(
"Storage",
"Notes are stored in ~/.notes/\n\nEach note is a separate file.",
TopicType::Text,
Some("storage".to_string()),
));
// Render a topic
if let Some(topic) = registry.get_topic("storage") {
let output = render_topic(topic, None).unwrap();
println!("{}", output);
}
// Load topics from a directory
registry.add_from_directory_if_exists("docs/topics").ok();§Integration with Clap
The cli module provides full clap integration with:
- Command dispatch with automatic template rendering
- Help command interception (
help,help <topic>,help topics) - Output flag injection (
--output=auto|term|text|json) - Styled help rendering
use clap::Command;
use standout::cli::{App, HandlerResult, Output};
// Simple parsing with styled help
let matches = App::parse(Command::new("my-app"));
// Full application with command dispatch
App::builder()
.command("list", |_m, _ctx| {
Ok(Output::Render(json!({"items": ["a", "b"]})))
}, "{% for item in items %}{{ item }}\n{% endfor %}")
.build()?
.run(cmd, std::env::args());Re-exports§
pub use standout_seeker as seeker;
Modules§
- assets
- Framework-supplied assets (templates and styles).
- cli
- CLI dispatch and integration for clap-based applications.
- context
- Context injection for template rendering.
- file_
loader - File-based resource loading for templates and stylesheets.
- style
- Style system for named styles, aliases, and YAML-based stylesheets.
- tabular
- Unicode-aware column formatting for terminal tables.
- topics
- Help topics system for extended CLI documentation.
- views
- View abstractions for standardized CLI output patterns.
Macros§
- dispatch
- Declarative macro for defining command dispatch tables.
- embed_
styles - Embeds all stylesheet files from a directory at compile time.
- embed_
templates - Embeds all template files from a directory at compile time.
Structs§
- Embedded
Source - Embedded resource source with optional debug hot-reload.
- Error
- Represents template errors.
- File
Registry - Generic registry for file-based resources.
- File
Registry Config - Configuration for a file registry.
- Loaded
File - A file discovered during directory walking.
- Renderer
- A renderer with pre-registered templates.
- Style
Attributes - Parsed style attributes from YAML.
- Styles
- A collection of named styles.
- Stylesheet
Registry - Registry for stylesheet/theme resolution from multiple sources.
- Stylesheet
Resource - Marker type for stylesheet resources.
- Template
File - A template file discovered during directory walking.
- Template
Registry - Registry for template resolution from multiple sources.
- Template
Resource - Marker type for template resources.
- Theme
- A named collection of styles used when rendering templates.
- Theme
Variants - Theme variants containing styles for base, light, and dark modes.
- Unknown
TagError - An error representing an unknown tag in the input.
- Unknown
TagErrors - A collection of unknown tag errors found during parsing.
Enums§
- Color
Def - Parsed color definition from stylesheet.
- Color
Mode - The user’s preferred color mode.
- Load
Error - Error type for file loading operations.
- Loaded
Entry - How a resource is stored—file path (dev) or content (release).
- Output
Destination - Destination for rendered output.
- Output
Mode - Controls how output is rendered.
- Registry
Error - Error type for template registry operations.
- Resolved
Template - How a template’s content is stored or accessed.
- Setup
Error - Error type for setup operations.
- Style
Definition - Parsed style definition from YAML.
- Style
Validation Error - Error returned when style validation fails.
- Style
Value - A style value that can be either a concrete style or an alias to another style.
- Stylesheet
Error - Error type for stylesheet parsing failures.
- Unknown
TagKind - The kind of unknown tag encountered.
Constants§
- DEFAULT_
MISSING_ STYLE_ INDICATOR - Default prefix shown when a style name is not found.
- STYLESHEET_
EXTENSIONS - Recognized stylesheet file extensions in priority order.
- TEMPLATE_
EXTENSIONS - Recognized template file extensions in priority order.
Functions§
- build_
embedded_ registry - Builds a registry map from embedded entries with extension priority handling.
- detect_
color_ mode - Detects the user’s preferred color mode from the OS.
- extension_
priority - Returns the extension priority for a filename (lower = higher priority).
- flatten_
json_ for_ csv - Flattens a JSON Value into a list of records for CSV export.
- parse_
css - Parses a CSS stylesheet and builds theme variants.
- parse_
stylesheet - Parses a YAML stylesheet and builds theme variants.
- render
- Renders a template with automatic terminal color detection.
- render_
auto - Auto-dispatches between template rendering and direct serialization.
- render_
auto_ with_ context - Auto-dispatches with context injection support.
- render_
auto_ with_ spec - Auto-dispatches with granular control over structured output.
- render_
with_ context - Renders a template with additional context objects injected.
- render_
with_ mode - Renders a template with explicit output mode and color mode control.
- render_
with_ output - Renders a template with explicit output mode control.
- render_
with_ vars - Renders a template with additional variables injected into the context.
- rgb_
to_ ansi256 - Converts an RGB triplet to the nearest ANSI 256-color palette index.
- rgb_
to_ truecolor - Placeholder helper for true-color output.
- set_
theme_ detector - Overrides the detector used to determine whether the user prefers a light or dark theme.
- strip_
extension - Strips a recognized extension from a filename.
- truncate_
to_ width - Truncates a string to fit within a maximum display width, adding ellipsis if needed.
- validate_
template - Validates a template for unknown style tags.
- walk_
dir - Walks a directory recursively and collects files with recognized extensions.
- walk_
template_ dir - Walks a template directory and collects template files.
- write_
binary_ output - Writes binary content to the specified destination.
- write_
output - Writes text content to the specified destination.
Type Aliases§
- Embedded
Styles - Type alias for embedded stylesheets.
- Embedded
Templates - Type alias for embedded templates.
Derive Macros§
- Seekable
- Derives the
Seekabletrait for query-enabled structs. - Tabular
- Derives a
TabularSpecfrom struct field annotations. - Tabular
Row - Derives optimized row extraction for tabular formatting.