termcinema_cli/render/
theme.rs

1use crate::args::CliArgs;
2use crate::style::patch_theme;
3use anyhow::Result;
4use termcinema_engine::{
5    ControlSpec, CursorSpec, StyleSpec, ThemeError, all_presets, resolve_theme,
6};
7
8/// Resolve the selected theme and apply CLI overrides.
9///
10/// Steps:
11/// - Loads the preset theme using `--theme` (or fallback default)
12/// - Applies user-specified overrides (font, speed, color, etc.)
13///
14/// Returns the fully configured:
15/// - [`StyleSpec`]  → visual properties (font, color)
16/// - [`CursorSpec`] → cursor character settings
17/// - [`ControlSpec`] → animation behavior
18///
19/// Returns an error if the theme name is invalid.
20pub(crate) fn resolve_and_patch_theme(
21    args: &CliArgs,
22    is_script: bool,
23) -> Result<(StyleSpec, CursorSpec, ControlSpec), ThemeError> {
24    // Resolve theme from name
25    let (mut style, mut cursor, mut control) = resolve_theme(args.theme.as_deref())?;
26
27    // Apply CLI-level overrides (font, speed, color, etc.)
28    patch_theme(&mut style, &mut cursor, &mut control, args, is_script);
29
30    Ok((style, cursor, control))
31}
32
33/// Print a list of all available theme presets to stdout.
34///
35/// Used by `--list-themes` to preview supported visual styles.
36pub(crate) fn print_theme_list() {
37    println!("\x1b[36m\nšŸŽØ Built-in themes:\x1b[0m");
38
39    for preset in all_presets() {
40        let slug = preset.name.to_lowercase().replace(' ', "_");
41        println!("   • {:<17} (\"{}\")", preset.name, slug);
42    }
43
44    println!("\nšŸ’” Pass a theme using: --theme \"poke_terminal\"");
45
46    println!();
47}
48
49/// Return the names of all built-in themes.
50///
51/// Useful for SDKs, GUI dropdowns, or autocomplete.
52#[allow(dead_code)]
53pub fn available_theme_names() -> Vec<&'static str> {
54    all_presets().into_iter().map(|t| t.name).collect()
55}