1mod colors;
2mod default_colors;
3mod default_theme;
4mod registry;
5mod scale;
6mod settings;
7mod syntax;
8mod themes;
9mod user_theme;
10
11use std::sync::Arc;
12
13use ::settings::Settings;
14pub use colors::*;
15pub use default_colors::*;
16pub use default_theme::*;
17pub use registry::*;
18pub use scale::*;
19pub use settings::*;
20pub use syntax::*;
21pub use themes::*;
22pub use user_theme::*;
23
24use gpui::{AppContext, Hsla, SharedString};
25use serde::Deserialize;
26
27#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
28pub enum Appearance {
29 Light,
30 Dark,
31}
32
33pub fn init(cx: &mut AppContext) {
34 cx.set_global(ThemeRegistry::default());
35 ThemeSettings::register(cx);
36}
37
38pub trait ActiveTheme {
39 fn theme(&self) -> &Arc<Theme>;
40}
41
42impl ActiveTheme for AppContext {
43 fn theme(&self) -> &Arc<Theme> {
44 &ThemeSettings::get_global(self).active_theme
45 }
46}
47
48pub struct ThemeFamily {
49 pub id: String,
50 pub name: SharedString,
51 pub author: SharedString,
52 pub themes: Vec<Theme>,
53 pub scales: ColorScales,
54}
55
56impl ThemeFamily {}
57
58pub struct Theme {
59 pub id: String,
60 pub name: SharedString,
61 pub appearance: Appearance,
62 pub styles: ThemeStyles,
63}
64
65impl Theme {
66 /// Returns the [`ThemeColors`] for the theme.
67 #[inline(always)]
68 pub fn players(&self) -> &PlayerColors {
69 &self.styles.player
70 }
71
72 /// Returns the [`ThemeColors`] for the theme.
73 #[inline(always)]
74 pub fn colors(&self) -> &ThemeColors {
75 &self.styles.colors
76 }
77
78 /// Returns the [`SyntaxTheme`] for the theme.
79 #[inline(always)]
80 pub fn syntax(&self) -> &Arc<SyntaxTheme> {
81 &self.styles.syntax
82 }
83
84 /// Returns the [`StatusColors`] for the theme.
85 #[inline(always)]
86 pub fn status(&self) -> &StatusColors {
87 &self.styles.status
88 }
89
90 /// Returns the [`GitStatusColors`] for the theme.
91 #[inline(always)]
92 pub fn git(&self) -> &GitStatusColors {
93 &self.styles.git
94 }
95
96 /// Returns the color for the syntax node with the given name.
97 #[inline(always)]
98 pub fn syntax_color(&self, name: &str) -> Hsla {
99 self.syntax().color(name)
100 }
101
102 /// Returns the [`StatusColors`] for the theme.
103 #[inline(always)]
104 pub fn diagnostic_style(&self) -> DiagnosticStyle {
105 DiagnosticStyle {
106 error: self.status().error,
107 warning: self.status().warning,
108 info: self.status().info,
109 hint: self.status().info,
110 ignored: self.status().ignored,
111 }
112 }
113}
114
115#[derive(Clone, Debug)]
116pub struct DiagnosticStyle {
117 pub error: Hsla,
118 pub warning: Hsla,
119 pub info: Hsla,
120 pub hint: Hsla,
121 pub ignored: Hsla,
122}