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 [`SystemColors`] for the theme.
67 #[inline(always)]
68 pub fn system(&self) -> &SystemColors {
69 &self.styles.system
70 }
71
72 /// Returns the [`PlayerColors`] for the theme.
73 #[inline(always)]
74 pub fn players(&self) -> &PlayerColors {
75 &self.styles.player
76 }
77
78 /// Returns the [`ThemeColors`] for the theme.
79 #[inline(always)]
80 pub fn colors(&self) -> &ThemeColors {
81 &self.styles.colors
82 }
83
84 /// Returns the [`SyntaxTheme`] for the theme.
85 #[inline(always)]
86 pub fn syntax(&self) -> &Arc<SyntaxTheme> {
87 &self.styles.syntax
88 }
89
90 /// Returns the [`StatusColors`] for the theme.
91 #[inline(always)]
92 pub fn status(&self) -> &StatusColors {
93 &self.styles.status
94 }
95
96 /// Returns the [`GitStatusColors`] for the theme.
97 #[inline(always)]
98 pub fn git(&self) -> &GitStatusColors {
99 &self.styles.git
100 }
101
102 /// Returns the color for the syntax node with the given name.
103 #[inline(always)]
104 pub fn syntax_color(&self, name: &str) -> Hsla {
105 self.syntax().color(name)
106 }
107
108 /// Returns the [`StatusColors`] for the theme.
109 #[inline(always)]
110 pub fn diagnostic_style(&self) -> DiagnosticStyle {
111 DiagnosticStyle {
112 error: self.status().error,
113 warning: self.status().warning,
114 info: self.status().info,
115 hint: self.status().info,
116 ignored: self.status().ignored,
117 }
118 }
119}
120
121#[derive(Clone, Debug)]
122pub struct DiagnosticStyle {
123 pub error: Hsla,
124 pub warning: Hsla,
125 pub info: Hsla,
126 pub hint: Hsla,
127 pub ignored: Hsla,
128}