1use gpui::Hsla;
2use refineable::Refineable;
3
4use crate::SyntaxTheme;
5
6#[derive(Clone)]
7pub struct SystemColors {
8 pub transparent: Hsla,
9 pub mac_os_traffic_light_red: Hsla,
10 pub mac_os_traffic_light_yellow: Hsla,
11 pub mac_os_traffic_light_green: Hsla,
12}
13
14#[derive(Debug, Clone, Copy)]
15pub struct PlayerColor {
16 pub cursor: Hsla,
17 pub background: Hsla,
18 pub selection: Hsla,
19}
20
21#[derive(Clone)]
22pub struct PlayerColors(pub Vec<PlayerColor>);
23
24#[derive(Refineable, Clone, Debug)]
25#[refineable(debug)]
26pub struct StatusColors {
27 pub conflict: Hsla,
28 pub created: Hsla,
29 pub deleted: Hsla,
30 pub error: Hsla,
31 pub hidden: Hsla,
32 pub ignored: Hsla,
33 pub info: Hsla,
34 pub modified: Hsla,
35 pub renamed: Hsla,
36 pub success: Hsla,
37 pub warning: Hsla,
38}
39
40#[derive(Refineable, Clone, Debug)]
41#[refineable(debug)]
42pub struct GitStatusColors {
43 pub conflict: Hsla,
44 pub created: Hsla,
45 pub deleted: Hsla,
46 pub ignored: Hsla,
47 pub modified: Hsla,
48 pub renamed: Hsla,
49}
50
51#[derive(Refineable, Clone, Debug)]
52#[refineable(debug, deserialize)]
53pub struct ThemeColors {
54 pub border: Hsla,
55 pub border_variant: Hsla,
56 pub border_focused: Hsla,
57 pub border_selected: Hsla,
58 pub border_transparent: Hsla,
59 pub border_disabled: Hsla,
60 pub elevated_surface_background: Hsla,
61 pub surface_background: Hsla,
62 pub background: Hsla,
63 pub element_background: Hsla,
64 pub element_hover: Hsla,
65 pub element_active: Hsla,
66 pub element_selected: Hsla,
67 pub element_disabled: Hsla,
68 pub element_placeholder: Hsla,
69 pub element_drop_target: Hsla,
70 pub ghost_element_background: Hsla,
71 pub ghost_element_hover: Hsla,
72 pub ghost_element_active: Hsla,
73 pub ghost_element_selected: Hsla,
74 pub ghost_element_disabled: Hsla,
75 pub text: Hsla,
76 pub text_muted: Hsla,
77 pub text_placeholder: Hsla,
78 pub text_disabled: Hsla,
79 pub text_accent: Hsla,
80 pub icon: Hsla,
81 pub icon_muted: Hsla,
82 pub icon_disabled: Hsla,
83 pub icon_placeholder: Hsla,
84 pub icon_accent: Hsla,
85 pub status_bar_background: Hsla,
86 pub title_bar_background: Hsla,
87 pub toolbar_background: Hsla,
88 pub tab_bar_background: Hsla,
89 pub tab_inactive_background: Hsla,
90 pub tab_active_background: Hsla,
91 pub editor_background: Hsla,
92 pub editor_subheader_background: Hsla,
93 pub editor_active_line: Hsla,
94 pub terminal_background: Hsla,
95 pub terminal_ansi_bright_black: Hsla,
96 pub terminal_ansi_bright_red: Hsla,
97 pub terminal_ansi_bright_green: Hsla,
98 pub terminal_ansi_bright_yellow: Hsla,
99 pub terminal_ansi_bright_blue: Hsla,
100 pub terminal_ansi_bright_magenta: Hsla,
101 pub terminal_ansi_bright_cyan: Hsla,
102 pub terminal_ansi_bright_white: Hsla,
103 pub terminal_ansi_black: Hsla,
104 pub terminal_ansi_red: Hsla,
105 pub terminal_ansi_green: Hsla,
106 pub terminal_ansi_yellow: Hsla,
107 pub terminal_ansi_blue: Hsla,
108 pub terminal_ansi_magenta: Hsla,
109 pub terminal_ansi_cyan: Hsla,
110 pub terminal_ansi_white: Hsla,
111}
112
113#[derive(Refineable, Clone)]
114pub struct ThemeStyles {
115 pub system: SystemColors,
116
117 #[refineable]
118 pub colors: ThemeColors,
119 pub status: StatusColors,
120 pub git: GitStatusColors,
121 pub player: PlayerColors,
122 pub syntax: SyntaxTheme,
123}
124
125#[cfg(test)]
126mod tests {
127 use serde_json::json;
128
129 use super::*;
130
131 #[test]
132 fn override_a_single_theme_color() {
133 let mut colors = ThemeColors::default_light();
134
135 let magenta: Hsla = gpui::rgb(0xff00ff);
136
137 assert_ne!(colors.text, magenta);
138
139 let overrides = ThemeColorsRefinement {
140 text: Some(magenta),
141 ..Default::default()
142 };
143
144 colors.refine(&overrides);
145
146 assert_eq!(colors.text, magenta);
147 }
148
149 #[test]
150 fn override_multiple_theme_colors() {
151 let mut colors = ThemeColors::default_light();
152
153 let magenta: Hsla = gpui::rgb(0xff00ff);
154 let green: Hsla = gpui::rgb(0x00ff00);
155
156 assert_ne!(colors.text, magenta);
157 assert_ne!(colors.background, green);
158
159 let overrides = ThemeColorsRefinement {
160 text: Some(magenta),
161 background: Some(green),
162 ..Default::default()
163 };
164
165 colors.refine(&overrides);
166
167 assert_eq!(colors.text, magenta);
168 assert_eq!(colors.background, green);
169 }
170
171 #[test]
172 fn deserialize_theme_colors_refinement_from_json() {
173 let colors: ThemeColorsRefinement = serde_json::from_value(json!({
174 "background": "#ff00ff",
175 "text": "#ff0000"
176 }))
177 .unwrap();
178
179 assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
180 assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
181 }
182}