theme2.rs

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