diff --git a/example/themes/gruvbox-light.kdl b/example/themes/gruvbox-light.kdl deleted file mode 100644 index 7bb33e6830..0000000000 --- a/example/themes/gruvbox-light.kdl +++ /dev/null @@ -1,16 +0,0 @@ -themes { - gruvbox-light { - fg 60 56 54 - bg 251 82 75 - black 40 40 40 - red 205 75 69 - green 152 151 26 - yellow 215 153 33 - blue 69 133 136 - magenta 177 98 134 - cyan 104 157 106 - white 213 196 161 - orange 214 93 14 - } -} - diff --git a/example/themes/gruvbox-dark.kdl b/example/themes/gruvbox.kdl similarity index 51% rename from example/themes/gruvbox-dark.kdl rename to example/themes/gruvbox.kdl index 53c9d6ab3c..2c7ca0c8f6 100644 --- a/example/themes/gruvbox-dark.kdl +++ b/example/themes/gruvbox.kdl @@ -1,4 +1,17 @@ themes { + gruvbox-light { + fg 60 56 54 + bg 251 82 75 + black 40 40 40 + red 205 75 69 + green 152 151 26 + yellow 215 153 33 + blue 69 133 136 + magenta 177 98 134 + cyan 104 157 106 + white 213 196 161 + orange 214 93 14 + } gruvbox-dark { fg 213 196 161 bg 40 40 40 diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__theme__theme_test__dracula_theme_from_file.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__theme__theme_test__dracula_theme_from_file.snap index 26ee77f898..315c6d50eb 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__theme__theme_test__dracula_theme_from_file.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__theme__theme_test__dracula_theme_from_file.snap @@ -1,11 +1,9 @@ --- source: zellij-utils/src/input/./unit/theme_test.rs -assertion_line: 15 expression: "format!(\"{:#?}\", theme)" --- -( - "dracula", - Theme { +{ + "dracula": Theme { palette: Palette { source: Default, theme_hue: Dark, @@ -106,4 +104,4 @@ expression: "format!(\"{:#?}\", theme)" ), }, }, -) +} diff --git a/zellij-utils/src/input/unit/theme_test.rs b/zellij-utils/src/input/unit/theme_test.rs index 5625920172..97d5adc925 100644 --- a/zellij-utils/src/input/unit/theme_test.rs +++ b/zellij-utils/src/input/unit/theme_test.rs @@ -11,13 +11,13 @@ fn theme_test_dir(theme: String) -> PathBuf { #[test] fn dracula_theme_from_file() { let path = theme_test_dir("dracula.kdl".into()); - let theme = Theme::from_path(path).unwrap(); + let theme = Themes::from_path(path).unwrap(); assert_snapshot!(format!("{:#?}", theme)); } #[test] fn no_theme_is_err() { let path = theme_test_dir("nonexistent.kdl".into()); - let theme = Theme::from_path(path); + let theme = Themes::from_path(path); assert!(theme.is_err()); } diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index b08e8510b3..d37463d4c6 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1587,10 +1587,8 @@ impl Themes { let themes = Themes::from_data(themes); Ok(themes) } -} -impl Theme { - pub fn from_path(path_to_theme_file: PathBuf) -> Result<(String, Self), ConfigError> { + pub fn from_path(path_to_theme_file: PathBuf) -> Result { // String is the theme name let mut file = File::open(path_to_theme_file.clone())?; let mut kdl_config = String::new(); @@ -1602,34 +1600,6 @@ impl Theme { kdl_config.span().len(), ))?; let all_themes_in_file = Themes::from_kdl(kdl_themes)?; - let theme_file_name = path_to_theme_file - .file_name() - .ok_or(ConfigError::new_kdl_error( - "Failed to find file name".into(), - kdl_config.span().offset(), - kdl_config.span().len(), - ))? - .to_string_lossy() - .to_string(); - if let Some(theme_name) = theme_file_name.strip_suffix(".kdl") { - let theme = - all_themes_in_file - .get_theme(theme_name) - .ok_or(ConfigError::new_kdl_error( - format!( - "Not theme with name {} found in file {:?}", - theme_name, path_to_theme_file - ), - kdl_config.span().offset(), - kdl_config.span().len(), - ))?; - Ok((theme_name.to_string(), theme.clone())) - } else { - Err(ConfigError::new_kdl_error( - "no theme file found".into(), - kdl_config.span().offset(), - kdl_config.span().len(), - )) - } + Ok(all_themes_in_file) } } diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index c105c929ee..a4b3e202cb 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -1,4 +1,4 @@ -use crate::input::theme::Theme; +use crate::input::theme::Themes; use crate::{ cli::{CliArgs, Command}, consts::{ @@ -241,10 +241,8 @@ impl Setup { for entry in (theme_dir.read_dir()?).flatten() { if let Some(extension) = entry.path().extension() { if extension == "kdl" { - match Theme::from_path(entry.path()) { - Ok((theme_name, theme)) => { - config.themes.insert(theme_name, theme); - }, + match Themes::from_path(entry.path()) { + Ok(themes) => config.themes = config.themes.merge(themes), Err(e) => { log::error!("error loading theme file: {:?}", e); },