Skip to content

Commit

Permalink
feat: ya.hide() plugin API (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Mar 8, 2024
1 parent 3f80bc5 commit 9396d87
Show file tree
Hide file tree
Showing 38 changed files with 287 additions and 140 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"language":"en","flagWords":[],"version":"0.2","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff"]}
{"version":"0.2","flagWords":[],"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup"]}
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.3"
version = "0.2.4"
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.3" }
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
yazi-config = { path = "../yazi-config", version = "0.2.4" }
yazi-shared = { path = "../yazi-shared", version = "0.2.4" }

# External dependencies
anyhow = "^1"
Expand Down
6 changes: 3 additions & 3 deletions yazi-boot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yazi-boot"
version = "0.2.3"
version = "0.2.4"
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.3" }
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
yazi-config = { path = "../yazi-config", version = "0.2.4" }
yazi-shared = { path = "../yazi-shared", version = "0.2.4" }

# External dependencies
clap = { version = "^4", features = [ "derive" ] }
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.3"
version = "0.2.4"
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.3" }
yazi-shared = { path = "../yazi-shared", version = "0.2.4" }

# External dependencies
anyhow = "^1"
Expand Down
2 changes: 2 additions & 0 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,5 @@ sort_reverse = false

[log]
enabled = false

[headsup]
34 changes: 34 additions & 0 deletions yazi-config/src/headsup/headsup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use serde::{Deserialize, Deserializer};

use crate::MERGED_YAZI;

#[derive(Debug)]
pub struct Headsup {
// TODO: remove this once Yazi 0.3 is released --
pub disable_exec_warn: bool,
}

impl Default for Headsup {
fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() }
}

impl<'de> Deserialize<'de> for Headsup {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Outer {
headsup: Shadow,
}
#[derive(Deserialize)]
struct Shadow {
#[serde(default)]
disable_exec_warn: bool,
}

let outer = Outer::deserialize(deserializer)?;

Ok(Self { disable_exec_warn: outer.headsup.disable_exec_warn })
}
}
3 changes: 3 additions & 0 deletions yazi-config/src/headsup/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod headsup;

pub use headsup::*;
6 changes: 5 additions & 1 deletion yazi-config/src/keymap/control.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{borrow::Cow, collections::VecDeque};
use std::{borrow::Cow, collections::VecDeque, sync::atomic::Ordering};

use serde::{Deserialize, Deserializer};
use yazi_shared::event::Cmd;

use super::Key;
use crate::DEPRECATED_EXEC;

#[derive(Debug, Default)]
pub struct Control {
Expand Down Expand Up @@ -61,6 +62,9 @@ impl<'de> Deserialize<'de> for Control {
#[derive(Deserialize)]
struct VecCmd(#[serde(deserialize_with = "super::run_deserialize")] Vec<Cmd>);

if shadow.exec.is_some() {
DEPRECATED_EXEC.store(true, Ordering::Relaxed);
}
let Some(run) = shadow.run.or(shadow.exec) else {
return Err(serde::de::Error::custom("missing field `run` within `[keymap]`"));
};
Expand Down
21 changes: 21 additions & 0 deletions yazi-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use yazi_shared::{RoCell, Xdg};

pub mod headsup;
pub mod keymap;
mod layout;
mod log;
Expand All @@ -23,12 +24,17 @@ pub(crate) use pattern::*;
pub(crate) use preset::*;
pub use priority::*;

// TODO: remove this once Yazi 0.3 is released --
pub static DEPRECATED_EXEC: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);

static MERGED_YAZI: RoCell<String> = RoCell::new();
static MERGED_KEYMAP: RoCell<String> = RoCell::new();
static MERGED_THEME: RoCell<String> = RoCell::new();

pub static LAYOUT: RoCell<arc_swap::ArcSwap<Layout>> = RoCell::new();

pub static HEADSUP: RoCell<headsup::Headsup> = RoCell::new();
pub static KEYMAP: RoCell<keymap::Keymap> = RoCell::new();
pub static LOG: RoCell<log::Log> = RoCell::new();
pub static MANAGER: RoCell<manager::Manager> = RoCell::new();
Expand All @@ -49,6 +55,7 @@ pub fn init() {

LAYOUT.with(Default::default);

HEADSUP.with(Default::default);
KEYMAP.with(Default::default);
LOG.with(Default::default);
MANAGER.with(Default::default);
Expand All @@ -60,4 +67,18 @@ pub fn init() {
INPUT.with(Default::default);
SELECT.with(Default::default);
WHICH.with(Default::default);

// TODO: remove this once Yazi 0.3 is released --
if !HEADSUP.disable_exec_warn && DEPRECATED_EXEC.load(std::sync::atomic::Ordering::Relaxed) {
println!(
r#"
WARNING: `exec` will be deprecated in the next major version v0.3 and replaced by `run`.
Please replace all `exec = ...` with `run = ...`, in your `yazi.toml` and `keymap.toml`.
---
Add `disable_exec_warn = true` to your `yazi.toml` under `[headsup]` to suppress this warning.
"#
);
}
}
7 changes: 7 additions & 0 deletions yazi-config/src/open/opener.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::sync::atomic::Ordering;

use serde::{Deserialize, Deserializer};

use crate::DEPRECATED_EXEC;

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Opener {
pub run: String,
Expand Down Expand Up @@ -47,6 +51,9 @@ impl<'de> Deserialize<'de> for Opener {
let shadow = Shadow::deserialize(deserializer)?;

// TODO: remove this once Yazi 0.3 is released --
if shadow.exec.is_some() {
DEPRECATED_EXEC.store(true, Ordering::Relaxed);
}
let run = shadow.run.or(shadow.exec).unwrap_or_default();
// TODO: -- remove this once Yazi 0.3 is released

Expand Down
7 changes: 6 additions & 1 deletion yazi-config/src/plugin/rule.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::atomic::Ordering;

use serde::{Deserialize, Deserializer};
use yazi_shared::{event::Cmd, Condition};

use crate::{Pattern, Priority};
use crate::{Pattern, Priority, DEPRECATED_EXEC};

pub struct PluginRule {
pub id: u8,
Expand Down Expand Up @@ -50,6 +52,9 @@ impl<'de> Deserialize<'de> for PluginRule {
#[derive(Deserialize)]
struct WrappedCmd(#[serde(deserialize_with = "super::run_deserialize")] Cmd);

if shadow.exec.is_some() {
DEPRECATED_EXEC.store(true, Ordering::Relaxed);
}
let Some(run) = shadow.run.or(shadow.exec) else {
return Err(serde::de::Error::custom("missing field `run` within `[plugin]`"));
};
Expand Down
16 changes: 8 additions & 8 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.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <[email protected]>" ]
Expand All @@ -9,13 +9,13 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.3" }
yazi-boot = { path = "../yazi-boot", version = "0.2.3" }
yazi-config = { path = "../yazi-config", version = "0.2.3" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.3" }
yazi-proxy = { path = "../yazi-proxy", version = "0.2.3" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.3" }
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.4" }
yazi-boot = { path = "../yazi-boot", version = "0.2.4" }
yazi-config = { path = "../yazi-config", version = "0.2.4" }
yazi-plugin = { path = "../yazi-plugin", version = "0.2.4" }
yazi-proxy = { path = "../yazi-proxy", version = "0.2.4" }
yazi-scheduler = { path = "../yazi-scheduler", version = "0.2.4" }
yazi-shared = { path = "../yazi-shared", version = "0.2.4" }

# External dependencies
anyhow = "^1"
Expand Down

0 comments on commit 9396d87

Please sign in to comment.