fix: switch default profile to terminal and fixed some comments
This commit is contained in:
1 parent
971375bf1f
commit
52787b57c7
71 files changed
+671
-188
No files matched your search
@@ -1,3 +1,6 @@
|
||||
// config loading: reads config.toml from the platform config dir, creates defaults if missing.
|
||||
// everything lands in the SETTINGS static so the rest of the app can just grab it.
|
||||
|
||||
use config::{Config as ConfigLoader, ConfigError, File};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
@@ -15,6 +18,7 @@ pub fn get_config_path() -> PathBuf {
|
||||
.join("mcl")
|
||||
}
|
||||
|
||||
// seeds the config file from the bundled default on first run
|
||||
fn ensure_config_exists() -> PathBuf {
|
||||
let config_path = get_config_path().join("config.toml");
|
||||
if !config_path.exists() {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// all the config structs that map to sections in config.toml.
|
||||
// everything has sane defaults so a blank file (or no file) still works.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::Deserialize;
|
||||
@@ -43,6 +46,7 @@ impl Default for Paths {
|
||||
}
|
||||
}
|
||||
|
||||
// expand ~ in paths since toml doesn't do that for us
|
||||
pub fn resolve_path(raw: &str) -> PathBuf {
|
||||
if let Some(stripped) = raw.strip_prefix("~/") {
|
||||
if let Some(home) = dirs_next::home_dir() {
|
||||
@@ -94,6 +98,8 @@ impl Default for Defaults {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
// timing knobs for the error toast animation: show for 5s, start sliding at 3.5s,
|
||||
// fly off screen over 300ms. tweak these if the toasts feel too fast or slow.
|
||||
pub struct Ui {
|
||||
#[serde(default = "default_error_auto_dismiss_ms")]
|
||||
pub error_auto_dismiss_ms: u64,
|
||||
|
||||
+19
-13
@@ -1,3 +1,7 @@
|
||||
// theme resolution: loads theme.toml, picks a base theme (builtin or custom file),
|
||||
// then layers user color overrides on top. supports loading .toml themes from the
|
||||
// config/theme/ directory or by absolute path.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
@@ -92,6 +96,7 @@ fn ensure_theme_exists(path: &Path) {
|
||||
let _ = std::fs::write(path, include_str!("../../assets/theme.toml"));
|
||||
}
|
||||
|
||||
// start from a base theme, then override individual colors if the user specified any
|
||||
fn resolve_app_theme(config: &ThemeConfig) -> Box<dyn Theme> {
|
||||
let base = load_base_theme(&config.theme);
|
||||
|
||||
@@ -112,21 +117,23 @@ fn resolve_app_theme(config: &ThemeConfig) -> Box<dyn Theme> {
|
||||
warning: overrides.warning.unwrap_or_else(|| base.warning()),
|
||||
info: overrides.info.unwrap_or_else(|| base.info()),
|
||||
diff_added: overrides.diff_added.unwrap_or_else(|| base.diff_added()),
|
||||
diff_removed: overrides.diff_removed.unwrap_or_else(|| base.diff_removed()),
|
||||
diff_context: overrides.diff_context.unwrap_or_else(|| base.diff_context()),
|
||||
diff_removed: overrides
|
||||
.diff_removed
|
||||
.unwrap_or_else(|| base.diff_removed()),
|
||||
diff_context: overrides
|
||||
.diff_context
|
||||
.unwrap_or_else(|| base.diff_context()),
|
||||
border: overrides.border.unwrap_or_else(|| base.border()),
|
||||
surface: overrides.surface.unwrap_or_else(|| base.surface()),
|
||||
background: overrides.background.unwrap_or_else(|| base.background()),
|
||||
})
|
||||
}
|
||||
|
||||
/// Load a base theme by built-in name or file path.
|
||||
// tries to find the theme: absolute path > config/theme/<name> > config/theme/<name>.toml > builtin
|
||||
fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
||||
// Try as a file path first (absolute or relative to config dir)
|
||||
let path = if Path::new(name).is_absolute() {
|
||||
Some(std::path::PathBuf::from(name))
|
||||
} else {
|
||||
// Check in the mcl config theme directory
|
||||
let theme_dir = super::get_config_path().join("theme");
|
||||
let candidate = theme_dir.join(name);
|
||||
if candidate.exists() {
|
||||
@@ -142,15 +149,15 @@ fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
||||
};
|
||||
|
||||
if let Some(path) = path
|
||||
&& let Ok(content) = std::fs::read_to_string(&path) {
|
||||
if let Ok(custom) = toml::from_str::<CustomTheme>(&content) {
|
||||
return Box::new(custom);
|
||||
} else {
|
||||
tracing::warn!("Failed to parse theme file: {}", path.display());
|
||||
}
|
||||
&& let Ok(content) = std::fs::read_to_string(&path)
|
||||
{
|
||||
if let Ok(custom) = toml::from_str::<CustomTheme>(&content) {
|
||||
return Box::new(custom);
|
||||
} else {
|
||||
tracing::warn!("Failed to parse theme file: {}", path.display());
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to built-in theme by name
|
||||
resolve_theme(name)
|
||||
}
|
||||
|
||||
@@ -218,7 +225,6 @@ accent = "Red"
|
||||
};
|
||||
let theme = resolve_app_theme(&config);
|
||||
assert_eq!(theme.accent(), Color::Red);
|
||||
// Other colors should come from dracula base
|
||||
let base = resolve_theme("dracula");
|
||||
assert_eq!(theme.text(), base.text());
|
||||
assert_eq!(theme.error(), base.error());
|
||||
|
||||
Reference in new issue
Block a user