hotfix: include theme files into binary (#2566)
* fix: include theme files into binary * fix: delete unused features * fix: change user theme dir to optional
This commit is contained in:
parent
294b87803f
commit
9ed45357ff
5 changed files with 45 additions and 20 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
|
@ -1353,6 +1353,25 @@ dependencies = [
|
|||
"winapi-util",
|
||||
]
|
||||
|
||||
[[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"
|
||||
|
|
@ -4486,6 +4505,7 @@ dependencies = [
|
|||
"colorsys",
|
||||
"crossbeam",
|
||||
"directories-next",
|
||||
"include_dir",
|
||||
"insta",
|
||||
"interprocess",
|
||||
"kdl",
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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] = &[
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)?);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue