refactor: redesign theme tokens and split catppuccin themes

This commit is contained in:
2026-05-13 20:02:26 +08:00
parent af5fd60eb5
commit 2c3de1fd6e
20 changed files with 797 additions and 667 deletions

View File

@@ -1,6 +1,6 @@
use gpui::Rgba;
mod catppuccin;
use crate::colors::hex;
use gpui::Rgba;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ThemeMode {
@@ -28,15 +28,49 @@ pub struct ThemeColors {
pub background: Rgba,
pub surface: Rgba,
pub surface_elevated: Rgba,
pub surface_chrome: Rgba,
pub surface_hover: Rgba,
pub surface_active: Rgba,
pub border: Rgba,
pub border_muted: Rgba,
pub border_strong: Rgba,
pub focus_ring: Rgba,
pub text: Rgba,
pub text_muted: Rgba,
pub accent: Rgba,
pub accent_hover: Rgba,
pub accent_text: Rgba,
pub success: Rgba,
pub warning: Rgba,
pub danger: Rgba,
pub text_subtle: Rgba,
pub text_disabled: Rgba,
pub icon_muted: Rgba,
pub link: Rgba,
pub link_hover: Rgba,
pub code_bg: Rgba,
pub code_border: Rgba,
pub selection_bg: Rgba,
pub selection_border: Rgba,
pub accent_fg: Rgba,
pub accent_muted: Rgba,
pub accent_border: Rgba,
pub accent_solid: Rgba,
pub accent_on_solid: Rgba,
pub success_fg: Rgba,
pub success_muted: Rgba,
pub success_border: Rgba,
pub success_solid: Rgba,
pub success_on_solid: Rgba,
pub warning_fg: Rgba,
pub warning_muted: Rgba,
pub warning_border: Rgba,
pub warning_solid: Rgba,
pub warning_on_solid: Rgba,
pub danger_fg: Rgba,
pub danger_muted: Rgba,
pub danger_border: Rgba,
pub danger_solid: Rgba,
pub danger_on_solid: Rgba,
pub info_fg: Rgba,
pub info_muted: Rgba,
pub info_border: Rgba,
pub info_solid: Rgba,
pub info_on_solid: Rgba,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@@ -52,20 +86,20 @@ impl ThemeFamily {
pub const fn id(self) -> &'static str {
match self {
| Self::Catppuccin => "catppuccin",
| Self::Catppuccin => catppuccin::FAMILY_ID,
}
}
pub const fn label(self) -> &'static str {
match self {
| Self::Catppuccin => "Catppuccin",
| Self::Catppuccin => catppuccin::FAMILY_LABEL,
}
}
pub const fn variant(self, mode: ThemeMode) -> ThemeVariant {
match (self, mode) {
| (Self::Catppuccin, ThemeMode::Light) => ThemeVariant::CatppuccinLatte,
| (Self::Catppuccin, ThemeMode::Dark) => ThemeVariant::CatppuccinMocha,
| (Self::Catppuccin, ThemeMode::Light) => ThemeVariant::CatppuccinLatte,
| (Self::Catppuccin, ThemeMode::Dark) => ThemeVariant::CatppuccinMocha,
}
}
@@ -92,64 +126,28 @@ impl ThemeVariant {
pub const fn family(self) -> ThemeFamily {
match self {
| Self::CatppuccinLatte | Self::CatppuccinMocha => ThemeFamily::Catppuccin,
| Self::CatppuccinLatte | Self::CatppuccinMocha => ThemeFamily::Catppuccin,
}
}
pub const fn mode(self) -> ThemeMode {
match self {
| Self::CatppuccinLatte => ThemeMode::Light,
| Self::CatppuccinMocha => ThemeMode::Dark,
| Self::CatppuccinLatte => ThemeMode::Light,
| Self::CatppuccinMocha => ThemeMode::Dark,
}
}
pub const fn label(self) -> &'static str {
match self {
| Self::CatppuccinLatte => "Catppuccin Latte",
| Self::CatppuccinMocha => "Catppuccin Mocha",
| Self::CatppuccinLatte => catppuccin::LATTE_LABEL,
| Self::CatppuccinMocha => catppuccin::MOCHA_LABEL,
}
}
pub const fn theme(self) -> Theme {
match self {
| Self::CatppuccinLatte => Theme {
id: "catppuccin-latte",
name: "Catppuccin Latte",
mode: ThemeMode::Light,
colors: ThemeColors {
background: hex(0xeff1f5),
surface: hex(0xeff1f5),
surface_elevated: hex(0xdce0e8),
border: hex(0xccd0da),
text: hex(0x4c4f69),
text_muted: hex(0x6c6f85),
accent: hex(0x8839ef),
accent_hover: hex(0x7287fd),
accent_text: hex(0xeff1f5),
success: hex(0x40a02b),
warning: hex(0xdf8e1d),
danger: hex(0xd20f39),
},
},
| Self::CatppuccinMocha => Theme {
id: "catppuccin-mocha",
name: "Catppuccin Mocha",
mode: ThemeMode::Dark,
colors: ThemeColors {
background: hex(0x1e1e2e),
surface: hex(0x181825),
surface_elevated: hex(0x313244),
border: hex(0x45475a),
text: hex(0xcdd6f4),
text_muted: hex(0xa6adc8),
accent: hex(0xcba6f7),
accent_hover: hex(0xb4befe),
accent_text: hex(0x1e1e2e),
success: hex(0xa6e3a1),
warning: hex(0xf9e2af),
danger: hex(0xf38ba8),
},
},
| Self::CatppuccinLatte => catppuccin::latte(),
| Self::CatppuccinMocha => catppuccin::mocha(),
}
}
}
@@ -157,8 +155,10 @@ impl ThemeVariant {
impl From<gpui::WindowAppearance> for ThemeMode {
fn from(value: gpui::WindowAppearance) -> Self {
match value {
| gpui::WindowAppearance::Light | gpui::WindowAppearance::VibrantLight => ThemeMode::Light,
| gpui::WindowAppearance::Dark | gpui::WindowAppearance::VibrantDark => ThemeMode::Dark,
| gpui::WindowAppearance::Light | gpui::WindowAppearance::VibrantLight => {
ThemeMode::Light
}
| gpui::WindowAppearance::Dark | gpui::WindowAppearance::VibrantDark => ThemeMode::Dark,
}
}
}