1#![warn(missing_docs)]
26#![forbid(unsafe_code)]
27#![deny(clippy::unwrap_used)]
28#![deny(clippy::expect_used)]
29
30pub mod colors;
31pub mod config;
32pub mod derive;
33pub mod icons;
34
35use gpui_component::theme::{Theme, ThemeMode};
36use native_theme::{NativeTheme, ResolvedTheme, ThemeVariant};
37
38#[deprecated(since = "0.3.2", note = "Use NativeTheme::pick_variant() instead")]
43#[allow(deprecated)]
44pub fn pick_variant(theme: &NativeTheme, is_dark: bool) -> Option<&ThemeVariant> {
45 theme.pick_variant(is_dark)
46}
47
48pub fn to_theme(resolved: &ResolvedTheme, name: &str, is_dark: bool) -> Theme {
55 let theme_color = colors::to_theme_color(resolved);
56 let mode = if is_dark {
57 ThemeMode::Dark
58 } else {
59 ThemeMode::Light
60 };
61 let theme_config = config::to_theme_config(resolved, name, mode);
62
63 let mut theme = Theme::from(&theme_color);
70 theme.apply_config(&theme_config.into());
71 theme.colors = theme_color;
72 theme
73}
74
75#[cfg(test)]
76#[allow(deprecated)]
77#[allow(clippy::unwrap_used, clippy::expect_used)]
78mod tests {
79 use super::*;
80
81 fn test_resolved() -> ResolvedTheme {
82 let nt = NativeTheme::preset("catppuccin-mocha").expect("preset must exist");
83 let mut v = nt
84 .pick_variant(false)
85 .expect("preset must have light variant")
86 .clone();
87 v.resolve();
88 v.validate().expect("resolved preset must validate")
89 }
90
91 #[test]
92 fn pick_variant_light_first() {
93 let nt = NativeTheme::preset("catppuccin-mocha").expect("preset must exist");
94 let picked = pick_variant(&nt, false);
95 assert!(picked.is_some());
96 }
97
98 #[test]
99 fn pick_variant_dark_first() {
100 let nt = NativeTheme::preset("catppuccin-mocha").expect("preset must exist");
101 let picked = pick_variant(&nt, true);
102 assert!(picked.is_some());
103 }
104
105 #[test]
106 fn pick_variant_empty_returns_none() {
107 let theme = NativeTheme::new("Empty");
108 assert!(pick_variant(&theme, false).is_none());
109 assert!(pick_variant(&theme, true).is_none());
110 }
111
112 #[test]
113 fn to_theme_produces_valid_theme() {
114 let resolved = test_resolved();
115 let theme = to_theme(&resolved, "Test", false);
116
117 assert!(!theme.is_dark());
119 }
120
121 #[test]
122 fn to_theme_dark_mode() {
123 let nt = NativeTheme::preset("catppuccin-mocha").expect("preset must exist");
124 let mut v = nt
125 .pick_variant(true)
126 .expect("preset must have dark variant")
127 .clone();
128 v.resolve();
129 let resolved = v.validate().expect("resolved preset must validate");
130 let theme = to_theme(&resolved, "DarkTest", true);
131
132 assert!(theme.is_dark());
133 }
134}