termcinema-cli 0.1.0

🎬 Animated terminal-to-SVG renderer CLI for the termcinema project
Documentation
use crate::args::CliArgs;
use crate::utils::warn_if_svg_too_large;
use anyhow::{Result, anyhow};
use std::fs::write;

/// Write the rendered SVG to file or print it to stdout, based on CLI flags.
///
/// Behavior:
/// - If `--output` is specified:
///     - Saves the SVG to the given file path
///     - Emits a size warning if the file exceeds 1MB
/// - Otherwise:
///     - Prints the SVG to stdout (for piping or previewing)
///
/// Returns an error if the file cannot be written.
pub(crate) fn write_svg(svg: String, args: &CliArgs) -> Result<()> {
    if let Some(path) = &args.output {
        // Write to file
        write(path, &svg).map_err(|_| anyhow!("Failed to write file: {}", path))?;
        println!("✅ Saved to {}", path);

        // Warn if file exceeds 1MB
        warn_if_svg_too_large(path, 1_000_000);
    } else {
        // Print to terminal
        println!("{}", svg);
    }

    Ok(())
}