theme2.rs

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