Skip to content

Commit

Permalink
feat: add prepend_keymap and append_keymap for configuring mixing (
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Jan 20, 2024
1 parent 97a7eb7 commit 93dc1b7
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 78 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ cd $SCRIPT_DIR/..
echo "Bumping version: $1"

TOML_FILES="$(git ls-files '*Cargo.toml')"
perl -pi -e "s/^version .*= .*\$/version = \"$1\"/" $TOML_FILES
perl -pi -e "s/^(yazi-[a-z]+)\\s*=\\s*{.*\$/\\1 = { path = \"..\/\\1\", version = \"$1\" }/" $TOML_FILES
perl -pi -e "s/^version .*= .*\$/version = \"$1\"/" -- $TOML_FILES
perl -pi -e "s/^(yazi-[a-z]+)\\s*=\\s*{.*\$/\\1 = { path = \"..\/\\1\", version = \"$1\" }/" -- $TOML_FILES

ESLINT_USE_FLAT_CONFIG=true eslint -c ~/.config/rules/eslint/eslint.config.cjs --fix -- $TOML_FILES
6 changes: 3 additions & 3 deletions yazi-adaptor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-adaptor"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,8 +9,8 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-config = { path = "../yazi-config", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-config = { path = "../yazi-config", version = "0.2.2" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }

# External dependencies
anyhow = "^1"
Expand Down
4 changes: 2 additions & 2 deletions yazi-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-config"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,7 +9,7 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }

# External dependencies
anyhow = "^1"
Expand Down
35 changes: 30 additions & 5 deletions yazi-config/src/keymap/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Deserializer};
use yazi_shared::Layer;

use super::Control;
use crate::MERGED_KEYMAP;
use crate::{Preset, MERGED_KEYMAP};

