theme2.rs

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