|
@@ -12,17 +12,21 @@ use serde_norway;
|
|
|
use std::collections::HashMap;
|
|
use std::collections::HashMap;
|
|
|
use std::path::PathBuf;
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
-#[derive(Debug, Default, Eq, PartialEq)]
|
|
|
|
|
|
|
+#[derive(Debug, Eq, PartialEq)]
|
|
|
pub struct ThemeConfig {
|
|
pub struct ThemeConfig {
|
|
|
// This is rather bare for now, will be expanded with config file
|
|
// This is rather bare for now, will be expanded with config file
|
|
|
- location: ConfigLoc,
|
|
|
|
|
|
|
+ location: PathBuf,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[derive(Debug, Default, PartialEq, Eq)]
|
|
|
|
|
-pub enum ConfigLoc {
|
|
|
|
|
- #[default]
|
|
|
|
|
- Default, // $XDG_CONFIG_HOME/eza/config|theme.yml
|
|
|
|
|
- Env(PathBuf), // $EZA_CONFIG_DIR
|
|
|
|
|
|
|
+impl Default for ThemeConfig {
|
|
|
|
|
+ fn default() -> Self {
|
|
|
|
|
+ ThemeConfig {
|
|
|
|
|
+ location: dirs::config_dir()
|
|
|
|
|
+ .unwrap_or_default()
|
|
|
|
|
+ .join("eza")
|
|
|
|
|
+ .join("theme.yml"),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
trait FromOverride<T>: Sized {
|
|
trait FromOverride<T>: Sized {
|
|
@@ -600,23 +604,13 @@ impl FromOverride<UiStylesOverride> for UiStyles {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
impl ThemeConfig {
|
|
impl ThemeConfig {
|
|
|
- pub fn from_path(path: &str) -> Self {
|
|
|
|
|
- let path = PathBuf::from(path);
|
|
|
|
|
- ThemeConfig {
|
|
|
|
|
- location: ConfigLoc::Env(path),
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ pub fn from_path(path: PathBuf) -> Self {
|
|
|
|
|
+ ThemeConfig { location: path }
|
|
|
}
|
|
}
|
|
|
pub fn to_theme(&self) -> Option<UiStyles> {
|
|
pub fn to_theme(&self) -> Option<UiStyles> {
|
|
|
- let ui_styles_override: Option<UiStylesOverride> = match &self.location {
|
|
|
|
|
- ConfigLoc::Default => {
|
|
|
|
|
- let path = dirs::config_dir()?.join("eza").join("theme.yml");
|
|
|
|
|
- let file = std::fs::File::open(path).ok()?;
|
|
|
|
|
- serde_norway::from_reader(&file).ok()
|
|
|
|
|
- }
|
|
|
|
|
- ConfigLoc::Env(path) => {
|
|
|
|
|
- let file = std::fs::File::open(path).ok()?;
|
|
|
|
|
- serde_norway::from_reader(&file).ok()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let ui_styles_override: Option<UiStylesOverride> = {
|
|
|
|
|
+ let file = std::fs::File::open(&self.location).ok()?;
|
|
|
|
|
+ serde_norway::from_reader(&file).ok()
|
|
|
};
|
|
};
|
|
|
FromOverride::from(ui_styles_override, Some(UiStyles::default()))
|
|
FromOverride::from(ui_styles_override, Some(UiStyles::default()))
|
|
|
}
|
|
}
|