asg/
lib.rs

1pub mod asciicast;
2pub mod input;
3pub mod renderer;
4pub mod terminal;
5pub mod theme;
6
7use std::str::FromStr;
8
9use anyhow::Result;
10use clap::ValueEnum;
11
12#[derive(Debug, Clone, ValueEnum)]
13pub enum Theme {
14    #[clap(name = "asciinema")]
15    Asciinema,
16    #[clap(name = "dracula")]
17    Dracula,
18    #[clap(name = "github-dark")]
19    GithubDark,
20    #[clap(name = "github-light")]
21    GithubLight,
22    #[clap(name = "monokai")]
23    Monokai,
24    #[clap(name = "solarized-dark")]
25    SolarizedDark,
26    #[clap(name = "solarized-light")]
27    SolarizedLight,
28
29    #[clap(skip)]
30    Custom(String),
31}
32
33impl TryFrom<Theme> for theme::Theme {
34    type Error = anyhow::Error;
35
36    fn try_from(theme: Theme) -> Result<Self, Self::Error> {
37        use Theme::*;
38
39        match theme {
40            Asciinema => theme::Theme::from_str(
41                "121314,cccccc,000000,dd3c69,4ebf22,ddaf3c,26b0d7,b954e1,54e1b9,d9d9d9,4d4d4d,dd3c69,4ebf22,ddaf3c,26b0d7,b954e1,54e1b9,ffffff",
42            ),
43            Dracula => theme::Theme::from_str(
44                "282a36,f8f8f2,21222c,ff5555,50fa7b,f1fa8c,bd93f9,ff79c6,8be9fd,f8f8f2,6272a4,ff6e6e,69ff94,ffffa5,d6acff,ff92df,a4ffff,ffffff",
45            ),
46            GithubDark => theme::Theme::from_str(
47                "171b21,eceff4,0e1116,f97583,a2fca2,fabb72,7db4f9,c4a0f5,1f6feb,eceff4,6a737d,bf5a64,7abf7a,bf8f57,608bbf,997dbf,195cbf,b9bbbf",
48            ),
49            GithubLight => theme::Theme::from_str(
50                "f6f8fa,24292f,ffffff,cf222e,1a7f37,9a6700,0969da,8250df,1f6feb,24292f,57606a,a40e26,2da44e,bf8700,1f6feb,a475f9,1f6feb,8c959f",
51            ),
52            Monokai => theme::Theme::from_str(
53                "272822,f8f8f2,272822,f92672,a6e22e,f4bf75,66d9ef,ae81ff,a1efe4,f8f8f2,75715e,f92672,a6e22e,f4bf75,66d9ef,ae81ff,a1efe4,f9f8f5",
54            ),
55            SolarizedDark => theme::Theme::from_str(
56                "002b36,839496,073642,dc322f,859900,b58900,268bd2,6c71c4,2aa198,93a1a1,586e75,dc322f,859900,b58900,268bd2,6c71c4,2aa198,fdf6e3",
57            ),
58            SolarizedLight => theme::Theme::from_str(
59                "fdf6e3,657b83,eee8d5,dc322f,859900,b58900,268bd2,6c71c4,2aa198,586e75,93a1a1,dc322f,859900,b58900,268bd2,6c71c4,2aa198,002b36",
60            ),
61            Custom(colors) => theme::Theme::from_str(&colors),
62        }
63    }
64}
65
66#[derive(Debug, Clone, Copy, ValueEnum)]
67pub enum Timeline {
68    /// Use original timing from cast (variable per-frame durations)
69    Original,
70    /// Resample to a fixed FPS (uniform per-frame durations)
71    Fixed,
72}
73
74pub struct Config {
75    pub theme: Option<Theme>,
76    pub speed: f64,
77    pub fps: u8,
78    pub font_size: u8,
79    pub font_family: String,
80    pub line_height: f32,
81    pub cols: Option<u16>,
82    pub rows: Option<u16>,
83    pub idle_time_limit: Option<f64>,
84    pub loop_enable: bool,
85    pub at: Option<f64>,
86    pub from: Option<f64>,
87    pub to: Option<f64>,
88    pub no_cursor: bool,
89    pub window: bool,
90    pub padding: u16,
91    pub padding_x: Option<u16>,
92    pub padding_y: Option<u16>,
93    pub timeline: Timeline,
94}
95
96impl Config {
97    pub fn effective_padding_x(&self) -> u16 {
98        self.padding_x.unwrap_or(self.padding)
99    }
100
101    pub fn effective_padding_y(&self) -> u16 {
102        self.padding_y.unwrap_or(self.padding)
103    }
104}