mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: ya.input() plugin API
This commit is contained in:
parent
b39b506e27
commit
b71bd8a30e
17 changed files with 89 additions and 30 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -2740,6 +2740,7 @@ dependencies = [
|
||||||
"yazi-boot",
|
"yazi-boot",
|
||||||
"yazi-config",
|
"yazi-config",
|
||||||
"yazi-plugin",
|
"yazi-plugin",
|
||||||
|
"yazi-proxy",
|
||||||
"yazi-scheduler",
|
"yazi-scheduler",
|
||||||
"yazi-shared",
|
"yazi-shared",
|
||||||
]
|
]
|
||||||
|
|
@ -2770,6 +2771,7 @@ dependencies = [
|
||||||
"yazi-config",
|
"yazi-config",
|
||||||
"yazi-core",
|
"yazi-core",
|
||||||
"yazi-plugin",
|
"yazi-plugin",
|
||||||
|
"yazi-proxy",
|
||||||
"yazi-scheduler",
|
"yazi-scheduler",
|
||||||
"yazi-shared",
|
"yazi-shared",
|
||||||
]
|
]
|
||||||
|
|
@ -2810,6 +2812,15 @@ version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632"
|
checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yazi-proxy"
|
||||||
|
version = "0.2.3"
|
||||||
|
dependencies = [
|
||||||
|
"tokio",
|
||||||
|
"yazi-config",
|
||||||
|
"yazi-shared",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yazi-scheduler"
|
name = "yazi-scheduler"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
|
@ -2828,6 +2839,7 @@ dependencies = [
|
||||||
"yazi-adaptor",
|
"yazi-adaptor",
|
||||||
"yazi-config",
|
"yazi-config",
|
||||||
"yazi-plugin",
|
"yazi-plugin",
|
||||||
|
"yazi-proxy",
|
||||||
"yazi-shared",
|
"yazi-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.3" }
|
||||||
yazi-boot = { path = "../yazi-boot", version = "0.2.3" }
|
yazi-boot = { path = "../yazi-boot", version = "0.2.3" }
|
||||||
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
||||||
yazi-plugin = { path = "../yazi-plugin", 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-scheduler = { path = "../yazi-scheduler", version = "0.2.3" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
|
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ impl Manager {
|
||||||
|
|
||||||
let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]);
|
let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]);
|
||||||
for u in selected {
|
for u in selected {
|
||||||
if self.mimetype.get(u).is_some() {
|
if self.mimetype.contains_key(u) {
|
||||||
done.push((u.clone(), String::new()));
|
done.push((u.clone(), String::new()));
|
||||||
} else if self.guess_folder(u) {
|
} else if self.guess_folder(u) {
|
||||||
done.push((u.clone(), MIME_DIR.to_owned()));
|
done.push((u.clone(), MIME_DIR.to_owned()));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ use anyhow::{anyhow, bail, Result};
|
||||||
use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
||||||
use yazi_config::{popup::InputCfg, OPEN, PREVIEW};
|
use yazi_config::{popup::InputCfg, OPEN, PREVIEW};
|
||||||
use yazi_plugin::external::{self, ShellOpt};
|
use yazi_plugin::external::{self, ShellOpt};
|
||||||
use yazi_scheduler::{Scheduler, BLOCKER};
|
use yazi_proxy::App;
|
||||||
|
use yazi_scheduler::BLOCKER;
|
||||||
use yazi_shared::{event::Cmd, fs::{max_common_root, File, FilesOp, Url}, term::Term, Defer};
|
use yazi_shared::{event::Cmd, fs::{max_common_root, File, FilesOp, Url}, term::Term, Defer};
|
||||||
|
|
||||||
use crate::{input::Input, manager::Manager};
|
use crate::{input::Input, manager::Manager};
|
||||||
|
|
@ -122,10 +123,10 @@ impl Manager {
|
||||||
|
|
||||||
let _guard = BLOCKER.acquire().await.unwrap();
|
let _guard = BLOCKER.acquire().await.unwrap();
|
||||||
let _defer = Defer::new(|| {
|
let _defer = Defer::new(|| {
|
||||||
Scheduler::app_resume();
|
App::resume();
|
||||||
tokio::spawn(fs::remove_file(tmp.clone()))
|
tokio::spawn(fs::remove_file(tmp.clone()))
|
||||||
});
|
});
|
||||||
Scheduler::app_stop().await;
|
App::stop().await;
|
||||||
|
|
||||||
let mut child = external::shell(ShellOpt {
|
let mut child = external::shell(ShellOpt {
|
||||||
cmd: (*opener.exec).into(),
|
cmd: (*opener.exec).into(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_scheduler::Scheduler;
|
use yazi_proxy::App;
|
||||||
use yazi_shared::event::Cmd;
|
use yazi_shared::event::Cmd;
|
||||||
|
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
@ -7,7 +7,7 @@ impl Manager {
|
||||||
pub fn suspend(&mut self, _: Cmd) {
|
pub fn suspend(&mut self, _: Cmd) {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
Scheduler::app_stop().await;
|
App::stop().await;
|
||||||
unsafe { libc::raise(libc::SIGTSTP) };
|
unsafe { libc::raise(libc::SIGTSTP) };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use yazi_plugin::external::{self, FzfOpt, ZoxideOpt};
|
use yazi_plugin::external::{self, FzfOpt, ZoxideOpt};
|
||||||
use yazi_scheduler::{Scheduler, BLOCKER};
|
use yazi_proxy::App;
|
||||||
|
use yazi_scheduler::BLOCKER;
|
||||||
use yazi_shared::{event::Cmd, fs::ends_with_slash, Defer};
|
use yazi_shared::{event::Cmd, fs::ends_with_slash, Defer};
|
||||||
|
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
@ -37,8 +38,8 @@ impl Tab {
|
||||||
let cwd = self.current.cwd.clone();
|
let cwd = self.current.cwd.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let _guard = BLOCKER.acquire().await.unwrap();
|
let _guard = BLOCKER.acquire().await.unwrap();
|
||||||
let _defer = Defer::new(Scheduler::app_resume);
|
let _defer = Defer::new(App::resume);
|
||||||
Scheduler::app_stop().await;
|
App::stop().await;
|
||||||
|
|
||||||
let result = if opt.type_ == OptType::Fzf {
|
let result = if opt.type_ == OptType::Fzf {
|
||||||
external::fzf(FzfOpt { cwd }).await
|
external::fzf(FzfOpt { cwd }).await
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ use std::io::{stdout, Write};
|
||||||
|
|
||||||
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
||||||
use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time};
|
use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time};
|
||||||
use yazi_scheduler::{Scheduler, BLOCKER};
|
use yazi_proxy::App;
|
||||||
|
use yazi_scheduler::BLOCKER;
|
||||||
use yazi_shared::{event::Cmd, term::Term, Defer};
|
use yazi_shared::{event::Cmd, term::Term, Defer};
|
||||||
|
|
||||||
use crate::tasks::Tasks;
|
use crate::tasks::Tasks;
|
||||||
|
|
@ -26,10 +27,10 @@ impl Tasks {
|
||||||
task.logs.clone()
|
task.logs.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
Scheduler::app_stop().await;
|
App::stop().await;
|
||||||
let _defer = Defer::new(|| {
|
let _defer = Defer::new(|| {
|
||||||
disable_raw_mode().ok();
|
disable_raw_mode().ok();
|
||||||
Scheduler::app_resume();
|
App::resume();
|
||||||
});
|
});
|
||||||
|
|
||||||
Term::clear(&mut stdout()).ok();
|
Term::clear(&mut stdout()).ok();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ yazi-boot = { path = "../yazi-boot", version = "0.2.3" }
|
||||||
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
||||||
yazi-core = { path = "../yazi-core", version = "0.2.3" }
|
yazi-core = { path = "../yazi-core", version = "0.2.3" }
|
||||||
yazi-plugin = { path = "../yazi-plugin", 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-scheduler = { path = "../yazi-scheduler", version = "0.2.3" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
|
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
|
|
||||||
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
|
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
|
||||||
Line::styled(
|
Line::styled(
|
||||||
help.keyword().unwrap_or_else(|| format!("{}.help", help.layer.to_string())),
|
help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)),
|
||||||
THEME.help.footer,
|
THEME.help.footer,
|
||||||
)
|
)
|
||||||
.render(chunks[1], buf);
|
.render(chunks[1], buf);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ impl Signals {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
|
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
|
||||||
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
||||||
use yazi_scheduler::{Scheduler, BLOCKER};
|
use yazi_scheduler::BLOCKER;
|
||||||
|
|
||||||
let mut signals = signal_hook_tokio::Signals::new([
|
let mut signals = signal_hook_tokio::Signals::new([
|
||||||
// Terminating signals
|
// Terminating signals
|
||||||
|
|
@ -65,7 +65,7 @@ impl Signals {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SIGCONT => Scheduler::app_resume(),
|
SIGCONT => yazi_proxy::App::resume(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,21 @@ impl Utils {
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
ya.raw_set(
|
||||||
|
"input",
|
||||||
|
lua.create_async_function(|_, t: Table| async move {
|
||||||
|
// pub title: String,
|
||||||
|
// pub value: String,
|
||||||
|
// pub cursor: Option<usize>,
|
||||||
|
// pub position: Position,
|
||||||
|
// pub realtime: bool,
|
||||||
|
// pub completion: bool,
|
||||||
|
// pub highlight: bool,
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
yazi-proxy/Cargo.toml
Normal file
16
yazi-proxy/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "yazi-proxy"
|
||||||
|
version = "0.2.3"
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
authors = [ "sxyazi <sxyazi@gmail.com>" ]
|
||||||
|
description = "Yazi event proxy"
|
||||||
|
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" }
|
||||||
|
|
||||||
|
# External dependencies
|
||||||
|
tokio = { version = "^1", features = [ "parking_lot" ] }
|
||||||
16
yazi-proxy/src/app.rs
Normal file
16
yazi-proxy/src/app.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use tokio::sync::oneshot;
|
||||||
|
use yazi_shared::{emit, event::Cmd, Layer};
|
||||||
|
|
||||||
|
pub struct App;
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub async fn stop() {
|
||||||
|
let (tx, rx) = oneshot::channel::<()>();
|
||||||
|
emit!(Call(Cmd::new("stop").with_data(tx), Layer::App));
|
||||||
|
rx.await.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resume() {
|
||||||
|
emit!(Call(Cmd::new("resume"), Layer::App));
|
||||||
|
}
|
||||||
|
}
|
||||||
3
yazi-proxy/src/lib.rs
Normal file
3
yazi-proxy/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod app;
|
||||||
|
|
||||||
|
pub use app::*;
|
||||||
|
|
@ -11,8 +11,9 @@ repository = "https://github.com/sxyazi/yazi"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.3" }
|
yazi-adaptor = { path = "../yazi-adaptor", version = "0.2.3" }
|
||||||
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
yazi-config = { path = "../yazi-config", version = "0.2.3" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "0.2.3" }
|
|
||||||
yazi-plugin = { path = "../yazi-plugin", 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" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
anyhow = "^1"
|
anyhow = "^1"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::mpsc};
|
use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::mpsc};
|
||||||
use yazi_plugin::external::{self, ShellOpt};
|
use yazi_plugin::external::{self, ShellOpt};
|
||||||
|
use yazi_proxy::App;
|
||||||
|
|
||||||
use super::ProcessOpOpen;
|
use super::ProcessOpOpen;
|
||||||
use crate::{Scheduler, TaskProg, BLOCKER};
|
use crate::{TaskProg, BLOCKER};
|
||||||
|
|
||||||
pub struct Process {
|
pub struct Process {
|
||||||
prog: mpsc::UnboundedSender<TaskProg>,
|
prog: mpsc::UnboundedSender<TaskProg>,
|
||||||
|
|
@ -16,7 +17,7 @@ impl Process {
|
||||||
let opt = ShellOpt::from(&mut task);
|
let opt = ShellOpt::from(&mut task);
|
||||||
if task.block {
|
if task.block {
|
||||||
let _guard = BLOCKER.acquire().await.unwrap();
|
let _guard = BLOCKER.acquire().await.unwrap();
|
||||||
Scheduler::app_stop().await;
|
App::stop().await;
|
||||||
|
|
||||||
match external::shell(opt) {
|
match external::shell(opt) {
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
|
|
@ -28,7 +29,7 @@ impl Process {
|
||||||
self.fail(task.id, format!("Failed to spawn process: {e}"))?;
|
self.fail(task.id, format!("Failed to spawn process: {e}"))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(Scheduler::app_resume());
|
return Ok(App::resume());
|
||||||
}
|
}
|
||||||
|
|
||||||
if task.orphan {
|
if task.orphan {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use parking_lot::Mutex;
|
||||||
use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}};
|
use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}};
|
||||||
use yazi_config::{open::Opener, plugin::PluginRule, TASKS};
|
use yazi_config::{open::Opener, plugin::PluginRule, TASKS};
|
||||||
use yazi_plugin::ValueSendable;
|
use yazi_plugin::ValueSendable;
|
||||||
use yazi_shared::{emit, event::Cmd, fs::{unique_path, Url}, Layer, Throttle};
|
use yazi_shared::{fs::{unique_path, Url}, Throttle};
|
||||||
|
|
||||||
use super::{Running, TaskProg, TaskStage};
|
use super::{Running, TaskProg, TaskStage};
|
||||||
use crate::{file::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash}, plugin::{Plugin, PluginOpEntry}, preload::{Preload, PreloadOpRule, PreloadOpSize}, process::{Process, ProcessOpOpen}, TaskKind, TaskOp, HIGH, LOW, NORMAL};
|
use crate::{file::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash}, plugin::{Plugin, PluginOpEntry}, preload::{Preload, PreloadOpRule, PreloadOpSize}, process::{Process, ProcessOpOpen}, TaskKind, TaskOp, HIGH, LOW, NORMAL};
|
||||||
|
|
@ -163,16 +163,6 @@ impl Scheduler {
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn app_stop() {
|
|
||||||
let (tx, rx) = oneshot::channel::<()>();
|
|
||||||
emit!(Call(Cmd::new("stop").with_data(tx), Layer::App));
|
|
||||||
rx.await.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn app_resume() {
|
|
||||||
emit!(Call(Cmd::new("resume"), Layer::App));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_cut(&self, from: Url, mut to: Url, force: bool) {
|
pub fn file_cut(&self, from: Url, mut to: Url, force: bool) {
|
||||||
let mut running = self.running.lock();
|
let mut running = self.running.lock();
|
||||||
let id = running.add(TaskKind::User, format!("Cut {:?} to {:?}", from, to));
|
let id = running.add(TaskKind::User, format!("Cut {:?} to {:?}", from, to));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue