1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//! # 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 mode
//! - [`ColorMode`]: Light or dark color mode enum
//! - [`OutputMode`]: 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 rendering
//! - [`validate_template`]: Check templates for unknown style tags
//!
//! ## Quick Start
//!
//! ```rust
//! 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:
//!
//! ```rust
//! 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.
//!
//! ```rust
//! 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.
//!
//! ```rust
//! 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
//!
//! 1. Build a [`Theme`] using the fluent builder API or YAML.
//! 2. Load/define templates using regular MiniJinja syntax (`{{ value }}`, `{% for %}`, etc.)
//! with tag-based styling (`[name]content[/name]`).
//! 3. Call [`render`] for ad-hoc rendering or create a [`Renderer`] if you have many templates.
//! 4. 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
//!
//! ```rust
//! 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:
//!
//! ```rust
//! 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
//!
//! ```rust,ignore
//! 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 and app state
//! struct Database { /* ... */ }
//!
//! App::builder()
//! .app_state(Database::connect()?) // Shared state for all handlers
//! .command("list", |_m, ctx| {
//! let db = ctx.app_state.get_required::<Database>()?;
//! Ok(Output::Render(json!({"items": db.list()?})))
//! }, "{% for item in items %}{{ item }}\n{% endfor %}")
//! .build()?
//! .run(cmd, std::env::args());
//! ```
// Internal modules (standout-specific)
// Public submodules
// Re-export everything from standout-render
// This provides the rendering layer without CLI knowledge
pub use context;
pub use file_loader;
pub use style;
pub use tabular;
// Error type (from standout-render)
pub use RenderError;
// Style module exports (from standout-render)
pub use ;
// Theme module exports (from standout-render)
pub use ;
// Output module exports (from standout-render)
pub use ;
// Render module exports (from standout-render)
pub use ;
// Re-export BBParser types for template validation
pub use ;
// Utility exports (from standout-render)
pub use ;
// File loader exports (from standout-render)
pub use ;
// Embedded source types (from standout-render, for macros)
pub use ;
// Setup error type (standout-specific)
pub use SetupError;
// Macro re-exports
pub use ;
// Tabular derive macros
pub use ;
// Seeker query engine (re-export from standout-seeker)
pub use standout_seeker as seeker;
// Seeker derive macro (requires `features = ["macros"]`)
pub use Seekable;
// CLI integration