termcinema_cli/
args.rs

1//! Command-line argument definitions for the `termcinema` binary.
2//!
3//! This module defines the [`CliArgs`] struct, which covers all
4//! rendering configuration options exposed via CLI:
5//!
6//! - Input source: `--input`, `--script`, or stdin
7//! - Style and theme overrides
8//! - Layout and spacing options
9//! - Animation controls
10//! - Output destination
11//!
12//! Argument parsing is powered by [`clap`].
13
14use clap::Parser;
15use std::path::PathBuf;
16
17/// Defines all command-line options for the `termcinema` binary.
18#[derive(Parser, Debug)]
19#[command(
20    name = "termcinema",
21    author,
22    version,
23    about = "🎬 Turn terminal into cinematic SVG",
24    help_template = "\
25{name} {version}
26{about}
27
28📥 Input:
29    -i, --input <INPUT>                 Input raw text directly
30    -s, --script <FILE>                 Load from a script file
31        (stdin)                         echo \"The quick brown fox\" | termcinema
32
33
34💾 Output:
35    -o, --output <FILE>                 Write SVG to file (default: stdout)
36
37
38🎨 Style:
39    --theme <THEME>                     Theme name (e.g. \"dos_classic\", see --list-themes for all)
40
41    --font-family <FONT>                Font family name (e.g. \"Monospace\", see --list-fonts for all)
42    --font-size <PX>                    Font size in pixels
43
44    --text-color <HEX>                  Text color (e.g. \"#00FF00\")
45    --background-color <HEX>            Background color (e.g. \"#000000\")
46
47    --cursor-char <CHAR>                Custom cursor character (e.g. \"_\")
48
49
50📐 Layout:
51    --width <PX>                        SVG width in pixels
52    --height <PX>                       SVG height in pixels
53
54    --padding <PX>                      Margin (default 10px)
55    --line-spacing <PX>                 Line spacing in pixels
56
57    --align <left|center|right>         Horizontal alignment
58    --v-align <top|middle|bottom>       Vertical alignment
59
60
61🎞️ Animation:
62    --speed <slow|normal|fast|extreme>  Typing speed preset (e.g. \"normal\")
63    --frame-delay <MS>                  Frame delay per character (ms, lower = faster)
64
65    --fade-duration <MS>                Fade-in duration per char (e.g. 100)
66
67
68⚙️ Advanced:
69    --no-escape                         Disable escape sequences
70
71    --list-fonts                        List all built-in fonts
72    --list-themes                       List all built-in themes
73
74
75❓ Help:
76    -h, --help                          Print help
77    -V, --version                       Print version
78"
79)]
80pub struct CliArgs {
81    // 📥 Input
82    /// Input text (conflicts with --script)
83    #[arg(short = 'i', long, value_name = "TEXT", conflicts_with = "script")]
84    pub input: Option<String>,
85
86    /// Script file path (conflicts with --input)
87    #[arg(short = 's', long, value_name = "FILE", conflicts_with = "input")]
88    pub script: Option<PathBuf>,
89
90    // stdin is supported implicitly (no field needed)
91
92    // 💾 Output
93    /// Output file path (default: stdout)
94    #[arg(short = 'o', long, value_name = "FILE")]
95    pub output: Option<String>,
96
97    // 🎨 Style
98    /// Theme name (see --list-themes)
99    #[arg(long, value_name = "NAME")]
100    pub theme: Option<String>,
101
102    /// Font family name
103    #[arg(long, value_name = "FONT")]
104    pub font_family: Option<String>,
105
106    /// Font size in pixels
107    #[arg(long, value_name = "PX")]
108    pub font_size: Option<u32>,
109
110    /// Text color (e.g. "#00FF00")
111    #[arg(long, value_name = "HEX")]
112    pub text_color: Option<String>,
113
114    /// Background color (e.g. "#000000")
115    #[arg(long, value_name = "HEX")]
116    pub background_color: Option<String>,
117
118    /// Cursor character (e.g. "_")
119    #[arg(long, value_name = "CHAR")]
120    pub cursor_char: Option<String>,
121
122    // 📐 Layout
123    /// Padding around content (default: 10)
124    #[arg(long, value_name = "PX")]
125    pub width: Option<u32>,
126
127    /// Line spacing in pixels
128    #[arg(long, value_name = "PX")]
129    pub height: Option<u32>,
130
131    /// SVG height in pixels
132    #[arg(long, value_name = "PX")]
133    pub padding: Option<u32>,
134
135    /// SVG width in pixels
136    #[arg(long, value_name = "PX")]
137    pub line_spacing: Option<u32>,
138
139    /// Horizontal alignment: left, center, or right
140    #[arg(long, value_name = "ENUM")]
141    pub align: Option<String>,
142
143    /// Vertical alignment: top, middle, or bottom
144    #[arg(long, value_name = "ENUM")]
145    pub v_align: Option<String>,
146
147    // 🎞️ Animation
148    /// Typing speed preset (e.g. "normal")
149    #[arg(long, value_name = "ENUM", conflicts_with = "frame_delay")]
150    pub speed: Option<String>,
151
152    /// Frame delay per character (ms)
153    #[arg(long, value_name = "MS", conflicts_with = "speed")]
154    pub frame_delay: Option<u32>,
155
156    /// Fade-in duration per character (ms)
157    #[arg(long, value_name = "MS")]
158    pub fade_duration: Option<u32>,
159
160    // ⚙️ Advanced
161    /// Disable escape sequences like \n or \t
162    #[arg(long, default_value_t = false)]
163    pub no_escape: bool,
164
165    /// List all built-in fonts
166    #[arg(long, default_value_t = false)]
167    pub list_fonts: bool,
168
169    /// List all built-in themes
170    #[arg(long, default_value_t = false)]
171    pub list_themes: bool,
172}
173
174/// Parse command-line arguments using `clap`.
175///
176/// Called once by `main()` as the entrypoint to argument collection.
177#[allow(dead_code)]
178pub(crate) fn parse_args() -> CliArgs {
179    CliArgs::parse()
180}
181
182/// Return default arguments for internal use or SDK initialization.
183///
184/// Equivalent to `CliArgs::default()`.
185#[allow(dead_code)]
186pub fn default_args() -> CliArgs {
187    CliArgs::default()
188}
189
190/// Provide default arguments for SDKs, playgrounds, or programmatic usage.
191///
192/// These defaults are suitable for embedding scenarios where no CLI is involved.
193/// They represent a typical middle-ground layout and animation config.
194///
195/// This implementation is used by [`default_args()`] and [`render_svg_direct()`].
196impl Default for CliArgs {
197    fn default() -> Self {
198        Self {
199            input: None,
200            script: None,
201            output: None,
202
203            theme: None,
204            font_family: None,
205            font_size: Some(16),
206            text_color: None,
207            background_color: None,
208            cursor_char: None,
209
210            width: Some(800),
211            height: Some(600),
212            padding: Some(10),
213            line_spacing: Some(6),
214            align: Some("left".into()),
215            v_align: Some("middle".into()),
216
217            speed: Some("normal".into()),
218            frame_delay: None,
219            fade_duration: Some(100),
220
221            no_escape: false,
222            list_fonts: false,
223            list_themes: false,
224        }
225    }
226}