mirror of
https://github.com/sxyazi/yazi.git
synced 2024-07-14 13:40:26 +03:00
feat: add prepend_keymap
and append_keymap
for configuring mixing (#546)
This commit is contained in:
parent
97a7eb7d47
commit
93dc1b78e2
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -2616,7 +2616,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-adaptor"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arc-swap",
|
||||
@ -2634,7 +2634,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-config"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arc-swap",
|
||||
@ -2659,7 +2659,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-core"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
@ -2688,7 +2688,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-fm"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"better-panic",
|
||||
@ -2715,7 +2715,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-plugin"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"ansi-to-tui",
|
||||
"anyhow",
|
||||
@ -2748,7 +2748,7 @@ checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632"
|
||||
|
||||
[[package]]
|
||||
name = "yazi-scheduler"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-priority-channel",
|
||||
@ -2769,7 +2769,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "yazi-shared"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.4.1",
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-adaptor"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-config"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -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 {
|
||||
@ -30,12 +30,29 @@ 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`.
|
||||
@ -43,7 +60,15 @@ In Yazi v0.2.0, `<Backspace>` previously hardcoded within the input component ha
|
||||
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,
|
||||
|
@ -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 {
|
||||
@ -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>,
|
||||
@ -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");
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::fs;
|
||||
use std::{fs, mem};
|
||||
|
||||
use toml::Table;
|
||||
|
||||
@ -7,6 +7,26 @@ 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 {
|
||||
@ -14,7 +34,7 @@ impl Preset {
|
||||
continue;
|
||||
};
|
||||
|
||||
if k == "icons" || max <= 1 {
|
||||
if max <= 1 {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -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"))
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-core"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -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()),
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-fm"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-plugin"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-scheduler"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "yazi-shared"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||
|
Loading…
Reference in New Issue
Block a user