mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
3ec0d45be7
commit
9e4c70138c
9 changed files with 66 additions and 24 deletions
|
|
@ -84,7 +84,7 @@ impl Manager {
|
||||||
if targets.is_empty() {
|
if targets.is_empty() {
|
||||||
return;
|
return;
|
||||||
} else if !opt.interactive {
|
} else if !opt.interactive {
|
||||||
return tasks.file_open(&opt.hovered, &targets);
|
return tasks.process_from_files(&opt.hovered, &targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
let openers: Vec<_> = OPEN.common_openers(&targets).into_iter().cloned().collect();
|
let openers: Vec<_> = OPEN.common_openers(&targets).into_iter().cloned().collect();
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@ mod arrow;
|
||||||
mod cancel;
|
mod cancel;
|
||||||
mod inspect;
|
mod inspect;
|
||||||
mod open_with;
|
mod open_with;
|
||||||
|
mod process_exec;
|
||||||
mod toggle;
|
mod toggle;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::tasks::Tasks;
|
||||||
impl Tasks {
|
impl Tasks {
|
||||||
pub fn open_with(&mut self, opt: impl TryInto<OpenWithOpt>) {
|
pub fn open_with(&mut self, opt: impl TryInto<OpenWithOpt>) {
|
||||||
if let Ok(opt) = opt.try_into() {
|
if let Ok(opt) = opt.try_into() {
|
||||||
self.file_open_with(&opt.opener, &opt.targets);
|
self.process_from_opener(&opt.opener, &opt.targets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
yazi-core/src/tasks/commands/process_exec.rs
Normal file
12
yazi-core/src/tasks/commands/process_exec.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
use yazi_proxy::options::ProcessExecOpt;
|
||||||
|
|
||||||
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
|
impl Tasks {
|
||||||
|
pub fn process_exec(&mut self, opt: impl TryInto<ProcessExecOpt>) {
|
||||||
|
if let Ok(opt) = opt.try_into() {
|
||||||
|
// FIXME
|
||||||
|
// self.process_from_opener(&opt.opener, &opt.targets);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
|
mod process;
|
||||||
mod progress;
|
mod progress;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
|
|
||||||
|
|
|
||||||
30
yazi-core/src/tasks/process.rs
Normal file
30
yazi-core/src/tasks/process.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
use std::{collections::HashMap, ffi::OsStr};
|
||||||
|
|
||||||
|
use yazi_config::{open::Opener, OPEN};
|
||||||
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
|
use super::Tasks;
|
||||||
|
|
||||||
|
impl Tasks {
|
||||||
|
pub fn process_from_files(&self, hovered: &Url, targets: &[(Url, String)]) {
|
||||||
|
let mut openers = HashMap::new();
|
||||||
|
for (url, mime) in targets {
|
||||||
|
if let Some(opener) = OPEN.openers(url, mime).and_then(|o| o.first().copied()) {
|
||||||
|
openers.entry(opener).or_insert_with(|| vec![hovered]).push(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (opener, args) in openers {
|
||||||
|
self.process_from_opener(opener, &args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_from_opener(&self, opener: &Opener, args: &[impl AsRef<OsStr>]) {
|
||||||
|
if opener.spread {
|
||||||
|
self.scheduler.process_open(opener, args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for target in args.iter().skip(1) {
|
||||||
|
self.scheduler.process_open(opener, &[&args[0], target]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -56,28 +56,6 @@ impl Tasks {
|
||||||
ongoing.values().take(Self::limit()).map(Into::into).collect()
|
ongoing.values().take(Self::limit()).map(Into::into).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_open(&self, hovered: &Url, targets: &[(Url, String)]) {
|
|
||||||
let mut openers = HashMap::new();
|
|
||||||
for (url, mime) in targets {
|
|
||||||
if let Some(opener) = OPEN.openers(url, mime).and_then(|o| o.first().copied()) {
|
|
||||||
openers.entry(opener).or_insert_with(|| vec![hovered]).push(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (opener, args) in openers {
|
|
||||||
self.file_open_with(opener, &args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_open_with(&self, opener: &Opener, args: &[impl AsRef<OsStr>]) {
|
|
||||||
if opener.spread {
|
|
||||||
self.scheduler.process_open(opener, args);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for target in args.iter().skip(1) {
|
|
||||||
self.scheduler.process_open(opener, &[&args[0], target]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_cut(&self, src: &[&Url], dest: &Url, force: bool) {
|
pub fn file_cut(&self, src: &[&Url], dest: &Url, force: bool) {
|
||||||
for &u in src {
|
for &u in src {
|
||||||
let to = dest.join(u.file_name().unwrap());
|
let to = dest.join(u.file_name().unwrap());
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
mod input;
|
mod input;
|
||||||
mod notify;
|
mod notify;
|
||||||
mod open;
|
mod open;
|
||||||
|
mod process;
|
||||||
mod select;
|
mod select;
|
||||||
|
|
||||||
pub use input::*;
|
pub use input::*;
|
||||||
pub use notify::*;
|
pub use notify::*;
|
||||||
pub use open::*;
|
pub use open::*;
|
||||||
|
pub use process::*;
|
||||||
pub use select::*;
|
pub use select::*;
|
||||||
|
|
|
||||||
18
yazi-proxy/src/options/process.rs
Normal file
18
yazi-proxy/src/options/process.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
use std::ffi::OsString;
|
||||||
|
|
||||||
|
use yazi_shared::event::Cmd;
|
||||||
|
|
||||||
|
// --- Exec
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct ProcessExecOpt {
|
||||||
|
pub cmd: OsString,
|
||||||
|
pub args: Vec<OsString>,
|
||||||
|
pub block: bool,
|
||||||
|
pub orphan: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<Cmd> for ProcessExecOpt {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(mut c: Cmd) -> Result<Self, Self::Error> { c.take_data().ok_or(()) }
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue