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
// Source: /data/home/swei/claudecode/openclaudecode/src/utils/ink.ts
//! Ink color conversion utilities
//!
//! Convert color strings to Ink's TextProps['color'] format.
/// Default agent theme color for subagents
const DEFAULT_AGENT_THEME_COLOR: &str = "cyan_FOR_SUBAGENTS_ONLY";
/// Agent color name to theme color mapping
///
/// Note: This mapping would be populated from the actual agent color manager
const AGENT_COLOR_TO_THEME_COLOR: &[(&str, &str)] = &[
("black", "black"),
("red", "red"),
("green", "green"),
("yellow", "yellow"),
("blue", "blue"),
("magenta", "magenta"),
("cyan", "cyan"),
("white", "white"),
("gray", "gray"),
("grey", "gray"),
];
/// Convert a color string to Ink's TextProps['color'] format.
///
/// Colors are typically AgentColorName values like 'blue', 'green', etc.
/// This converts them to theme keys so they respect the current theme.
/// Falls back to the raw ANSI color if the color is not a known agent color.
///
/// # Arguments
/// * `color` - The color string to convert
///
/// # Returns
/// The Ink-compatible color value
pub fn to_ink_color(color: Option<&str>) -> String {
let color = match color {
Some(c) => c,
None => return DEFAULT_AGENT_THEME_COLOR.to_string(),
};
// Try to map to a theme color if it's a known agent color
for (agent_color, theme_color) in AGENT_COLOR_TO_THEME_COLOR {
if agent_color.eq_ignore_ascii_case(color) {
return theme_color.to_string();
}
}
// Fall back to raw ANSI color for unknown colors
format!("ansi:{}", color)
}