diff --git a/Cargo.lock b/Cargo.lock index 28030fd8..d9d53dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -230,9 +230,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.3" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "bytemuck" @@ -269,9 +269,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -281,9 +281,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -293,9 +293,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -303,9 +303,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -2689,7 +2689,7 @@ dependencies = [ [[package]] name = "yazi-adaptor" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "arc-swap", @@ -2708,7 +2708,7 @@ dependencies = [ [[package]] name = "yazi-boot" -version = "0.2.3" +version = "0.2.4" dependencies = [ "clap", "clap_complete", @@ -2722,7 +2722,7 @@ dependencies = [ [[package]] name = "yazi-config" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "arc-swap", @@ -2741,7 +2741,7 @@ dependencies = [ [[package]] name = "yazi-core" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "base64 0.22.0", @@ -2772,7 +2772,7 @@ dependencies = [ [[package]] name = "yazi-fm" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "better-panic", @@ -2803,7 +2803,7 @@ dependencies = [ [[package]] name = "yazi-plugin" -version = "0.2.3" +version = "0.2.4" dependencies = [ "ansi-to-tui", "anyhow", @@ -2840,7 +2840,7 @@ checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632" [[package]] name = "yazi-proxy" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "mlua", @@ -2851,7 +2851,7 @@ dependencies = [ [[package]] name = "yazi-scheduler" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "async-priority-channel", @@ -2873,7 +2873,7 @@ dependencies = [ [[package]] name = "yazi-shared" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "bitflags 2.4.2", diff --git a/cspell.json b/cspell.json index b5bb36bf..559b3847 100644 --- a/cspell.json +++ b/cspell.json @@ -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"]} \ No newline at end of file +{"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"]} \ No newline at end of file diff --git a/yazi-adaptor/Cargo.toml b/yazi-adaptor/Cargo.toml index 911df9ee..ee6ab4f3 100644 --- a/yazi-adaptor/Cargo.toml +++ b/yazi-adaptor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-adaptor" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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" diff --git a/yazi-boot/Cargo.toml b/yazi-boot/Cargo.toml index 71854f4b..42c5b4c4 100644 --- a/yazi-boot/Cargo.toml +++ b/yazi-boot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-boot" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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" ] } diff --git a/yazi-config/Cargo.toml b/yazi-config/Cargo.toml index c4b47b04..5582bf93 100644 --- a/yazi-config/Cargo.toml +++ b/yazi-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-config" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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" diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index f47daae3..b860d825 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -192,3 +192,5 @@ sort_reverse = false [log] enabled = false + +[headsup] diff --git a/yazi-config/src/headsup/headsup.rs b/yazi-config/src/headsup/headsup.rs new file mode 100644 index 00000000..062725fa --- /dev/null +++ b/yazi-config/src/headsup/headsup.rs @@ -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(deserializer: D) -> Result + 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 }) + } +} diff --git a/yazi-config/src/headsup/mod.rs b/yazi-config/src/headsup/mod.rs new file mode 100644 index 00000000..82e85f0a --- /dev/null +++ b/yazi-config/src/headsup/mod.rs @@ -0,0 +1,3 @@ +mod headsup; + +pub use headsup::*; diff --git a/yazi-config/src/keymap/control.rs b/yazi-config/src/keymap/control.rs index 7b357b09..a236e5a0 100644 --- a/yazi-config/src/keymap/control.rs +++ b/yazi-config/src/keymap/control.rs @@ -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 { @@ -61,6 +62,9 @@ impl<'de> Deserialize<'de> for Control { #[derive(Deserialize)] struct VecCmd(#[serde(deserialize_with = "super::run_deserialize")] Vec); + 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]`")); }; diff --git a/yazi-config/src/lib.rs b/yazi-config/src/lib.rs index 117de23b..385ca369 100644 --- a/yazi-config/src/lib.rs +++ b/yazi-config/src/lib.rs @@ -2,6 +2,7 @@ use yazi_shared::{RoCell, Xdg}; +pub mod headsup; pub mod keymap; mod layout; mod log; @@ -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 = RoCell::new(); static MERGED_KEYMAP: RoCell = RoCell::new(); static MERGED_THEME: RoCell = RoCell::new(); pub static LAYOUT: RoCell> = RoCell::new(); +pub static HEADSUP: RoCell = RoCell::new(); pub static KEYMAP: RoCell = RoCell::new(); pub static LOG: RoCell = RoCell::new(); pub static MANAGER: RoCell = RoCell::new(); @@ -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); @@ -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. +"# + ); + } } diff --git a/yazi-config/src/open/opener.rs b/yazi-config/src/open/opener.rs index cb51db58..40409c7b 100644 --- a/yazi-config/src/open/opener.rs +++ b/yazi-config/src/open/opener.rs @@ -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, @@ -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 diff --git a/yazi-config/src/plugin/rule.rs b/yazi-config/src/plugin/rule.rs index e57027ef..b29f3f8e 100644 --- a/yazi-config/src/plugin/rule.rs +++ b/yazi-config/src/plugin/rule.rs @@ -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, @@ -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]`")); }; diff --git a/yazi-core/Cargo.toml b/yazi-core/Cargo.toml index c96dc59b..94eee563 100644 --- a/yazi-core/Cargo.toml +++ b/yazi-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-core" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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" diff --git a/yazi-core/src/manager/commands/bulk_rename.rs b/yazi-core/src/manager/commands/bulk_rename.rs index 8dca4fd6..ca4bf92b 100644 --- a/yazi-core/src/manager/commands/bulk_rename.rs +++ b/yazi-core/src/manager/commands/bulk_rename.rs @@ -4,8 +4,7 @@ use anyhow::{anyhow, Result}; use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}}; use yazi_config::{OPEN, PREVIEW}; use yazi_plugin::external::{self, ShellOpt}; -use yazi_proxy::AppProxy; -use yazi_scheduler::{HIDER, WATCHER}; +use yazi_proxy::{AppProxy, HIDER, WATCHER}; use yazi_shared::{fs::{accessible, max_common_root, File, FilesOp, Url}, term::Term, Defer}; use crate::manager::Manager; diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 385b4b2f..216dc522 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -3,8 +3,7 @@ use std::collections::HashMap; use anyhow::Result; use tokio::fs; use yazi_config::popup::InputCfg; -use yazi_proxy::{InputProxy, ManagerProxy}; -use yazi_scheduler::WATCHER; +use yazi_proxy::{InputProxy, ManagerProxy, WATCHER}; use yazi_shared::{event::Cmd, fs::{accessible, File, FilesOp, Url}}; use crate::manager::Manager; diff --git a/yazi-core/src/manager/watcher.rs b/yazi-core/src/manager/watcher.rs index f4e57def..e712e038 100644 --- a/yazi-core/src/manager/watcher.rs +++ b/yazi-core/src/manager/watcher.rs @@ -7,7 +7,7 @@ use tokio::{fs, pin, sync::mpsc::{self, UnboundedReceiver}}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tracing::error; use yazi_plugin::isolate; -use yazi_scheduler::WATCHER; +use yazi_proxy::WATCHER; use yazi_shared::fs::{File, FilesOp, Url}; use super::Linked; diff --git a/yazi-core/src/tab/commands/jump.rs b/yazi-core/src/tab/commands/jump.rs index 470c0317..cd0c73ea 100644 --- a/yazi-core/src/tab/commands/jump.rs +++ b/yazi-core/src/tab/commands/jump.rs @@ -1,6 +1,5 @@ use yazi_plugin::external::{self, FzfOpt, ZoxideOpt}; -use yazi_proxy::{AppProxy, TabProxy}; -use yazi_scheduler::HIDER; +use yazi_proxy::{AppProxy, TabProxy, HIDER}; use yazi_shared::{event::Cmd, fs::ends_with_slash, Defer}; use crate::tab::Tab; diff --git a/yazi-core/src/tasks/commands/inspect.rs b/yazi-core/src/tasks/commands/inspect.rs index e1e0ff5a..3d92c5e7 100644 --- a/yazi-core/src/tasks/commands/inspect.rs +++ b/yazi-core/src/tasks/commands/inspect.rs @@ -2,8 +2,7 @@ use std::io::{stdout, Write}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time}; -use yazi_proxy::AppProxy; -use yazi_scheduler::HIDER; +use yazi_proxy::{AppProxy, HIDER}; use yazi_shared::{event::Cmd, term::Term, Defer}; use crate::tasks::Tasks; diff --git a/yazi-fm/Cargo.toml b/yazi-fm/Cargo.toml index e95d31df..83214a82 100644 --- a/yazi-fm/Cargo.toml +++ b/yazi-fm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-fm" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,14 +9,14 @@ 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-core = { path = "../yazi-core", 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-core = { path = "../yazi-core", 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" diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index 95b72d1e..0b6e2c59 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -45,10 +45,10 @@ async fn main() -> anyhow::Result<()> { yazi_boot::init(); - yazi_scheduler::init(); - yazi_plugin::init(); + yazi_proxy::init(); + yazi_core::init(); app::App::serve().await diff --git a/yazi-fm/src/signals.rs b/yazi-fm/src/signals.rs index 214e6ee5..35933d63 100644 --- a/yazi-fm/src/signals.rs +++ b/yazi-fm/src/signals.rs @@ -43,8 +43,7 @@ impl Signals { #[cfg(unix)] fn spawn_system_task(&self) -> Result> { use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM}; - use yazi_proxy::AppProxy; - use yazi_scheduler::HIDER; + use yazi_proxy::{AppProxy, HIDER}; let mut signals = signal_hook_tokio::Signals::new([ // Terminating signals diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index 3168c6cf..1727184b 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-plugin" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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.3" } -yazi-boot = { path = "../yazi-boot", version = "0.2.3" } -yazi-config = { path = "../yazi-config", version = "0.2.3" } -yazi-proxy = { path = "../yazi-proxy", 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-proxy = { path = "../yazi-proxy", version = "0.2.4" } +yazi-shared = { path = "../yazi-shared", version = "0.2.4" } # External dependencies ansi-to-tui = "^3" diff --git a/yazi-plugin/src/bindings/mod.rs b/yazi-plugin/src/bindings/mod.rs index 57e87ef7..31f2ac4c 100644 --- a/yazi-plugin/src/bindings/mod.rs +++ b/yazi-plugin/src/bindings/mod.rs @@ -5,6 +5,7 @@ mod cha; mod file; mod icon; mod input; +mod permit; mod position; mod range; mod window; @@ -14,6 +15,7 @@ pub use cha::*; pub use file::*; pub use icon::*; pub use input::*; +pub use permit::*; pub use position::*; pub use range::*; pub use window::*; diff --git a/yazi-plugin/src/bindings/permit.rs b/yazi-plugin/src/bindings/permit.rs new file mode 100644 index 00000000..4dfb0b6a --- /dev/null +++ b/yazi-plugin/src/bindings/permit.rs @@ -0,0 +1,42 @@ +use std::{mem, ops::Deref}; + +use mlua::{prelude::LuaUserDataMethods, UserData}; +use tokio::sync::SemaphorePermit; + +pub type PermitRef<'lua, F> = mlua::UserDataRef<'lua, Permit>; + +pub struct Permit { + inner: Option>, + destruct: Option, +} + +impl Deref for Permit { + type Target = Option>; + + fn deref(&self) -> &Self::Target { &self.inner } +} + +impl Permit { + pub fn new(inner: SemaphorePermit<'static>, f: F) -> Self { + Self { inner: Some(inner), destruct: Some(f) } + } + + fn dropping(&mut self) { + if let Some(f) = self.destruct.take() { + f(); + } + if let Some(p) = self.inner.take() { + mem::drop(p); + } + } +} + +impl Drop for Permit { + fn drop(&mut self) { self.dropping(); } +} + +impl UserData for Permit { + fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_method_mut("drop", |_, me, ()| Ok(me.dropping())); + } +} diff --git a/yazi-plugin/src/lib.rs b/yazi-plugin/src/lib.rs index 0c1ffddf..00f88f2a 100644 --- a/yazi-plugin/src/lib.rs +++ b/yazi-plugin/src/lib.rs @@ -8,8 +8,8 @@ pub mod external; pub mod fs; pub mod isolate; mod loader; +mod lua; mod opt; -mod plugin; pub mod process; pub mod url; pub mod utils; @@ -17,5 +17,7 @@ pub mod utils; pub use cast::*; pub use config::*; pub use loader::*; +pub use lua::*; pub use opt::*; -pub use plugin::*; + +pub fn init() { crate::init_lua(); } diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs new file mode 100644 index 00000000..2a9bd1cb --- /dev/null +++ b/yazi-plugin/src/lua.rs @@ -0,0 +1,50 @@ +use anyhow::Result; +use mlua::Lua; +use yazi_boot::BOOT; +use yazi_shared::RoCell; + +pub static LUA: RoCell = RoCell::new(); + +pub(super) fn init_lua() { + let lua = Lua::new(); + stage_1(&lua).expect("failed to initialize Lua"); + stage_2(&lua); + LUA.init(lua); +} + +fn stage_1(lua: &Lua) -> Result<()> { + crate::Loader::init(); + crate::Config::new(lua).install_boot()?.install_manager()?.install_theme()?; + crate::utils::init(); + crate::utils::install(lua)?; + + // Base + lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?; + lua.load(include_str!("../preset/ya.lua")).exec()?; + crate::bindings::Cha::register(lua)?; + crate::bindings::File::register(lua)?; + crate::bindings::Icon::register(lua)?; + crate::elements::pour(lua)?; + crate::url::pour(lua)?; + + // Components + lua.load(include_str!("../preset/components/current.lua")).exec()?; + lua.load(include_str!("../preset/components/file.lua")).exec()?; + lua.load(include_str!("../preset/components/folder.lua")).exec()?; + lua.load(include_str!("../preset/components/header.lua")).exec()?; + lua.load(include_str!("../preset/components/manager.lua")).exec()?; + lua.load(include_str!("../preset/components/parent.lua")).exec()?; + lua.load(include_str!("../preset/components/preview.lua")).exec()?; + lua.load(include_str!("../preset/components/progress.lua")).exec()?; + lua.load(include_str!("../preset/components/status.lua")).exec()?; + + Ok(()) +} + +fn stage_2(lua: &Lua) { + lua.load(include_str!("../preset/setup.lua")).exec().unwrap(); + + if let Ok(b) = std::fs::read(BOOT.config_dir.join("init.lua")) { + lua.load(b).exec().unwrap(); + } +} diff --git a/yazi-plugin/src/plugin.rs b/yazi-plugin/src/plugin.rs deleted file mode 100644 index abc30719..00000000 --- a/yazi-plugin/src/plugin.rs +++ /dev/null @@ -1,50 +0,0 @@ -use anyhow::Result; -use mlua::Lua; -use yazi_boot::BOOT; -use yazi_shared::RoCell; - -pub static LUA: RoCell = RoCell::new(); - -pub fn init() { - fn stage_1(lua: &Lua) -> Result<()> { - crate::Loader::init(); - crate::Config::new(lua).install_boot()?.install_manager()?.install_theme()?; - crate::utils::init(); - crate::utils::install(lua)?; - - // Base - lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?; - lua.load(include_str!("../preset/ya.lua")).exec()?; - crate::bindings::Cha::register(lua)?; - crate::bindings::File::register(lua)?; - crate::bindings::Icon::register(lua)?; - crate::elements::pour(lua)?; - crate::url::pour(lua)?; - - // Components - lua.load(include_str!("../preset/components/current.lua")).exec()?; - lua.load(include_str!("../preset/components/file.lua")).exec()?; - lua.load(include_str!("../preset/components/folder.lua")).exec()?; - lua.load(include_str!("../preset/components/header.lua")).exec()?; - lua.load(include_str!("../preset/components/manager.lua")).exec()?; - lua.load(include_str!("../preset/components/parent.lua")).exec()?; - lua.load(include_str!("../preset/components/preview.lua")).exec()?; - lua.load(include_str!("../preset/components/progress.lua")).exec()?; - lua.load(include_str!("../preset/components/status.lua")).exec()?; - - Ok(()) - } - - fn stage_2(lua: &Lua) { - lua.load(include_str!("../preset/setup.lua")).exec().unwrap(); - - if let Ok(b) = std::fs::read(BOOT.config_dir.join("init.lua")) { - lua.load(b).exec().unwrap(); - } - } - - let lua = Lua::new(); - stage_1(&lua).expect("failed to initialize Lua"); - stage_2(&lua); - LUA.init(lua); -} diff --git a/yazi-plugin/src/utils/app.rs b/yazi-plugin/src/utils/app.rs new file mode 100644 index 00000000..e9f2db29 --- /dev/null +++ b/yazi-plugin/src/utils/app.rs @@ -0,0 +1,27 @@ +use mlua::{AnyUserData, ExternalError, Lua, Table}; +use yazi_proxy::{AppProxy, HIDER}; + +use super::Utils; +use crate::bindings::{Permit, PermitRef}; + +impl Utils { + pub(super) fn app(lua: &Lua, ya: &Table) -> mlua::Result<()> { + ya.raw_set( + "hide", + lua.create_async_function(|lua, ()| async move { + if lua.named_registry_value::>("HIDE_PERMIT").is_ok_and(|h| h.is_some()) { + return Err("Cannot hide while already hidden".into_lua_err()); + } + + let permit = HIDER.acquire().await.unwrap(); + AppProxy::stop().await; + + lua + .set_named_registry_value("HIDE_PERMIT", Permit::new(permit, AppProxy::resume as fn()))?; + lua.named_registry_value::("HIDE_PERMIT") + })?, + )?; + + Ok(()) + } +} diff --git a/yazi-plugin/src/utils/mod.rs b/yazi-plugin/src/utils/mod.rs index f5906355..e75695eb 100644 --- a/yazi-plugin/src/utils/mod.rs +++ b/yazi-plugin/src/utils/mod.rs @@ -1,5 +1,6 @@ #![allow(clippy::module_inception)] +mod app; mod cache; mod call; mod image; diff --git a/yazi-plugin/src/utils/plugin.rs b/yazi-plugin/src/utils/plugin.rs index e65ef7e2..95cd5fa3 100644 --- a/yazi-plugin/src/utils/plugin.rs +++ b/yazi-plugin/src/utils/plugin.rs @@ -12,7 +12,7 @@ impl Utils { lua.create_async_function( |_, (name, calls, args): (String, usize, Variadic)| async move { let args = ValueSendable::try_from_variadic(args)?; - let (tx, rx) = oneshot::channel::(); + let (tx, rx) = oneshot::channel::>(); let data = OptData { cb: Some({ @@ -27,9 +27,9 @@ impl Utils { self_args.push(arg.into_lua(lua)?); } - let value: ValueSendable = - block.call::<_, Value>(Variadic::from_iter(self_args))?.try_into()?; - tx.send(value).map_err(|_| "send failed".into_lua_err()) + let values = + ValueSendable::try_from_variadic(block.call(Variadic::from_iter(self_args))?)?; + tx.send(values).map_err(|_| "send failed".into_lua_err()) }) }), ..Default::default() @@ -40,8 +40,9 @@ impl Utils { Layer::App )); - rx.await - .map_err(|_| format!("Failed to execute sync block in `{name}` plugin").into_lua_err()) + Ok(Variadic::from_iter(rx.await.map_err(|_| { + format!("Failed to execute sync block-{calls} in `{name}` plugin").into_lua_err() + })?)) }, )?, )?; diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index a9be944a..75850015 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -8,6 +8,7 @@ pub(super) struct Utils; pub fn install(lua: &mlua::Lua) -> mlua::Result<()> { let ya: mlua::Table = lua.create_table()?; + Utils::app(lua, &ya)?; Utils::cache(lua, &ya)?; Utils::call(lua, &ya)?; Utils::image(lua, &ya)?; diff --git a/yazi-proxy/Cargo.toml b/yazi-proxy/Cargo.toml index 8fbc3400..63149a55 100644 --- a/yazi-proxy/Cargo.toml +++ b/yazi-proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-proxy" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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" diff --git a/yazi-proxy/src/lib.rs b/yazi-proxy/src/lib.rs index 8d60381d..6a0687fe 100644 --- a/yazi-proxy/src/lib.rs +++ b/yazi-proxy/src/lib.rs @@ -4,6 +4,7 @@ mod input; mod manager; pub mod options; mod select; +mod semaphore; mod tab; mod tasks; @@ -12,5 +13,8 @@ pub use completion::*; pub use input::*; pub use manager::*; pub use select::*; +pub use semaphore::*; pub use tab::*; pub use tasks::*; + +pub fn init() { crate::init_semaphore(); } diff --git a/yazi-scheduler/src/semaphore.rs b/yazi-proxy/src/semaphore.rs similarity index 100% rename from yazi-scheduler/src/semaphore.rs rename to yazi-proxy/src/semaphore.rs diff --git a/yazi-scheduler/Cargo.toml b/yazi-scheduler/Cargo.toml index e6488457..7c760a29 100644 --- a/yazi-scheduler/Cargo.toml +++ b/yazi-scheduler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-scheduler" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -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.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-shared = { path = "../yazi-shared", version = "0.2.3" } +yazi-adaptor = { path = "../yazi-adaptor", 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-shared = { path = "../yazi-shared", version = "0.2.4" } # External dependencies anyhow = "^1" diff --git a/yazi-scheduler/src/lib.rs b/yazi-scheduler/src/lib.rs index 1d74cb35..f744e551 100644 --- a/yazi-scheduler/src/lib.rs +++ b/yazi-scheduler/src/lib.rs @@ -7,17 +7,13 @@ mod plugin; mod preload; mod process; mod scheduler; -mod semaphore; mod task; pub use ongoing::*; pub use op::*; pub use scheduler::*; -pub use semaphore::*; pub use task::*; const LOW: u8 = yazi_config::Priority::Low as u8; const NORMAL: u8 = yazi_config::Priority::Normal as u8; const HIGH: u8 = yazi_config::Priority::High as u8; - -pub fn init() { init_semaphore(); } diff --git a/yazi-scheduler/src/process/process.rs b/yazi-scheduler/src/process/process.rs index 02e26aa6..e1b0e930 100644 --- a/yazi-scheduler/src/process/process.rs +++ b/yazi-scheduler/src/process/process.rs @@ -1,11 +1,11 @@ use anyhow::Result; use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::mpsc}; use yazi_plugin::external::{self, ShellOpt}; -use yazi_proxy::AppProxy; +use yazi_proxy::{AppProxy, HIDER}; use yazi_shared::Defer; use super::ProcessOpOpen; -use crate::{TaskProg, HIDER}; +use crate::TaskProg; pub struct Process { prog: mpsc::UnboundedSender, diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 52df8e0d..f40da216 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-shared" -version = "0.2.3" +version = "0.2.4" edition = "2021" license = "MIT" authors = [ "sxyazi " ]