termcinema-cli 0.1.0

🎬 Animated terminal-to-SVG renderer CLI for the termcinema project
Documentation
//! Rendering orchestration module for `termcinema`.
//!
//! This module coordinates the full rendering pipeline,
//! including input resolution, theme application, layout generation,
//! and SVG rendering. It supports both CLI and SDK usage.
//!
//! It includes:
//! - Input loading from `--input`, `--script`, or stdin
//! - Escape sequence processing (unless `--no-escape`)
//! - Theme resolution with CLI patching
//! - Layout construction from dimensions and alignment
//! - Final SVG rendering via `termcinema-engine`
//!
//! For SDKs and embedders, [`render_svg_direct`] provides a simplified entrypoint.

mod font;
mod handle;
mod input;
mod output;
mod text;
mod theme;

pub(crate) use font::print_font_families;
pub(crate) use input::load_input;
pub(crate) use output::write_svg;
pub(crate) use text::resolve_plain_text;
pub(crate) use theme::{print_theme_list, resolve_and_patch_theme};

#[allow(unused_imports)]
pub use crate::render::theme::available_theme_names;

use crate::args::CliArgs;
use crate::render::handle::{handle_render, prepare_svg};
use std::process::exit;

/// Entrypoint for CLI execution.
///
/// Called by the `main.rs` binary. Delegates to [`handle_render`] to
/// run the complete rendering pipeline: input → theme/layout → SVG → output.
///
/// Prints any fatal error to stderr and exits with code 1.
#[allow(dead_code)]
pub(crate) fn run(args: CliArgs) {
    if let Err(e) = handle_render(&args) {
        eprintln!("{}", e);
        exit(1);
    }
}

/// SDK-friendly rendering entrypoint.
///
/// This function is designed for programmatic use, such as:
/// - WASM bindings
/// - Python FFI
/// - Embedded browser demos
///
/// It skips all CLI-specific input logic (stdin, `--input`, `--script`),
/// and directly renders an SVG from a raw input string + [`CliArgs`] config.
///
/// Script mode is disabled internally, and only layout/style-related fields are respected.
///
/// # Arguments
/// - `raw`: Raw input text (e.g. `"echo hello\\nworld"`)
/// - `args`: CLI-style arguments (theme, font, layout, etc)
///
/// # Returns
/// - `Ok(svg_string)` on success
/// - `Err(...)` if any step fails (invalid theme, layout error, etc)
#[allow(dead_code)]
pub fn render_svg_direct(raw: &str, args: &CliArgs) -> anyhow::Result<String> {
    prepare_svg(raw, false, args)
}