mermaid-cli 0.17.0

Open-source AI pair programmer with agentic capabilities. Local-first with Ollama, native tool calling, and beautiful TUI.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
use ratatui::style::Color;
use serde::{Deserialize, Serialize};

/// Theme configuration for the TUI
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Theme {
    pub name: String,
    pub colors: ThemeColors,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThemeColors {
    // Primary colors
    pub background: ColorValue,
    pub foreground: ColorValue,

    // UI elements
    pub border: ColorValue,
    pub border_focused: ColorValue,
    pub header: ColorValue,
    pub status_bar: ColorValue,

    // Text colors
    pub text_primary: ColorValue,
    pub text_secondary: ColorValue,
    pub text_disabled: ColorValue,
    pub text_highlight: ColorValue,

    // Message colors
    pub user_message: ColorValue,
    pub assistant_message: ColorValue,
    pub system_message: ColorValue,
    /// Full-width background band behind the user's submitted prompt
    /// (Claude-Code style). A clearly-visible neutral gray, a step above the
    /// main background — not a blue tint.
    pub user_message_background: ColorValue,

    // Code highlighting
    pub code_background: ColorValue,
    pub code_foreground: ColorValue,
    pub code_keyword: ColorValue,
    pub code_string: ColorValue,
    pub code_comment: ColorValue,

    // Mode colors
    pub mode_normal: ColorValue,
    pub mode_accept_edits: ColorValue,
    pub mode_plan: ColorValue,
    pub mode_bypass_all: ColorValue,

    // Status colors
    pub success: ColorValue,
    pub warning: ColorValue,
    pub error: ColorValue,
    pub info: ColorValue,

    /// Brand accent (aqua #22D3EE) — the `ask_user_question` modal's header chip
    /// and border. Serde-defaulted so themes/configs predating it still load.
    #[serde(default = "default_brand")]
    pub brand: ColorValue,

    /// Muted meta text (tool headers, byline timestamps) — deliberately a
    /// specific mid-gray rather than the terminal's ANSI gray, which most
    /// palettes render much brighter. Serde-defaulted like `brand`.
    #[serde(default = "default_text_meta")]
    pub text_meta: ColorValue,
    /// Background band behind added diff lines.
    #[serde(default = "default_diff_added_bg")]
    pub diff_added_bg: ColorValue,
    /// Background band behind removed diff lines.
    #[serde(default = "default_diff_removed_bg")]
    pub diff_removed_bg: ColorValue,
    /// Highlight band behind queued (mid-run steering) messages in the
    /// status area.
    #[serde(default = "default_queued_bg")]
    pub queued_bg: ColorValue,
}

/// Mermaid's aqua brand accent, used when a theme omits `brand`.
fn default_brand() -> ColorValue {
    ColorValue::Rgb {
        r: 34,
        g: 211,
        b: 238,
    }
}

/// Dark-theme values double as serde defaults so themes/configs predating
/// these fields keep today's exact colors.
fn default_text_meta() -> ColorValue {
    ColorValue::Rgb {
        r: 136,
        g: 136,
        b: 136,
    }
}

fn default_diff_added_bg() -> ColorValue {
    ColorValue::Rgb {
        r: 20,
        g: 50,
        b: 20,
    }
}

fn default_diff_removed_bg() -> ColorValue {
    ColorValue::Rgb {
        r: 60,
        g: 20,
        b: 20,
    }
}

fn default_queued_bg() -> ColorValue {
    ColorValue::Rgb {
        r: 60,
        g: 60,
        b: 80,
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ColorValue {
    Rgb { r: u8, g: u8, b: u8 },
    Named(String),
}

impl ColorValue {
    pub fn to_color(&self) -> Color {
        match self {
            ColorValue::Rgb { r, g, b } => Color::Rgb(*r, *g, *b),
            ColorValue::Named(name) => match name.as_str() {
                // The terminal's own default fg/bg — what `Theme::plain()`
                // (NO_COLOR) is built from.
                "default" => Color::Reset,
                "black" => Color::Black,
                "red" => Color::Red,
                "green" => Color::Green,
                "yellow" => Color::Yellow,
                "blue" => Color::Blue,
                "magenta" => Color::Magenta,
                "cyan" => Color::Cyan,
                "white" => Color::White,
                "gray" | "grey" => Color::Gray,
                "dark_gray" | "dark_grey" => Color::DarkGray,
                _ => Color::White,
            },
        }
    }
}

impl Theme {
    /// Create a light theme. Selected by `ui.theme = "light"` in config.toml
    /// or `/theme light` (see `render()`'s theme memo).
    pub fn light() -> Self {
        Self {
            name: "Light".to_string(),
            colors: ThemeColors {
                background: ColorValue::Rgb {
                    r: 250,
                    g: 250,
                    b: 250,
                },
                foreground: ColorValue::Rgb {
                    r: 30,
                    g: 30,
                    b: 30,
                },

                border: ColorValue::Named("gray".to_string()),
                border_focused: ColorValue::Named("blue".to_string()),
                header: ColorValue::Named("blue".to_string()),
                status_bar: ColorValue::Named("white".to_string()),

                text_primary: ColorValue::Named("black".to_string()),
                text_secondary: ColorValue::Named("dark_gray".to_string()),
                text_disabled: ColorValue::Named("gray".to_string()),
                text_highlight: ColorValue::Named("magenta".to_string()),

                user_message: ColorValue::Named("blue".to_string()),
                assistant_message: ColorValue::Named("green".to_string()),
                system_message: ColorValue::Named("yellow".to_string()),
                user_message_background: ColorValue::Rgb {
                    r: 230,
                    g: 230,
                    b: 230,
                },

                code_background: ColorValue::Rgb {
                    r: 240,
                    g: 240,
                    b: 240,
                },
                code_foreground: ColorValue::Named("dark_gray".to_string()),
                code_keyword: ColorValue::Named("magenta".to_string()),
                code_string: ColorValue::Named("green".to_string()),
                code_comment: ColorValue::Named("gray".to_string()),

                mode_normal: ColorValue::Named("green".to_string()),
                mode_accept_edits: ColorValue::Named("yellow".to_string()),
                mode_plan: ColorValue::Named("blue".to_string()),
                mode_bypass_all: ColorValue::Named("red".to_string()),

                success: ColorValue::Named("green".to_string()),
                warning: ColorValue::Named("yellow".to_string()),
                error: ColorValue::Named("red".to_string()),
                info: ColorValue::Named("blue".to_string()),

                brand: default_brand(),
                text_meta: ColorValue::Rgb {
                    r: 110,
                    g: 110,
                    b: 110,
                },
                diff_added_bg: ColorValue::Rgb {
                    r: 220,
                    g: 245,
                    b: 220,
                },
                diff_removed_bg: ColorValue::Rgb {
                    r: 250,
                    g: 225,
                    b: 225,
                },
                queued_bg: ColorValue::Rgb {
                    r: 225,
                    g: 225,
                    b: 240,
                },
            },
        }
    }

    /// Create the default dark theme
    pub fn dark() -> Self {
        Self {
            name: "Dark".to_string(),
            colors: ThemeColors {
                background: ColorValue::Rgb {
                    r: 20,
                    g: 20,
                    b: 20,
                },
                foreground: ColorValue::Rgb {
                    r: 230,
                    g: 230,
                    b: 230,
                },

                border: ColorValue::Named("dark_gray".to_string()),
                border_focused: ColorValue::Named("cyan".to_string()),
                header: ColorValue::Named("cyan".to_string()),
                status_bar: ColorValue::Named("black".to_string()),

                text_primary: ColorValue::Named("white".to_string()),
                text_secondary: ColorValue::Named("gray".to_string()),
                text_disabled: ColorValue::Named("dark_gray".to_string()),
                text_highlight: ColorValue::Named("yellow".to_string()),

                user_message: ColorValue::Named("blue".to_string()),
                assistant_message: ColorValue::Named("green".to_string()),
                system_message: ColorValue::Named("yellow".to_string()),
                user_message_background: ColorValue::Rgb {
                    r: 54,
                    g: 54,
                    b: 54,
                },

                code_background: ColorValue::Rgb {
                    r: 40,
                    g: 40,
                    b: 40,
                },
                code_foreground: ColorValue::Named("gray".to_string()),
                code_keyword: ColorValue::Named("magenta".to_string()),
                code_string: ColorValue::Named("green".to_string()),
                code_comment: ColorValue::Named("dark_gray".to_string()),

                mode_normal: ColorValue::Named("green".to_string()),
                mode_accept_edits: ColorValue::Named("yellow".to_string()),
                mode_plan: ColorValue::Named("blue".to_string()),
                mode_bypass_all: ColorValue::Named("red".to_string()),

                success: ColorValue::Named("green".to_string()),
                warning: ColorValue::Named("yellow".to_string()),
                error: ColorValue::Named("red".to_string()),
                info: ColorValue::Named("cyan".to_string()),

                brand: default_brand(),
                text_meta: default_text_meta(),
                diff_added_bg: default_diff_added_bg(),
                diff_removed_bg: default_diff_removed_bg(),
                queued_bg: default_queued_bg(),
            },
        }
    }

    /// Colorless theme for `NO_COLOR`: every slot is the terminal's own
    /// default fg/bg (`Color::Reset`), so nothing emits a color at all.
    /// Structure (glyphs, layout, bold/dim) is untouched — diffs still read
    /// via their `+`/`-` prefixes.
    pub fn plain() -> Self {
        fn d() -> ColorValue {
            ColorValue::Named("default".to_string())
        }
        Self {
            name: "Plain".to_string(),
            colors: ThemeColors {
                background: d(),
                foreground: d(),
                border: d(),
                border_focused: d(),
                header: d(),
                status_bar: d(),
                text_primary: d(),
                text_secondary: d(),
                text_disabled: d(),
                text_highlight: d(),
                user_message: d(),
                assistant_message: d(),
                system_message: d(),
                user_message_background: d(),
                code_background: d(),
                code_foreground: d(),
                code_keyword: d(),
                code_string: d(),
                code_comment: d(),
                mode_normal: d(),
                mode_accept_edits: d(),
                mode_plan: d(),
                mode_bypass_all: d(),
                success: d(),
                warning: d(),
                error: d(),
                info: d(),
                brand: d(),
                text_meta: d(),
                diff_added_bg: d(),
                diff_removed_bg: d(),
                queued_bg: d(),
            },
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn named_default_maps_to_reset() {
        assert_eq!(
            ColorValue::Named("default".to_string()).to_color(),
            Color::Reset
        );
    }

    #[test]
    fn plain_theme_is_entirely_reset() {
        // Every slot must resolve to the terminal's own default — a single
        // colored slot would defeat NO_COLOR. Serializing the palette and
        // scanning for any non-"default" value covers all fields without
        // enumerating them (new fields are covered automatically).
        let theme = Theme::plain();
        let json = serde_json::to_value(&theme.colors).unwrap();
        let obj = json.as_object().unwrap();
        assert!(!obj.is_empty());
        for (field, value) in obj {
            assert_eq!(
                value.as_str(),
                Some("default"),
                "plain theme leaks color through `{field}`: {value}"
            );
        }
    }

    #[test]
    fn dark_and_light_populate_the_new_slots() {
        for theme in [Theme::dark(), Theme::light()] {
            assert_ne!(theme.colors.diff_added_bg.to_color(), Color::Reset);
            assert_ne!(theme.colors.diff_removed_bg.to_color(), Color::Reset);
            assert_ne!(theme.colors.queued_bg.to_color(), Color::Reset);
            assert_ne!(theme.colors.text_meta.to_color(), Color::Reset);
        }
    }

    #[test]
    fn theme_colors_deserialize_defaults_new_fields() {
        // A theme serialized before the new slots existed still loads, with
        // the dark values as defaults.
        let dark = Theme::dark();
        let mut json = serde_json::to_value(&dark.colors).unwrap();
        let obj = json.as_object_mut().unwrap();
        for field in ["text_meta", "diff_added_bg", "diff_removed_bg", "queued_bg"] {
            obj.remove(field);
        }
        let colors: ThemeColors = serde_json::from_value(json).unwrap();
        assert_eq!(
            colors.text_meta.to_color(),
            dark.colors.text_meta.to_color()
        );
        assert_eq!(
            colors.diff_added_bg.to_color(),
            dark.colors.diff_added_bg.to_color()
        );
    }
}