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
24impl PlayerColors {
25 pub fn local(&self) -> PlayerColor {
26 // todo!("use a valid color");
27 *self.0.first().unwrap()
28 }
29
30 pub fn absent(&self) -> PlayerColor {
31 // todo!("use a valid color");
32 *self.0.last().unwrap()
33 }
34
35 pub fn color_for_participant(&self, participant_index: u32) -> PlayerColor {
36 let len = self.0.len() - 1;
37 self.0[(participant_index as usize % len) + 1]
38 }
39}
40
41#[derive(Refineable, Clone, Debug)]
42#[refineable(debug)]
43pub struct StatusColors {
44 pub conflict: Hsla,
45 pub created: Hsla,
46 pub deleted: Hsla,
47 pub error: Hsla,
48 pub hidden: Hsla,
49 pub ignored: Hsla,
50 pub info: Hsla,
51 pub modified: Hsla,
52 pub renamed: Hsla,
53 pub success: Hsla,
54 pub warning: Hsla,
55}
56
57#[derive(Refineable, Clone, Debug)]
58#[refineable(debug)]
59pub struct GitStatusColors {
60 pub conflict: Hsla,
61 pub created: Hsla,
62 pub deleted: Hsla,
63 pub ignored: Hsla,
64 pub modified: Hsla,
65 pub renamed: Hsla,
66}
67
68#[derive(Refineable, Clone, Debug)]
69#[refineable(debug, deserialize)]
70pub struct ThemeColors {
71 pub border: Hsla,
72 pub border_variant: Hsla,
73 pub border_focused: Hsla,
74 pub border_selected: Hsla,
75 pub border_transparent: Hsla,
76 pub border_disabled: Hsla,
77 pub elevated_surface_background: Hsla,
78 pub surface_background: Hsla,
79 pub background: Hsla,
80 pub element_background: Hsla,
81 pub element_hover: Hsla,
82 pub element_active: Hsla,
83 pub element_selected: Hsla,
84 pub element_disabled: Hsla,
85 pub element_placeholder: Hsla,
86 pub element_drop_target: Hsla,
87 pub ghost_element_background: Hsla,
88 pub ghost_element_hover: Hsla,
89 pub ghost_element_active: Hsla,
90 pub ghost_element_selected: Hsla,
91 pub ghost_element_disabled: Hsla,
92 pub text: Hsla,
93 pub text_muted: Hsla,
94 pub text_placeholder: Hsla,
95 pub text_disabled: Hsla,
96 pub text_accent: Hsla,
97 pub icon: Hsla,
98 pub icon_muted: Hsla,
99 pub icon_disabled: Hsla,
100 pub icon_placeholder: Hsla,
101 pub icon_accent: Hsla,
102 pub status_bar_background: Hsla,
103 pub title_bar_background: Hsla,
104 pub toolbar_background: Hsla,
105 pub tab_bar_background: Hsla,
106 pub tab_inactive_background: Hsla,
107 pub tab_active_background: Hsla,
108 pub editor_background: Hsla,
109 pub editor_gutter_background: Hsla,
110 pub editor_subheader_background: Hsla,
111 pub editor_active_line_background: Hsla,
112 pub editor_highlighted_line_background: Hsla,
113 pub editor_line_number: Hsla,
114 pub editor_active_line_number: Hsla,
115 pub editor_invisible: Hsla,
116 pub editor_wrap_guide: Hsla,
117 pub editor_active_wrap_guide: Hsla,
118 pub editor_document_highlight_read_background: Hsla,
119 pub editor_document_highlight_write_background: Hsla,
120 pub terminal_background: Hsla,
121 pub terminal_ansi_bright_black: Hsla,
122 pub terminal_ansi_bright_red: Hsla,
123 pub terminal_ansi_bright_green: Hsla,
124 pub terminal_ansi_bright_yellow: Hsla,
125 pub terminal_ansi_bright_blue: Hsla,
126 pub terminal_ansi_bright_magenta: Hsla,
127 pub terminal_ansi_bright_cyan: Hsla,
128 pub terminal_ansi_bright_white: Hsla,
129 pub terminal_ansi_black: Hsla,
130 pub terminal_ansi_red: Hsla,
131 pub terminal_ansi_green: Hsla,
132 pub terminal_ansi_yellow: Hsla,
133 pub terminal_ansi_blue: Hsla,
134 pub terminal_ansi_magenta: Hsla,
135 pub terminal_ansi_cyan: Hsla,
136 pub terminal_ansi_white: Hsla,
137}
138
139#[derive(Refineable, Clone)]
140pub struct ThemeStyles {
141 pub system: SystemColors,
142
143 #[refineable]
144 pub colors: ThemeColors,
145 pub status: StatusColors,
146 pub git: GitStatusColors,
147 pub player: PlayerColors,
148 pub syntax: SyntaxTheme,
149}
150
151#[cfg(test)]
152mod tests {
153 use serde_json::json;
154
155 use super::*;
156
157 #[test]
158 fn override_a_single_theme_color() {
159 let mut colors = ThemeColors::default_light();
160
161 let magenta: Hsla = gpui::rgb(0xff00ff);
162
163 assert_ne!(colors.text, magenta);
164
165 let overrides = ThemeColorsRefinement {
166 text: Some(magenta),
167 ..Default::default()
168 };
169
170 colors.refine(&overrides);
171
172 assert_eq!(colors.text, magenta);
173 }
174
175 #[test]
176 fn override_multiple_theme_colors() {
177 let mut colors = ThemeColors::default_light();
178
179 let magenta: Hsla = gpui::rgb(0xff00ff);
180 let green: Hsla = gpui::rgb(0x00ff00);
181
182 assert_ne!(colors.text, magenta);
183 assert_ne!(colors.background, green);
184
185 let overrides = ThemeColorsRefinement {
186 text: Some(magenta),
187 background: Some(green),
188 ..Default::default()
189 };
190
191 colors.refine(&overrides);
192
193 assert_eq!(colors.text, magenta);
194 assert_eq!(colors.background, green);
195 }
196
197 #[test]
198 fn deserialize_theme_colors_refinement_from_json() {
199 let colors: ThemeColorsRefinement = serde_json::from_value(json!({
200 "background": "#ff00ff",
201 "text": "#ff0000"
202 }))
203 .unwrap();
204
205 assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
206 assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
207 }
208}