1mod default_colors;
2mod default_theme;
3mod one_themes;
4mod registry;
5mod scale;
6mod settings;
7mod styles;
8#[cfg(not(feature = "importing-themes"))]
9mod themes;
10mod user_theme;
11
12use std::sync::Arc;
13
14use ::settings::Settings;
15pub use default_colors::*;
16pub use default_theme::*;
17pub use registry::*;
18pub use scale::*;
19pub use settings::*;
20pub use styles::*;
21#[cfg(not(feature = "importing-themes"))]
22pub use themes::*;
23pub use user_theme::*;
24
25use gpui::{AppContext, Hsla, SharedString};
26use serde::Deserialize;
27
28#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
29pub enum Appearance {
30 Light,
31 Dark,
32}
33
34#[derive(Debug, PartialEq, Eq, Clone, Copy)]
35pub enum LoadThemes {
36 /// Only load the base theme.
37 ///
38 /// No user themes will be loaded.
39 JustBase,
40
41 /// Load all of the built-in themes.
42 All,
43}
44
45pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
46 cx.set_global(ThemeRegistry::default());
47
48 match themes_to_load {
49 LoadThemes::JustBase => (),
50 LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),
51 }
52
53 ThemeSettings::register(cx);
54}
55
56pub trait ActiveTheme {
57 fn theme(&self) -> &Arc<Theme>;
58}
59
60impl ActiveTheme for AppContext {
61 fn theme(&self) -> &Arc<Theme> {
62 &ThemeSettings::get_global(self).active_theme
63 }
64}
65
66// impl<'a> ActiveTheme for WindowContext<'a> {
67// fn theme(&self) -> &Arc<Theme> {
68// &ThemeSettings::get_global(self.app()).active_theme
69// }
70// }
71
72pub struct ThemeFamily {
73 pub id: String,
74 pub name: SharedString,
75 pub author: SharedString,
76 pub themes: Vec<Theme>,
77 pub scales: ColorScales,
78}
79
80impl ThemeFamily {}
81
82pub struct Theme {
83 pub id: String,
84 pub name: SharedString,
85 pub appearance: Appearance,
86 pub styles: ThemeStyles,
87}
88
89impl Theme {
90 /// Returns the [`SystemColors`] for the theme.
91 #[inline(always)]
92 pub fn system(&self) -> &SystemColors {
93 &self.styles.system
94 }
95
96 /// Returns the [`PlayerColors`] for the theme.
97 #[inline(always)]
98 pub fn players(&self) -> &PlayerColors {
99 &self.styles.player
100 }
101
102 /// Returns the [`ThemeColors`] for the theme.
103 #[inline(always)]
104 pub fn colors(&self) -> &ThemeColors {
105 &self.styles.colors
106 }
107
108 /// Returns the [`SyntaxTheme`] for the theme.
109 #[inline(always)]
110 pub fn syntax(&self) -> &Arc<SyntaxTheme> {
111 &self.styles.syntax
112 }
113
114 /// Returns the [`StatusColors`] for the theme.
115 #[inline(always)]
116 pub fn status(&self) -> &StatusColors {
117 &self.styles.status
118 }
119
120 /// Returns the color for the syntax node with the given name.
121 #[inline(always)]
122 pub fn syntax_color(&self, name: &str) -> Hsla {
123 self.syntax().color(name)
124 }
125
126 /// Returns the [`DiagnosticStyle`] for the theme.
127 #[inline(always)]
128 pub fn diagnostic_style(&self) -> DiagnosticStyle {
129 DiagnosticStyle {
130 error: self.status().error,
131 warning: self.status().warning,
132 info: self.status().info,
133 hint: self.status().info,
134 ignored: self.status().ignored,
135 }
136 }
137
138 /// Returns the [`Appearance`] for the theme.
139 #[inline(always)]
140 pub fn appearance(&self) -> Appearance {
141 self.appearance
142 }
143}
144
145#[derive(Clone, Debug, Default)]
146pub struct DiagnosticStyle {
147 pub error: Hsla,
148 pub warning: Hsla,
149 pub info: Hsla,
150 pub hint: Hsla,
151 pub ignored: Hsla,
152}