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