Repository: zellij-org/zellij (language: rust)

Issue:
0.37.1 requires the .config/zellij/themes dir to exist or it crashes on startup
Thank you for taking the time to file this issue! Please follow the instructions and fill in the missing parts below the instructions, if it is meaningful. Try to be brief and concise.

**In Case of Graphical or Performance Issues**

1. Delete the contents of `/tmp/zellij-1000/zellij-log`, ie with `cd /tmp/zellij-1000/` and `rm -fr zellij-log/` (`/tmp/` is `$TMPDIR/` on OSX)
2. Run `zellij --debug`
3. Run `stty size`, copy the result and attach it in the bug report
4. Recreate your issue.
5. Quit Zellij immediately with ctrl-q (your bug should ideally still be visible on screen)

Please attach the files that were created in `/tmp/zellij-1000/zellij-log/` to the extent you are comfortable with.

> The log file is completely empty and running with debug produces no extra output

**Basic information**

`zellij --version`: 0.37.1
`stty size`: 81 288
`uname -av` or `ver`(Windows): 6.3.8-zen1-1-zen

List of programs you interact with as, `PROGRAM --version`: `N/A`

**Further information**

The entire contents of my `config.kbl` file is this:
```
theme "tokyo-night"
```

In 0.37.0 this worked fine and zellij loaded with the correct built-in theme, in 0.37.1 it crashes with
```
IoError: No such file or directory (os error 2), File: /home/adam/.config/zellij/themes
```

If I manually create the directory `themes` in that folder it runs without crashing and loads the appropriate theme.



Discussion / hints:
I've encountered the same bug. 
OS: Ubuntu 22.04
Zellij: 0.37.1 installed with cargo

It seems it has something to do with [these revert ](https://github.com/zellij-org/zellij/commit/a35bdb71e61015cac4922556cb5246e0c775ffcd)
Ping @jaeheonji - when you have the chance

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index ad00e69c8e..2e1439327e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml
index 56df794f22..65398c5324 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 047cf98621..50600a9342 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 dde4849689..a752929005 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 13eb63c0c2..44fed5fa80 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)?);


Test patch: