Skip to content

Commit

Permalink
Revert "feat: add self-provided themes (#2224)"
Browse files Browse the repository at this point in the history
This reverts commit 63bfe9c.
  • Loading branch information
imsnif committed Mar 6, 2023
1 parent 0708c10 commit 35be0af
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 111 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions example/themes/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Themes

It contains examples showing how to write a theme.
Themes can contain different flavors in one file, or can be created as individual files.

If you would like to add a theme to zellij, please refer [zellij-utils/assets/themes](../../zellij-utils/assets/themes).
Example:

```
gruvbox.kdl
├─ gruvbox-light
└─ gruvbox-dark
or
gruvbox-light.kdl
└─ gruvbox-light
gruvbox-dark.kdl
└─ gruvbox-dark
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 0 additions & 34 deletions example/themes/example.kdl

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion zellij-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ miette = { version = "3.3.0", features = ["fancy"] }
regex = "1.5.5"
tempfile = "3.2.0"
kdl = { version = "4.5.0", features = ["span"] }
include_dir = "0.7.3"

#[cfg(not(target_family = "wasm"))]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
Expand Down
2 changes: 0 additions & 2 deletions zellij-utils/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Zellij program-wide constants.
use directories_next::ProjectDirs;
use include_dir::{include_dir, Dir};
use lazy_static::lazy_static;
use once_cell::sync::OnceCell;
use std::path::PathBuf;
Expand All @@ -16,7 +15,6 @@ 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_THEMES_DIR: 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") {
Expand Down
30 changes: 6 additions & 24 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
}
}
47 changes: 19 additions & 28 deletions zellij-utils/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(not(target_family = "wasm"))]
use crate::consts::ASSET_MAP;
use crate::consts::ZELLIJ_THEMES_DIR;
use crate::input::theme::Themes;
use crate::{
cli::{CliArgs, Command},
Expand Down Expand Up @@ -52,22 +51,6 @@ fn default_config_dirs() -> Vec<Option<PathBuf>> {
]
}

#[cfg(not(test))]
fn get_default_themes() -> Result<Themes, ConfigError> {
let mut themes = Themes::default();
for entry in ZELLIJ_THEMES_DIR.files() {
if let Some(entry) = entry.contents_utf8() {
themes = themes.merge(Themes::from_string(entry.to_string())?);
}
}
Ok(themes)
}

#[cfg(test)]
fn get_default_themes() -> Result<Themes, ConfigError> {
Ok(Themes::default())
}

/// Looks for an existing dir, uses that, else returns a
/// dir matching the config spec.
pub fn get_default_data_dir() -> PathBuf {
Expand Down Expand Up @@ -104,7 +87,6 @@ pub fn get_layout_dir(config_dir: Option<PathBuf>) -> Option<PathBuf> {
pub fn get_theme_dir(config_dir: Option<PathBuf>) -> Option<PathBuf> {
config_dir.map(|dir| dir.join("themes"))
}

pub fn dump_asset(asset: &[u8]) -> std::io::Result<()> {
std::io::stdout().write_all(asset)?;
Ok(())
Expand Down Expand Up @@ -328,13 +310,25 @@ impl Setup {
None => config.options.clone(),
};

config.themes = config.themes.merge(get_default_themes()?);

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))
});
if let Some(user_dir) = user_theme_dir {
config.themes = config.themes.merge(Themes::from_dir(user_dir)?);
if let Some(theme_dir) = config_options
.theme_dir
.clone()
.or_else(|| get_theme_dir(cli_args.config_dir.clone().or_else(find_default_config_dir)))
{
if theme_dir.is_dir() {
for entry in (theme_dir.read_dir()?).flatten() {
if let Some(extension) = entry.path().extension() {
if extension == "kdl" {
match Themes::from_path(entry.path()) {
Ok(themes) => config.themes = config.themes.merge(themes),
Err(e) => {
log::error!("error loading theme file: {:?}", e);
},
}
}
}
}
}
}

if let Some(Command::Setup(ref setup)) = &cli_args.command {
Expand Down Expand Up @@ -520,7 +514,6 @@ impl Setup {

Ok(())
}

fn generate_completion(shell: &str) {
let shell: Shell = match shell.to_lowercase().parse() {
Ok(shell) => shell,
Expand Down Expand Up @@ -571,7 +564,6 @@ impl Setup {
_ => {},
}
}

fn parse_layout_and_override_config(
cli_config_options: Option<&Options>,
config: Config,
Expand Down Expand Up @@ -601,7 +593,6 @@ impl Setup {
// that needs to take precedence
Layout::from_path_or_default(chosen_layout.as_ref(), layout_dir.clone(), config)
}

fn handle_setup_commands(cli_args: &CliArgs) {
if let Some(Command::Setup(ref setup)) = &cli_args.command {
setup.from_cli().map_or_else(
Expand Down

0 comments on commit 35be0af

Please sign in to comment.