1mod resolution;
2mod theme_registry;
3
4use gpui::{
5 color::Color,
6 elements::{ContainerStyle, ImageStyle, LabelStyle},
7 fonts::{HighlightStyle, TextStyle},
8 Border,
9};
10use serde::Deserialize;
11use std::{collections::HashMap, sync::Arc};
12
13pub use theme_registry::*;
14
15pub const DEFAULT_THEME_NAME: &'static str = "black";
16
17#[derive(Deserialize, Default)]
18pub struct Theme {
19 #[serde(default)]
20 pub name: String,
21 pub workspace: Workspace,
22 pub chat_panel: ChatPanel,
23 pub people_panel: PeoplePanel,
24 pub project_panel: ProjectPanel,
25 pub selector: Selector,
26 pub editor: EditorStyle,
27}
28
29#[derive(Deserialize, Default)]
30pub struct Workspace {
31 pub background: Color,
32 pub titlebar: Titlebar,
33 pub tab: Tab,
34 pub active_tab: Tab,
35 pub pane_divider: Border,
36 pub left_sidebar: Sidebar,
37 pub right_sidebar: Sidebar,
38 pub status_bar: StatusBar,
39}
40
41#[derive(Clone, Deserialize, Default)]
42pub struct Titlebar {
43 #[serde(flatten)]
44 pub container: ContainerStyle,
45 pub title: TextStyle,
46 pub avatar_width: f32,
47 pub offline_icon: OfflineIcon,
48 pub icon_color: Color,
49 pub avatar: ImageStyle,
50 pub outdated_warning: ContainedText,
51}
52
53#[derive(Clone, Deserialize, Default)]
54pub struct OfflineIcon {
55 #[serde(flatten)]
56 pub container: ContainerStyle,
57 pub width: f32,
58}
59
60#[derive(Clone, Deserialize, Default)]
61pub struct Tab {
62 pub height: f32,
63 #[serde(flatten)]
64 pub container: ContainerStyle,
65 #[serde(flatten)]
66 pub label: LabelStyle,
67 pub spacing: f32,
68 pub icon_width: f32,
69 pub icon_close: Color,
70 pub icon_close_active: Color,
71 pub icon_dirty: Color,
72 pub icon_conflict: Color,
73}
74
75#[derive(Deserialize, Default)]
76pub struct Sidebar {
77 #[serde(flatten)]
78 pub container: ContainerStyle,
79 pub width: f32,
80 pub item: SidebarItem,
81 pub active_item: SidebarItem,
82 pub resize_handle: ContainerStyle,
83}
84
85#[derive(Deserialize, Default)]
86pub struct SidebarItem {
87 pub icon_color: Color,
88 pub icon_size: f32,
89 pub height: f32,
90}
91
92#[derive(Deserialize, Default)]
93pub struct StatusBar {
94 #[serde(flatten)]
95 pub container: ContainerStyle,
96 pub height: f32,
97 pub cursor_position: TextStyle,
98 pub diagnostic_icon_size: f32,
99 pub diagnostic_icon_spacing: f32,
100 pub diagnostic_icon_color: Color,
101 pub diagnostic_message: TextStyle,
102}
103
104#[derive(Deserialize, Default)]
105pub struct ChatPanel {
106 #[serde(flatten)]
107 pub container: ContainerStyle,
108 pub message: ChatMessage,
109 pub pending_message: ChatMessage,
110 pub channel_select: ChannelSelect,
111 pub input_editor: InputEditorStyle,
112 pub sign_in_prompt: TextStyle,
113 pub hovered_sign_in_prompt: TextStyle,
114}
115
116#[derive(Debug, Deserialize, Default)]
117pub struct ProjectPanel {
118 #[serde(flatten)]
119 pub container: ContainerStyle,
120 pub entry: ProjectPanelEntry,
121 pub hovered_entry: ProjectPanelEntry,
122 pub selected_entry: ProjectPanelEntry,
123 pub hovered_selected_entry: ProjectPanelEntry,
124}
125
126#[derive(Debug, Deserialize, Default)]
127pub struct ProjectPanelEntry {
128 pub height: f32,
129 #[serde(flatten)]
130 pub container: ContainerStyle,
131 pub text: TextStyle,
132 pub icon_color: Color,
133 pub icon_size: f32,
134 pub icon_spacing: f32,
135}
136
137#[derive(Deserialize, Default)]
138pub struct PeoplePanel {
139 #[serde(flatten)]
140 pub container: ContainerStyle,
141 pub host_row_height: f32,
142 pub host_avatar: ImageStyle,
143 pub host_username: ContainedText,
144 pub tree_branch_width: f32,
145 pub tree_branch_color: Color,
146 pub shared_worktree: WorktreeRow,
147 pub hovered_shared_worktree: WorktreeRow,
148 pub unshared_worktree: WorktreeRow,
149 pub hovered_unshared_worktree: WorktreeRow,
150}
151
152#[derive(Deserialize, Default)]
153pub struct WorktreeRow {
154 #[serde(flatten)]
155 pub container: ContainerStyle,
156 pub height: f32,
157 pub name: ContainedText,
158 pub guest_avatar: ImageStyle,
159 pub guest_avatar_spacing: f32,
160}
161
162#[derive(Deserialize, Default)]
163pub struct ChatMessage {
164 #[serde(flatten)]
165 pub container: ContainerStyle,
166 pub body: TextStyle,
167 pub sender: ContainedText,
168 pub timestamp: ContainedText,
169}
170
171#[derive(Deserialize, Default)]
172pub struct ChannelSelect {
173 #[serde(flatten)]
174 pub container: ContainerStyle,
175 pub header: ChannelName,
176 pub item: ChannelName,
177 pub active_item: ChannelName,
178 pub hovered_item: ChannelName,
179 pub hovered_active_item: ChannelName,
180 pub menu: ContainerStyle,
181}
182
183#[derive(Deserialize, Default)]
184pub struct ChannelName {
185 #[serde(flatten)]
186 pub container: ContainerStyle,
187 pub hash: ContainedText,
188 pub name: TextStyle,
189}
190
191#[derive(Deserialize, Default)]
192pub struct Selector {
193 #[serde(flatten)]
194 pub container: ContainerStyle,
195 pub empty: ContainedLabel,
196 pub input_editor: InputEditorStyle,
197 pub item: ContainedLabel,
198 pub active_item: ContainedLabel,
199}
200
201#[derive(Clone, Debug, Deserialize, Default)]
202pub struct ContainedText {
203 #[serde(flatten)]
204 pub container: ContainerStyle,
205 #[serde(flatten)]
206 pub text: TextStyle,
207}
208
209#[derive(Deserialize, Default)]
210pub struct ContainedLabel {
211 #[serde(flatten)]
212 pub container: ContainerStyle,
213 #[serde(flatten)]
214 pub label: LabelStyle,
215}
216
217#[derive(Clone, Deserialize, Default)]
218pub struct EditorStyle {
219 pub text: TextStyle,
220 #[serde(default)]
221 pub placeholder_text: Option<TextStyle>,
222 pub background: Color,
223 pub selection: SelectionStyle,
224 pub gutter_background: Color,
225 pub active_line_background: Color,
226 pub line_number: Color,
227 pub line_number_active: Color,
228 pub guest_selections: Vec<SelectionStyle>,
229 pub syntax: Arc<SyntaxTheme>,
230 pub diagnostic_error: DiagnosticStyle,
231 pub diagnostic_warning: DiagnosticStyle,
232 #[serde(default)]
233 pub diagnostic_information: DiagnosticStyle,
234 #[serde(default)]
235 pub diagnostic_hint: DiagnosticStyle,
236}
237
238#[derive(Copy, Clone, Deserialize, Default)]
239pub struct DiagnosticStyle {
240 pub text: Color,
241 #[serde(flatten)]
242 pub block: BlockStyle,
243}
244
245#[derive(Clone, Copy, Default, Deserialize)]
246pub struct SelectionStyle {
247 pub cursor: Color,
248 pub selection: Color,
249}
250
251#[derive(Clone, Deserialize, Default)]
252pub struct InputEditorStyle {
253 #[serde(flatten)]
254 pub container: ContainerStyle,
255 pub text: TextStyle,
256 #[serde(default)]
257 pub placeholder_text: Option<TextStyle>,
258 pub selection: SelectionStyle,
259}
260
261#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq)]
262pub struct BlockStyle {
263 pub background: Option<Color>,
264 pub border: Option<Color>,
265}
266
267impl EditorStyle {
268 pub fn placeholder_text(&self) -> &TextStyle {
269 self.placeholder_text.as_ref().unwrap_or(&self.text)
270 }
271}
272
273impl InputEditorStyle {
274 pub fn as_editor(&self) -> EditorStyle {
275 EditorStyle {
276 text: self.text.clone(),
277 placeholder_text: self.placeholder_text.clone(),
278 background: self
279 .container
280 .background_color
281 .unwrap_or(Color::transparent_black()),
282 selection: self.selection,
283 gutter_background: Default::default(),
284 active_line_background: Default::default(),
285 line_number: Default::default(),
286 line_number_active: Default::default(),
287 guest_selections: Default::default(),
288 syntax: Default::default(),
289 diagnostic_error: Default::default(),
290 diagnostic_warning: Default::default(),
291 diagnostic_information: Default::default(),
292 diagnostic_hint: Default::default(),
293 }
294 }
295}
296
297#[derive(Default)]
298pub struct SyntaxTheme {
299 pub highlights: Vec<(String, HighlightStyle)>,
300}
301
302impl SyntaxTheme {
303 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
304 Self { highlights }
305 }
306}
307
308impl<'de> Deserialize<'de> for SyntaxTheme {
309 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
310 where
311 D: serde::Deserializer<'de>,
312 {
313 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
314
315 let mut result = Self::new(Vec::new());
316 for (key, style) in syntax_data {
317 match result
318 .highlights
319 .binary_search_by(|(needle, _)| needle.cmp(&key))
320 {
321 Ok(i) | Err(i) => {
322 result.highlights.insert(i, (key, style));
323 }
324 }
325 }
326
327 Ok(result)
328 }
329}