1mod colors;
2mod default_colors;
3mod default_theme;
4mod registry;
5mod scale;
6mod settings;
7mod syntax;
8mod themes;
9
10use ::settings::Settings;
11pub use colors::*;
12pub use default_colors::*;
13pub use default_theme::*;
14pub use registry::*;
15pub use scale::*;
16pub use settings::*;
17pub use syntax::*;
18pub use themes::*;
19
20use gpui::{AppContext, Hsla, SharedString};
21
22#[derive(Debug, PartialEq, Clone, Copy)]
23pub enum Appearance {
24 Light,
25 Dark,
26}
27
28pub fn init(cx: &mut AppContext) {
29 cx.set_global(ThemeRegistry::default());
30 ThemeSettings::register(cx);
31}
32
33pub trait ActiveTheme {
34 fn theme(&self) -> &ThemeVariant;
35}
36
37impl ActiveTheme for AppContext {
38 fn theme(&self) -> &ThemeVariant {
39 &ThemeSettings::get_global(self).active_theme
40 }
41}
42
43pub struct ThemeFamily {
44 pub id: String,
45 pub name: SharedString,
46 pub author: SharedString,
47 pub themes: Vec<ThemeVariant>,
48 pub scales: ColorScales,
49}
50
51impl ThemeFamily {}
52
53pub struct ThemeVariant {
54 pub id: String,
55 pub name: SharedString,
56 pub appearance: Appearance,
57 pub styles: ThemeStyles,
58}
59
60impl ThemeVariant {
61 /// Returns the [`ThemeColors`] for the theme.
62 #[inline(always)]
63 pub fn colors(&self) -> &ThemeColors {
64 &self.styles.colors
65 }
66
67 /// Returns the [`SyntaxTheme`] for the theme.
68 #[inline(always)]
69 pub fn syntax(&self) -> &SyntaxTheme {
70 &self.styles.syntax
71 }
72
73 /// Returns the [`StatusColors`] for the theme.
74 #[inline(always)]
75 pub fn status(&self) -> &StatusColors {
76 &self.styles.status
77 }
78
79 /// Returns the [`GitStatusColors`] for the theme.
80 #[inline(always)]
81 pub fn git(&self) -> &GitStatusColors {
82 &self.styles.git
83 }
84
85 /// Returns the color for the syntax node with the given name.
86 #[inline(always)]
87 pub fn syntax_color(&self, name: &str) -> Hsla {
88 self.syntax().color(name)
89 }
90}