feat(theme): add palette system and per-element theming
This commit is contained in:
1 parent
ecc2b2bb23
commit
80210364d5
40 files changed
+2900
-1120
No files matched your search
+4
-4
@@ -51,9 +51,9 @@ fn ensure_config_exists(default_path: &str) -> PathBuf {
|
||||
config_path
|
||||
}
|
||||
|
||||
pub fn load_config(config_path: &PathBuf) -> Result<Config, ConfigError> {
|
||||
pub fn load_config(config_path: &std::path::Path) -> Result<Config, ConfigError> {
|
||||
let built = match ConfigLoader::builder()
|
||||
.add_source(File::from(config_path.clone()).required(false))
|
||||
.add_source(File::from(config_path).required(false))
|
||||
.build()
|
||||
{
|
||||
Ok(c) => c,
|
||||
@@ -81,7 +81,7 @@ pub fn load_config(config_path: &PathBuf) -> Result<Config, ConfigError> {
|
||||
}
|
||||
|
||||
pub static SETTINGS: Lazy<Config> = Lazy::new(|| {
|
||||
let path: PathBuf = ensure_config_exists("assets/default.toml");
|
||||
let path: PathBuf = ensure_config_exists("assets/config.toml");
|
||||
match load_config(&path) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
@@ -90,7 +90,7 @@ pub static SETTINGS: Lazy<Config> = Lazy::new(|| {
|
||||
general: types::General::default(),
|
||||
paths: types::Paths::default(),
|
||||
defaults: types::Defaults::default(),
|
||||
colors: types::Colors::default(),
|
||||
ui: types::Ui::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-166
@@ -1,25 +1,19 @@
|
||||
use dirs_next;
|
||||
use ratatui::style::Color;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct General {
|
||||
#[serde(default)]
|
||||
pub debug: bool,
|
||||
}
|
||||
|
||||
impl Default for General {
|
||||
fn default() -> Self {
|
||||
General { debug: false }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Paths {
|
||||
#[serde(default = "default_instances_dir")]
|
||||
pub instances_dir: String,
|
||||
#[serde(default = "default_meta_dir")]
|
||||
pub meta_dir: String,
|
||||
#[serde(default)]
|
||||
pub java_path: Option<String>,
|
||||
}
|
||||
|
||||
@@ -42,6 +36,10 @@ impl Default for Paths {
|
||||
}
|
||||
|
||||
impl Paths {
|
||||
pub fn effective_java_path(&self) -> Option<&str> {
|
||||
self.java_path.as_deref().filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
pub fn resolve_instances_dir(&self) -> std::path::PathBuf {
|
||||
let raw = &self.instances_dir;
|
||||
if let Some(stripped) = raw.strip_prefix("~/") {
|
||||
@@ -102,169 +100,45 @@ impl Default for Defaults {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct Colors {
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub background: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub foreground: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub border_focused: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub border_unfocused: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub row_highlight: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub row_background: Color,
|
||||
#[serde(deserialize_with = "deserialize_color")]
|
||||
pub row_alternate_bg: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_popup_bg")]
|
||||
pub popup_bg: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_error")]
|
||||
pub error: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_warn")]
|
||||
pub warn: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_success")]
|
||||
pub success: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_accent")]
|
||||
pub accent: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_text_idle")]
|
||||
pub text_idle: Color,
|
||||
#[serde(
|
||||
deserialize_with = "deserialize_color",
|
||||
default = "default_progress_fill"
|
||||
)]
|
||||
pub progress_fill: Color,
|
||||
#[serde(
|
||||
deserialize_with = "deserialize_color",
|
||||
default = "default_progress_track"
|
||||
)]
|
||||
pub progress_track: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_badge_text")]
|
||||
pub badge_text: Color,
|
||||
#[serde(deserialize_with = "deserialize_color", default = "default_fade_to")]
|
||||
pub fade_to: Color,
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Ui {
|
||||
#[serde(default = "default_error_auto_dismiss_ms")]
|
||||
pub error_auto_dismiss_ms: u64,
|
||||
#[serde(default = "default_error_slide_start_ms")]
|
||||
pub error_slide_start_ms: u64,
|
||||
#[serde(default = "default_error_fly_out_ms")]
|
||||
pub error_fly_out_ms: u64,
|
||||
#[serde(default = "default_max_error_events")]
|
||||
pub max_error_events: usize,
|
||||
}
|
||||
|
||||
impl Default for Colors {
|
||||
fn default_error_auto_dismiss_ms() -> u64 {
|
||||
5000
|
||||
}
|
||||
|
||||
fn default_error_slide_start_ms() -> u64 {
|
||||
3500
|
||||
}
|
||||
|
||||
fn default_error_fly_out_ms() -> u64 {
|
||||
300
|
||||
}
|
||||
|
||||
fn default_max_error_events() -> usize {
|
||||
50
|
||||
}
|
||||
|
||||
impl Default for Ui {
|
||||
fn default() -> Self {
|
||||
Colors {
|
||||
background: Color::Reset,
|
||||
foreground: Color::White,
|
||||
border_focused: Color::White,
|
||||
border_unfocused: Color::DarkGray,
|
||||
row_highlight: Color::White,
|
||||
row_background: Color::Reset,
|
||||
row_alternate_bg: Color::Reset,
|
||||
popup_bg: default_popup_bg(),
|
||||
error: default_error(),
|
||||
warn: default_warn(),
|
||||
success: default_success(),
|
||||
accent: default_accent(),
|
||||
text_idle: default_text_idle(),
|
||||
progress_fill: default_progress_fill(),
|
||||
progress_track: default_progress_track(),
|
||||
badge_text: default_badge_text(),
|
||||
fade_to: default_fade_to(),
|
||||
Ui {
|
||||
error_auto_dismiss_ms: default_error_auto_dismiss_ms(),
|
||||
error_slide_start_ms: default_error_slide_start_ms(),
|
||||
error_fly_out_ms: default_error_fly_out_ms(),
|
||||
max_error_events: default_max_error_events(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_popup_bg() -> Color {
|
||||
Color::Rgb(0x1e, 0x1e, 0x1e)
|
||||
}
|
||||
|
||||
fn default_error() -> Color {
|
||||
Color::Red
|
||||
}
|
||||
|
||||
fn default_warn() -> Color {
|
||||
Color::Yellow
|
||||
}
|
||||
|
||||
fn default_success() -> Color {
|
||||
Color::Green
|
||||
}
|
||||
|
||||
fn default_accent() -> Color {
|
||||
Color::Yellow
|
||||
}
|
||||
|
||||
fn default_text_idle() -> Color {
|
||||
Color::DarkGray
|
||||
}
|
||||
|
||||
fn default_progress_fill() -> Color {
|
||||
Color::Green
|
||||
}
|
||||
|
||||
fn default_progress_track() -> Color {
|
||||
Color::DarkGray
|
||||
}
|
||||
|
||||
fn default_badge_text() -> Color {
|
||||
Color::Black
|
||||
}
|
||||
|
||||
fn default_fade_to() -> Color {
|
||||
Color::DarkGray
|
||||
}
|
||||
|
||||
pub fn parse_color(color: &str) -> Color {
|
||||
match color.to_lowercase().as_str() {
|
||||
"black" => Color::Black,
|
||||
"red" => Color::Red,
|
||||
"green" => Color::Green,
|
||||
"yellow" => Color::Yellow,
|
||||
"blue" => Color::Blue,
|
||||
"magenta" => Color::Magenta,
|
||||
"cyan" => Color::Cyan,
|
||||
"white" => Color::White,
|
||||
"gray" | "grey" => Color::Gray,
|
||||
"darkgray" | "darkgrey" => Color::DarkGray,
|
||||
"lightred" => Color::LightRed,
|
||||
"lightgreen" => Color::LightGreen,
|
||||
"lightyellow" => Color::LightYellow,
|
||||
"lightblue" => Color::LightBlue,
|
||||
"lightmagenta" => Color::LightMagenta,
|
||||
"lightcyan" => Color::LightCyan,
|
||||
"reset" => Color::Reset,
|
||||
hex if hex.starts_with('#') && hex.len() == 7 => {
|
||||
let r = u8::from_str_radix(&hex[1..3], 16).unwrap_or_else(|_| {
|
||||
tracing::warn!("Invalid hex color: {}", color);
|
||||
255
|
||||
});
|
||||
let g = u8::from_str_radix(&hex[3..5], 16).unwrap_or_else(|_| {
|
||||
tracing::warn!("Invalid hex color: {}", color);
|
||||
255
|
||||
});
|
||||
let b = u8::from_str_radix(&hex[5..7], 16).unwrap_or_else(|_| {
|
||||
tracing::warn!("Invalid hex color: {}", color);
|
||||
255
|
||||
});
|
||||
Color::Rgb(r, g, b)
|
||||
}
|
||||
_ => {
|
||||
tracing::warn!("Unknown color '{}', using White as fallback", color);
|
||||
Color::White
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_color<'de, D>(deserializer: D) -> Result<Color, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let color_str: String = match Deserialize::deserialize(deserializer) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to deserialize color field: {}", e);
|
||||
return Ok(Color::White);
|
||||
}
|
||||
};
|
||||
Ok(parse_color(&color_str))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
@@ -274,5 +148,5 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub defaults: Defaults,
|
||||
#[serde(default)]
|
||||
pub colors: Colors,
|
||||
pub ui: Ui,
|
||||
}
|
||||
Reference in new issue
Block a user