diff options
author | Jae-Heon Ji <32578710+jaeheonji@users.noreply.github.com> | 2023-06-20 05:57:39 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-20 05:57:39 +0900 |
commit | 9ed45357ff34599ab0c99142b944c00d0276df6e (patch) | |
tree | 77879b78da32ad56abfa47949a6a513f65551a07 | |
parent | 294b87803f1b6a66c8ae559e736c69aa676f90b3 (diff) |
hotfix: include theme files into binary (#2566)
* fix: include theme files into binary
* fix: delete unused features
* fix: change user theme dir to optional
-rw-r--r-- | Cargo.lock | 20 | ||||
-rw-r--r-- | zellij-utils/Cargo.toml | 1 | ||||
-rw-r--r-- | zellij-utils/src/consts.rs | 17 | ||||
-rw-r--r-- | zellij-utils/src/kdl/mod.rs | 14 | ||||
-rw-r--r-- | zellij-utils/src/setup.rs | 13 |
5 files changed, 45 insertions, 20 deletions
diff --git a/Cargo.lock b/Cargo.lock index ad00e69c8..2e1439327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1354,6 +1354,25 @@ dependencies = [ ] [[package]] +name = "include_dir" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] name = "indexmap" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4486,6 +4505,7 @@ dependencies = [ "colorsys", "crossbeam", "directories-next", + "include_dir", "insta", "interprocess", "kdl", diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 56df794f2..65398c532 100644 --- a/zellij-utils/Cargo.toml +++ b/zellij-utils/Cargo.toml @@ -41,6 +41,7 @@ kdl = { version = "4.5.0", features = ["span"] } shellexpand = "3.0.0" uuid = { version = "0.8.2", features = ["serde", "v4"] } async-channel = "1.8.0" +include_dir = "0.7.3" #[cfg(not(target_family = "wasm"))] [target.'cfg(not(target_family = "wasm"))'.dependencies] diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs index 047cf9862..50600a934 100644 --- a/zellij-utils/src/consts.rs +++ b/zellij-utils/src/consts.rs @@ -1,7 +1,7 @@ //! Zellij program-wide constants. -use crate::input::theme::Themes; use directories_next::ProjectDirs; +use include_dir::{include_dir, Dir}; use lazy_static::lazy_static; use once_cell::sync::OnceCell; use std::path::PathBuf; @@ -18,6 +18,8 @@ pub static DEBUG_MODE: OnceCell<bool> = OnceCell::new(); pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij"; pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir(); +pub static ZELLIJ_DEFAULT_THEMES: Dir = include_dir!("$CARGO_MANIFEST_DIR/assets/themes"); + const fn system_default_data_dir() -> &'static str { if let Some(data_dir) = std::option_env!("PREFIX") { data_dir @@ -34,19 +36,6 @@ lazy_static! { .cache_dir() .to_path_buf() .join(format!("{}", Uuid::new_v4())); - pub static ref ZELLIJ_DEFAULT_THEMES: Themes = { - let mut default_themes = Themes::default(); - - let path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/themes")); - match Themes::from_dir(path) { - Ok(themes) => { - default_themes = default_themes.merge(themes); - }, - Err(_) => {}, - } - - default_themes - }; } pub const FEATURES: &[&str] = &[ diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index dde484968..a75292900 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1766,11 +1766,8 @@ impl Themes { Ok(themes) } - pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { - // String is the theme name - let kdl_config = std::fs::read_to_string(&path_to_theme_file) - .map_err(|e| ConfigError::IoPath(e, path_to_theme_file.into()))?; - let kdl_config: KdlDocument = kdl_config.parse()?; + pub fn from_string(raw_string: String) -> Result<Self, ConfigError> { + let kdl_config: KdlDocument = raw_string.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(), @@ -1780,6 +1777,13 @@ impl Themes { Ok(all_themes_in_file) } + pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { + // String is the theme name + let kdl_config = std::fs::read_to_string(&path_to_theme_file) + .map_err(|e| ConfigError::IoPath(e, path_to_theme_file.into()))?; + 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) diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 13eb63c0c..44fed5fa8 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -65,7 +65,17 @@ pub fn get_default_data_dir() -> PathBuf { #[cfg(not(test))] fn get_default_themes() -> Themes { - ZELLIJ_DEFAULT_THEMES.to_owned() + let mut themes = Themes::default(); + for file in ZELLIJ_DEFAULT_THEMES.files() { + if let Some(content) = file.contents_utf8() { + match Themes::from_string(content.to_string()) { + Ok(theme) => themes = themes.merge(theme), + Err(_) => {}, + } + } + } + + themes } #[cfg(test)] @@ -324,6 +334,7 @@ impl Setup { let user_theme_dir = config_options.theme_dir.clone().or_else(|| { get_theme_dir(cli_args.config_dir.clone().or_else(find_default_config_dir)) + .filter(|dir| dir.exists()) }); if let Some(user_theme_dir) = user_theme_dir { config.themes = config.themes.merge(Themes::from_dir(user_theme_dir)?); |