feat: ya.hide() plugin API (#792)

This commit is contained in:
三咲雅 · Misaki Masa 2024-03-09 03:07:20 +08:00 committed by GitHub
parent 3f80bc56a6
commit 9396d8760c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 287 additions and 140 deletions

38
Cargo.lock generated
View file

@ -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",

View file

@ -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"]}

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-adaptor"
version = "0.2.3"
version = "0.2.4"
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.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"

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-boot"
version = "0.2.3"
version = "0.2.4"
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.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" ] }

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-config"
version = "0.2.3"
version = "0.2.4"
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.3" }
yazi-shared = { path = "../yazi-shared", version = "0.2.4" }
# External dependencies
anyhow = "^1"

View file

@ -192,3 +192,5 @@ sort_reverse = false
[log]
enabled = false
[headsup]

View file

@ -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 })
}
}

View file

@ -0,0 +1,3 @@
mod headsup;
pub use headsup::*;

View file

@ -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<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]`"));
};

View file

@ -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<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();
@ -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.
"#
);
}
}

View file

@ -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

View file

@ -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]`"));
};

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-core"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@ -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"

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-fm"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@ -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"

View file

@ -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

View file

@ -43,8 +43,7 @@ impl Signals {
#[cfg(unix)]
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
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

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-plugin"
version = "0.2.3"
version = "0.2.4"
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.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"

View file

@ -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::*;

View file

@ -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<F>>;
pub struct Permit<F: FnOnce()> {
inner: Option<SemaphorePermit<'static>>,
destruct: Option<F>,
}
impl<F: FnOnce()> Deref for Permit<F> {
type Target = Option<SemaphorePermit<'static>>;
fn deref(&self) -> &Self::Target { &self.inner }
}
impl<F: FnOnce()> Permit<F> {
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<F: FnOnce()> Drop for Permit<F> {
fn drop(&mut self) { self.dropping(); }
}
impl<F: FnOnce()> UserData for Permit<F> {
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method_mut("drop", |_, me, ()| Ok(me.dropping()));
}
}

View file

@ -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(); }

50
yazi-plugin/src/lua.rs Normal file
View file

@ -0,0 +1,50 @@
use anyhow::Result;
use mlua::Lua;
use yazi_boot::BOOT;
use yazi_shared::RoCell;
pub static LUA: RoCell<Lua> = 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();
}
}

View file

@ -1,50 +0,0 @@
use anyhow::Result;
use mlua::Lua;
use yazi_boot::BOOT;
use yazi_shared::RoCell;
pub static LUA: RoCell<Lua> = 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);
}

View file

@ -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::<PermitRef<fn()>>("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::<AnyUserData>("HIDE_PERMIT")
})?,
)?;
Ok(())
}
}

View file

@ -1,5 +1,6 @@
#![allow(clippy::module_inception)]
mod app;
mod cache;
mod call;
mod image;

View file

@ -12,7 +12,7 @@ impl Utils {
lua.create_async_function(
|_, (name, calls, args): (String, usize, Variadic<Value>)| async move {
let args = ValueSendable::try_from_variadic(args)?;
let (tx, rx) = oneshot::channel::<ValueSendable>();
let (tx, rx) = oneshot::channel::<Vec<ValueSendable>>();
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()
})?))
},
)?,
)?;

View file

@ -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)?;

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-proxy"
version = "0.2.3"
version = "0.2.4"
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.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"

View file

@ -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(); }

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-scheduler"
version = "0.2.3"
version = "0.2.4"
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.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"

View file

@ -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(); }

View file

@ -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<TaskProg>,

View file

@ -1,6 +1,6 @@
[package]
name = "yazi-shared"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
authors = [ "sxyazi <sxyazi@gmail.com>" ]