termcinema-cli 0.1.0

🎬 Animated terminal-to-SVG renderer CLI for the termcinema project
Documentation
use crate::args::CliArgs;
use crate::layout::build_layout;
use crate::render::{
    load_input, print_font_families, print_theme_list, resolve_and_patch_theme, resolve_plain_text,
    write_svg,
};
use anyhow::Result;
use termcinema_engine::render_svg_from_input as render_svg;

/// Top-level render handler for CLI.
///
/// Based on user arguments, this either:
/// - Prints the available fonts if `--list-fonts` is set
/// - Prints the available themes if `--list-themes` is set
/// - Loads input (text or script), prepares the theme/layout config,
///   renders an SVG, and writes the result to file or stdout
pub(crate) fn handle_render(args: &CliArgs) -> Result<()> {
    // Print fonts list if requested
    if args.list_fonts {
        print_font_families();
        return Ok(());
    }

    // Print themes list if requested
    if args.list_themes {
        print_theme_list();
        return Ok(());
    }

    // Load raw input (from --input, --script, stdin, or file), and detect script mode
    let (raw, script_mode) = load_input(args)?;

    // Generate SVG from arguments
    let svg = prepare_svg(&raw, script_mode, args)?;

    // Output SVG to destination
    write_svg(svg, args)
}

/// Prepare and render an SVG based on raw input and CLI arguments.
///
/// Steps:
/// - Applies escape sequence resolution (unless `--no-escape`)
/// - Resolves theme and patches styles accordingly
/// - Builds layout from CLI flags
/// - Calls the rendering backend to generate SVG output
pub(crate) fn prepare_svg(raw: &str, is_script: bool, args: &CliArgs) -> Result<String> {
    // Resolve escape sequences if allowed
    let text = resolve_plain_text(raw.to_string(), is_script, args.no_escape);

    // Load and patch style + cursor
    let (style, cursor, control) = resolve_and_patch_theme(args, is_script)?;

    // Build layout configuration
    let layout = build_layout(args);

    // Render SVG using termcinema-engine
    let svg = render_svg(&text, is_script, &style, &layout, &cursor, &control);

    Ok(svg)
}