1mod default_colors;
2mod default_theme;
3mod registry;
4mod scale;
5mod settings;
6mod styles;
7#[cfg(not(feature = "importing-themes"))]
8mod themes;
9mod user_theme;
10
11use std::sync::Arc;
12
13use ::settings::Settings;
14pub use default_colors::*;
15pub use default_theme::*;
16pub use registry::*;
17pub use scale::*;
18pub use settings::*;
19pub use styles::*;
20#[cfg(not(feature = "importing-themes"))]
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 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 [`DiagnosticStyle`] 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}
123
124#[cfg(feature = "stories")]
125mod story;
126#[cfg(feature = "stories")]
127pub use story::*;