termcinema-engine 0.1.0

🧠 Core typewriter-style terminal animation engine (SVG renderer) for termcinema
Documentation
//! High-level SVG renderer dispatcher (glue layer).
//!
//! This module routes raw textual input to appropriate SVG rendering backends
//! based on the display mode (typing or REPL shell).
//!
//! It supports:
//! - Typing-style rendering with animated cursor and per-character fade-ins;
//! - REPL-style rendering from structured shell script blocks;
//! - Unified interface for embedding into CLI, web, or backend use cases;
//! - Full access to visual and behavioral configuration via `StyleSpec`,
//!   `LayoutSpec`, `CursorSpec`, and `ControlSpec`.
//!
//! Used by consumers to generate complete SVG strings from raw user input.

use crate::parser::parse_shell_blocks;
use crate::render::{render_repl_svg, render_typing_svg};
use crate::{ContentSpec, ControlSpec, CursorSpec, LayoutSpec, StyleSpec};

// ─────────────── 🔗 Public Glue-layer APIs ───────────────

/// Render a full SVG output based on raw text input and display mode.
///
/// If `from_script` is `true`, the text is interpreted as a shell session
/// (e.g. including prompt, commands, output) and rendered in REPL style.
/// Otherwise, it is rendered as a continuous typing animation.
///
/// Returns the full SVG string.
pub fn render_svg_from_input(
    text: &str,
    from_script: bool,
    style: &StyleSpec,
    layout: &LayoutSpec,
    cursor: &CursorSpec,
    control: &ControlSpec,
) -> String {
    if from_script {
        render_repl_from_script(text, style, layout, control)
    } else {
        render_typing_from_text(text, style, layout, cursor, control)
    }
}

/// Render a typing-style SVG from raw text.
///
/// The entire input is treated as a single block of text to be animated
/// character-by-character using the provided visual configuration.
pub fn render_typing_from_text(
    text: &str,
    style: &StyleSpec,
    layout: &LayoutSpec,
    cursor: &CursorSpec,
    control: &ControlSpec,
) -> String {
    let content = ContentSpec {
        text: text.to_string(),
    };
    render_typing_svg(&content, style, layout, cursor, control)
}

/// Render a REPL-style SVG from shell script input.
///
/// The script is parsed into a sequence of commands and outputs
/// (e.g. `prompt → command → output` groups), and each is rendered
/// with consistent spacing and layout.
pub fn render_repl_from_script(
    script: &str,
    style: &StyleSpec,
    layout: &LayoutSpec,
    control: &ControlSpec,
) -> String {
    let groups = parse_shell_blocks(script);
    render_repl_svg(&groups, style, layout, control)
}