theme2.rs

 1mod colors;
 2mod default_colors;
 3mod default_theme;
 4mod registry;
 5mod scale;
 6mod settings;
 7mod syntax;
 8
 9use std::sync::Arc;
10
11use ::settings::Settings;
12pub use colors::*;
13pub use default_colors::*;
14pub use default_theme::*;
15pub use registry::*;
16pub use scale::*;
17pub use settings::*;
18pub use syntax::*;
19
20use gpui::{AppContext, Hsla, SharedString};
21
22#[derive(Debug, Clone, PartialEq)]
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) -> &Arc<ThemeVariant>;
35}
36
37impl ActiveTheme for AppContext {
38    fn theme(&self) -> &Arc<ThemeVariant> {
39        &ThemeSettings::get_global(self).active_theme
40    }
41}
42
43pub struct ThemeFamily {
44    #[allow(dead_code)]
45    pub(crate) id: String,
46    pub name: SharedString,
47    pub author: SharedString,
48    pub themes: Vec<ThemeVariant>,
49    pub scales: ColorScales,
50}
51
52impl ThemeFamily {}
53
54pub struct ThemeVariant {
55    #[allow(dead_code)]
56    pub(crate) id: String,
57    pub name: SharedString,
58    pub appearance: Appearance,
59    pub styles: ThemeStyles,
60}
61
62impl ThemeVariant {
63    /// Returns the [`ThemeColors`] for the theme.
64    #[inline(always)]
65    pub fn players(&self) -> &PlayerColors {
66        &self.styles.player
67    }
68
69    /// Returns the [`ThemeColors`] for the theme.
70    #[inline(always)]
71    pub fn colors(&self) -> &ThemeColors {
72        &self.styles.colors
73    }
74
75    /// Returns the [`SyntaxTheme`] for the theme.
76    #[inline(always)]
77    pub fn syntax(&self) -> &SyntaxTheme {
78        &self.styles.syntax
79    }
80
81    /// Returns the [`StatusColors`] for the theme.
82    #[inline(always)]
83    pub fn status(&self) -> &StatusColors {
84        &self.styles.status
85    }
86
87    /// Returns the [`GitStatusColors`] for the theme.
88    #[inline(always)]
89    pub fn git(&self) -> &GitStatusColors {
90        &self.styles.git
91    }
92
93    /// Returns the color for the syntax node with the given name.
94    #[inline(always)]
95    pub fn syntax_color(&self, name: &str) -> Hsla {
96        self.syntax().color(name)
97    }
98}