diff options
Diffstat (limited to 'zellij-utils/src/kdl/mod.rs')
-rw-r--r-- | zellij-utils/src/kdl/mod.rs | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index 6d2c5958d..64fe0bac4 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1734,8 +1734,12 @@ impl Themes { Ok(themes) } - pub fn from_string(raw_string: String) -> Result<Self, ConfigError> { - let kdl_config: KdlDocument = raw_string.parse()?; + pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { + // String is the theme name + let mut file = File::open(path_to_theme_file.clone())?; + let mut kdl_config = String::new(); + file.read_to_string(&mut kdl_config)?; + let kdl_config: KdlDocument = kdl_config.parse()?; let kdl_themes = kdl_config.get("themes").ok_or(ConfigError::new_kdl_error( "No theme node found in file".into(), kdl_config.span().offset(), @@ -1744,26 +1748,4 @@ impl Themes { let all_themes_in_file = Themes::from_kdl(kdl_themes)?; Ok(all_themes_in_file) } - - pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { - // String is the theme name - let mut file = File::open(path_to_theme_file.clone())?; - let mut kdl_config = String::new(); - file.read_to_string(&mut kdl_config)?; - Themes::from_string(kdl_config) - } - - pub fn from_dir(path_to_theme_dir: PathBuf) -> Result<Self, ConfigError> { - let mut themes = Themes::default(); - for entry in std::fs::read_dir(path_to_theme_dir)? { - let entry = entry?; - let path = entry.path(); - if let Some(extension) = path.extension() { - if extension == "kdl" { - themes = themes.merge(Themes::from_path(path)?); - } - } - } - Ok(themes) - } } |