#[derive(Debug)]
pub struct Keymap {
Expand Down Expand Up @@ -30,20 +30,45 @@ impl<'de> Deserialize<'de> for Keymap {
}
#[derive(Deserialize)]
struct Inner {
keymap: Vec<Control>,
keymap: Vec<Control>,
#[serde(default)]
prepend_keymap: Vec<Control>,
#[serde(default)]
append_keymap: Vec<Control>,
}

let shadow = Shadow::deserialize(deserializer)?;
let mut shadow = Shadow::deserialize(deserializer)?;

// TODO: remove this when v0.2.0 is released --
#[rustfmt::skip]
Preset::mix(&mut shadow.manager.keymap, shadow.manager.prepend_keymap, shadow.manager.append_keymap);
#[rustfmt::skip]
Preset::mix(&mut shadow.tasks.keymap, shadow.tasks.prepend_keymap, shadow.tasks.append_keymap);
#[rustfmt::skip]
Preset::mix(&mut shadow.select.keymap, shadow.select.prepend_keymap, shadow.select.append_keymap);
#[rustfmt::skip]
Preset::mix(&mut shadow.input.keymap, shadow.input.prepend_keymap, shadow.input.append_keymap);
#[rustfmt::skip]
Preset::mix(&mut shadow.help.keymap, shadow.help.prepend_keymap, shadow.help.append_keymap);
#[rustfmt::skip]
Preset::mix(&mut shadow.completion.keymap, shadow.completion.prepend_keymap, shadow.completion.append_keymap);

// TODO: remove this when v0.2.3 is released --
if !shadow.input.keymap.iter().any(|c| c.on() == "<Backspace>") {
println!(
"WARNING: Default keybinding for `<Backspace>` is missing, please add a `{}` to the `[input]` section of `keymap.toml`.
In Yazi v0.2.0, `<Backspace>` previously hardcoded within the input component has been moved to `keymap.toml` to allow users to customize it.",
r#"{ on = [ "<Backspace>" ], exec = "backspace" }"#
);
}
// TODO: -- remove this when v0.2.0 is released
// TODO: -- remove this when v0.2.3 is released

// TODO: remove this when v0.2.3 is released --
if shadow.manager.keymap.iter().any(|c| c.exec().contains("--empty=name")) {
println!(
"WARNING: `rename --empty=name` is deprecated in Yazi v0.2.2, please use `rename --empty=stem` instead.",
);
}
// TODO: -- remove this when v0.2.3 is released

Ok(Self {
manager: shadow.manager.keymap,
Expand Down
26 changes: 8 additions & 18 deletions yazi-config/src/plugin/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use serde::Deserialize;
use yazi_shared::{event::Exec, Condition, MIME_DIR};

use crate::{pattern::Pattern, plugin::MAX_PRELOADERS, Priority, MERGED_YAZI};
use crate::{pattern::Pattern, plugin::MAX_PRELOADERS, Preset, Priority, MERGED_YAZI};

#[derive(Deserialize)]
pub struct Plugin {
Expand All @@ -30,6 +30,11 @@ pub struct PluginRule {

impl Default for Plugin {
fn default() -> Self {
#[derive(Deserialize)]
struct Outer {
plugin: Shadow,
}

#[derive(Deserialize)]
struct Shadow {
preloaders: Vec<PluginRule>,
Expand All @@ -45,24 +50,9 @@ impl Default for Plugin {
append_previewers: Vec<PluginRule>,
}

#[derive(Deserialize)]
struct Outer {
plugin: Shadow,
}

let mut shadow = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().plugin;
shadow.preloaders = shadow
.prepend_preloaders
.into_iter()
.chain(shadow.preloaders)
.chain(shadow.append_preloaders)
.collect();
shadow.previewers = shadow
.prepend_previewers
.into_iter()
.chain(shadow.previewers)
.chain(shadow.append_previewers)
.collect();
Preset::mix(&mut shadow.preloaders, shadow.prepend_preloaders, shadow.append_preloaders);
Preset::mix(&mut shadow.previewers, shadow.prepend_previewers, shadow.append_previewers);

if shadow.preloaders.len() > MAX_PRELOADERS as usize {
panic!("Too many preloaders");
Expand Down
39 changes: 22 additions & 17 deletions yazi-config/src/preset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fs;
use std::{fs, mem};

use toml::Table;

Expand All @@ -7,14 +7,34 @@ use crate::BOOT;
pub(crate) struct Preset;

impl Preset {
#[inline]
pub(crate) fn keymap() -> String {
Self::merge_str("keymap.toml", include_str!("../preset/keymap.toml"))
}

#[inline]
pub(crate) fn theme() -> String {
Self::merge_str("theme.toml", include_str!("../preset/theme.toml"))
}

#[inline]
pub(crate) fn yazi() -> String {
Self::merge_str("yazi.toml", include_str!("../preset/yazi.toml"))
}

#[inline]
pub(crate) fn mix<T>(a: &mut Vec<T>, b: Vec<T>, c: Vec<T>) {
*a = b.into_iter().chain(mem::take(a)).chain(c).collect();
}

fn merge(a: &mut Table, b: &Table, max: u8) {
for (k, v) in b {
let Some(a) = a.get_mut(k) else {
a.insert(k.clone(), v.clone());
continue;
};

if k == "icons" || max <= 1 {
if max <= 1 {
continue;
}

Expand All @@ -36,19 +56,4 @@ impl Preset {
Self::merge(&mut user, &base, 2);
user.to_string()
}

#[inline]
pub(crate) fn keymap() -> String {
Self::merge_str("keymap.toml", include_str!("../preset/keymap.toml"))
}

#[inline]
pub(crate) fn theme() -> String {
Self::merge_str("theme.toml", include_str!("../preset/theme.toml"))
}

#[inline]
pub(crate) fn yazi() -> String {
Self::merge_str("yazi.toml", include_str!("../preset/yazi.toml"))
}
}
12 changes: 6 additions & 6 deletions yazi-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-core"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,11 +9,11 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.1" }
yazi-config = { path = "../yazi-config", version = "0.2.1" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.1" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.2" }
yazi-config = { path = "../yazi-config", version = "0.2.2" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.2" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.2" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }

# External dependencies
anyhow = "^1"
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Manager {

let ext = url.extension();
match by {
"name" => ext.map_or_else(String::new, |s| format!(".{}", s.to_string_lossy().into_owned())),
"stem" => ext.map_or_else(String::new, |s| format!(".{}", s.to_string_lossy().into_owned())),
"ext" if ext.is_some() => format!("{}.", url.file_stem().unwrap().to_string_lossy()),
"dot_ext" if ext.is_some() => url.file_stem().unwrap().to_string_lossy().into_owned(),
_ => url.file_name().map_or_else(String::new, |s| s.to_string_lossy().into_owned()),
Expand Down
14 changes: 7 additions & 7 deletions yazi-fm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-fm"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,12 +9,12 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.1" }
yazi-config = { path = "../yazi-config", version = "0.2.1" }
yazi-core = { path = "../yazi-core", version = "0.2.1" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.1" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.2" }
yazi-config = { path = "../yazi-config", version = "0.2.2" }
yazi-core = { path = "../yazi-core", version = "0.2.2" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.2" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.2" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }

# External dependencies
anyhow = "^1"
Expand Down
8 changes: 4 additions & 4 deletions yazi-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-plugin"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.1" }
yazi-config = { path = "../yazi-config", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.2" }
yazi-config = { path = "../yazi-config", version = "0.2.2" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }

# External dependencies
ansi-to-tui = "^3"
Expand Down
10 changes: 5 additions & 5 deletions yazi-scheduler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-scheduler"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,10 +9,10 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.1" }
yazi-config = { path = "../yazi-config", version = "0.2.1" }
yazi-shared = { path = "../yazi-shared", version = "0.2.1" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.1" }
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.2" }
yazi-config = { path = "../yazi-config", version = "0.2.2" }
yazi-shared = { path = "../yazi-shared", version = "0.2.2" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.2" }

# External dependencies
anyhow = "^1"
Expand Down
2 changes: 1 addition & 1 deletion yazi-shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-shared"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand Down

0 comments on commit 93dc1b7

Please sign in to comment.