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
//! Theme-aware color accessors and small color helpers.
//!
//! Extracted from `ui/mod.rs` to keep the giant module focused on the
//! event loop. The function spellings (`c_agent()`, `c_error()`, …)
//! are preserved so call sites read identically to before.
use crossterm::style::Color;
use crate::ui::theme;
// Themed color accessors. These wrap `theme::agent()` etc. so we can
// keep the existing call-site spelling (e.g. `c_agent()` is now a fn).
// Active palette is set at startup via `theme::init`.
#[inline]
pub(crate) fn c_agent() -> Color {
theme::agent()
}
#[inline]
pub(crate) fn c_error() -> Color {
theme::error()
}
#[inline]
pub(crate) fn c_tool() -> Color {
theme::tool()
}
#[inline]
pub(crate) fn c_perm() -> Color {
theme::perm()
}
/// Map a plugin-supplied color string ("cyan", "red", ...) to a
/// crossterm `Color`. Falls back to dim grey for anything unrecognized
/// so a typo in plugin code doesn't crash the UI.
#[cfg(feature = "plugin")]
pub(crate) fn parse_plugin_color(name: &str) -> Color {
// Lowercase + strip a leading `:` so `:cyan`, `cyan`, `Cyan` all
// map to the same crossterm color.
let normalized = name.trim_start_matches(':').to_ascii_lowercase();
match normalized.as_str() {
"black" => Color::Black,
"red" => Color::Red,
"green" => Color::Green,
"yellow" => Color::Yellow,
"blue" => Color::Blue,
"magenta" => Color::Magenta,
"cyan" => Color::Cyan,
"white" => Color::White,
"darkgrey" | "darkgray" | "grey" | "gray" => Color::DarkGrey,
"darkred" => Color::DarkRed,
"darkgreen" => Color::DarkGreen,
"darkyellow" => Color::DarkYellow,
"darkblue" => Color::DarkBlue,
"darkmagenta" => Color::DarkMagenta,
"darkcyan" => Color::DarkCyan,
_ => Color::DarkGrey,
}
}