@@ -3,12 +3,24 @@ |
| 3 | 3 | pub mod lua; |
| 4 | 4 | |
| 5 | 5 | use anyhow::{Context, Result}; |
| 6 | | -use serde::{Deserialize, Serialize}; |
| 6 | +use gartk_core::Color; |
| 7 | +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; |
| 7 | 8 | use std::path::PathBuf; |
| 8 | 9 | use tracing::{debug, info, warn}; |
| 9 | 10 | |
| 10 | 11 | use crate::rules::Rule; |
| 11 | 12 | |
| 13 | +/// Serialize Color as hex string |
| 14 | +fn serialize_color<S: Serializer>(color: &Color, s: S) -> Result<S::Ok, S::Error> { |
| 15 | + s.serialize_str(&color.to_hex()) |
| 16 | +} |
| 17 | + |
| 18 | +/// Deserialize Color from any color string (hex, rgb, rgba, named) |
| 19 | +fn deserialize_color<'de, D: Deserializer<'de>>(d: D) -> Result<Color, D::Error> { |
| 20 | + let s: String = Deserialize::deserialize(d)?; |
| 21 | + Color::parse(&s).map_err(de::Error::custom) |
| 22 | +} |
| 23 | + |
| 12 | 24 | /// Get the default configuration file path |
| 13 | 25 | fn config_path() -> PathBuf { |
| 14 | 26 | dirs::config_dir() |
@@ -161,47 +173,56 @@ impl Default for AppearanceConfig { |
| 161 | 173 | } |
| 162 | 174 | } |
| 163 | 175 | |
| 164 | | -/// Color configuration |
| 176 | +/// Color configuration using gartk Color type |
| 165 | 177 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 166 | 178 | #[serde(default)] |
| 167 | 179 | pub struct ColorConfig { |
| 168 | 180 | /// Default background color |
| 169 | | - pub background: String, |
| 181 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 182 | + pub background: Color, |
| 170 | 183 | /// Default foreground (text) color |
| 171 | | - pub foreground: String, |
| 184 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 185 | + pub foreground: Color, |
| 172 | 186 | /// Default border color |
| 173 | | - pub border: String, |
| 187 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 188 | + pub border: Color, |
| 174 | 189 | |
| 175 | 190 | /// Low urgency background |
| 176 | | - pub low_background: String, |
| 191 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 192 | + pub low_background: Color, |
| 177 | 193 | /// Low urgency foreground |
| 178 | | - pub low_foreground: String, |
| 194 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 195 | + pub low_foreground: Color, |
| 179 | 196 | /// Low urgency border |
| 180 | | - pub low_border: String, |
| 197 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 198 | + pub low_border: Color, |
| 181 | 199 | |
| 182 | 200 | /// Critical urgency background |
| 183 | | - pub critical_background: String, |
| 201 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 202 | + pub critical_background: Color, |
| 184 | 203 | /// Critical urgency foreground |
| 185 | | - pub critical_foreground: String, |
| 204 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 205 | + pub critical_foreground: Color, |
| 186 | 206 | /// Critical urgency border |
| 187 | | - pub critical_border: String, |
| 207 | + #[serde(serialize_with = "serialize_color", deserialize_with = "deserialize_color")] |
| 208 | + pub critical_border: Color, |
| 188 | 209 | } |
| 189 | 210 | |
| 190 | 211 | impl Default for ColorConfig { |
| 191 | 212 | fn default() -> Self { |
| 192 | | - // Catppuccin-inspired colors |
| 213 | + // Catppuccin-inspired colors (matching gartk Theme::dark()) |
| 193 | 214 | Self { |
| 194 | | - background: "#1e1e2e".into(), |
| 195 | | - foreground: "#cdd6f4".into(), |
| 196 | | - border: "#45475a".into(), |
| 215 | + background: Color::from_hex("#1e1e2e").unwrap(), |
| 216 | + foreground: Color::from_hex("#cdd6f4").unwrap(), |
| 217 | + border: Color::from_hex("#45475a").unwrap(), |
| 197 | 218 | |
| 198 | | - low_background: "#1e1e2e".into(), |
| 199 | | - low_foreground: "#6c7086".into(), |
| 200 | | - low_border: "#45475a".into(), |
| 219 | + low_background: Color::from_hex("#1e1e2e").unwrap(), |
| 220 | + low_foreground: Color::from_hex("#6c7086").unwrap(), |
| 221 | + low_border: Color::from_hex("#45475a").unwrap(), |
| 201 | 222 | |
| 202 | | - critical_background: "#f38ba8".into(), |
| 203 | | - critical_foreground: "#1e1e2e".into(), |
| 204 | | - critical_border: "#f38ba8".into(), |
| 223 | + critical_background: Color::from_hex("#f38ba8").unwrap(), |
| 224 | + critical_foreground: Color::from_hex("#1e1e2e").unwrap(), |
| 225 | + critical_border: Color::from_hex("#f38ba8").unwrap(), |
| 205 | 226 | } |
| 206 | 227 | } |
| 207 | 228 | } |