termcinema_engine/core/
style.rs

1use crate::constants::*;
2
3/// Visual style configuration for font and color settings.
4///
5/// Defines the appearance of rendered content, including font size,
6/// font family, and optional text/background colors. Used across themes,
7/// CLI overrides, and fallback rendering.
8#[derive(Clone)]
9pub struct StyleSpec {
10    /// Font size in **pixels**.
11    pub font_size: u32,
12
13    /// CSS font-family name (e.g. `"JetBrains Mono"`).
14    /// Can refer to an embedded font or system fallback.
15    pub font_family: String,
16
17    /// Text color in hexadecimal (e.g. `"#00FF00"`), or `None` for transparent.
18    pub text_color: Option<String>,
19
20    /// Background color in hexadecimal (e.g. `"#000000"`), or `None` for transparent.
21    pub background_color: Option<String>,
22}
23
24/// Default style configuration using built-in constants.
25///
26/// This is used when no explicit style is provided by the user or theme.
27impl Default for StyleSpec {
28    fn default() -> Self {
29        StyleSpec {
30            font_size: DEFAULT_STYLE_FONT_SIZE,
31            font_family: DEFAULT_STYLE_FONT_FAMILY.into(),
32            text_color: Some(DEFAULT_STYLE_TEXT_COLOR.into()),
33            background_color: Some(DEFAULT_STYLE_BACKGROUND_COLOR.into()),
34        }
35    }
36}
37
38/// Extracts raw style values for rendering engines.
39///
40/// Returns a tuple of resolved visual parameters:
41/// `(font_size, font_family, text_color, background_color)`
42///
43/// - If any color is `None`, falls back to default constants;
44/// - Used by SVG renderers and preview tools for layout calculation.
45pub(crate) fn extract_style_primitives(style: &StyleSpec) -> (u32, &str, &str, &str) {
46    (
47        style.font_size,
48        &style.font_family,
49        style
50            .text_color
51            .as_deref()
52            .unwrap_or(DEFAULT_STYLE_TEXT_COLOR),
53        style
54            .background_color
55            .as_deref()
56            .unwrap_or(DEFAULT_STYLE_BACKGROUND_COLOR),
57    )
58}