mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
0a594302a4
commit
dee464d261
71 changed files with 173 additions and 174 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use super::{Exec, Key};
|
use super::Key;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Control {
|
pub struct Control {
|
||||||
pub on: Vec<Key>,
|
pub on: Vec<Key>,
|
||||||
#[serde(deserialize_with = "Exec::deserialize")]
|
#[serde(deserialize_with = "super::exec_deserialize")]
|
||||||
pub exec: Vec<Exec>,
|
pub exec: Vec<Exec>,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,22 @@
|
||||||
use std::{any::Any, collections::BTreeMap, fmt::{self, Debug, Display}};
|
use std::fmt;
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::{bail, Result};
|
||||||
use serde::{de::{self, Visitor}, Deserializer};
|
use serde::{de::{self, Visitor}, Deserializer};
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result<Vec<Exec>, D::Error>
|
||||||
pub struct Exec {
|
where
|
||||||
pub cmd: String,
|
D: Deserializer<'de>,
|
||||||
pub args: Vec<String>,
|
{
|
||||||
pub named: BTreeMap<String, String>,
|
struct ExecVisitor;
|
||||||
pub data: Option<Box<dyn Any + Send>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&str> for Exec {
|
fn parse(s: &str) -> Result<Exec> {
|
||||||
type Error = anyhow::Error;
|
|
||||||
|
|
||||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
|
||||||
let s = shell_words::split(s)?;
|
let s = shell_words::split(s)?;
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
bail!("`exec` cannot be empty");
|
bail!("`exec` cannot be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut exec = Self { cmd: s[0].clone(), ..Default::default() };
|
let mut exec = Exec { cmd: s[0].clone(), ..Default::default() };
|
||||||
for arg in s.into_iter().skip(1) {
|
for arg in s.into_iter().skip(1) {
|
||||||
if arg.starts_with("--") {
|
if arg.starts_with("--") {
|
||||||
let mut arg = arg.splitn(2, '=');
|
let mut arg = arg.splitn(2, '=');
|
||||||
|
|
@ -33,36 +29,12 @@ impl TryFrom<&str> for Exec {
|
||||||
}
|
}
|
||||||
Ok(exec)
|
Ok(exec)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Exec {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.cmd)?;
|
|
||||||
if !self.args.is_empty() {
|
|
||||||
write!(f, " {}", self.args.join(" "))?;
|
|
||||||
}
|
|
||||||
for (k, v) in &self.named {
|
|
||||||
write!(f, " --{k}")?;
|
|
||||||
if !v.is_empty() {
|
|
||||||
write!(f, "={v}")?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Exec {
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Exec>, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct ExecVisitor;
|
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for ExecVisitor {
|
impl<'de> Visitor<'de> for ExecVisitor {
|
||||||
type Value = Vec<Exec>;
|
type Value = Vec<Exec>;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
formatter.write_str("a exec string, e.g. tab_switch 0")
|
formatter.write_str("a exec string, e.g. `tab_switch 0`")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
|
|
@ -71,7 +43,7 @@ impl Exec {
|
||||||
{
|
{
|
||||||
let mut execs = Vec::new();
|
let mut execs = Vec::new();
|
||||||
while let Some(value) = &seq.next_element::<String>()? {
|
while let Some(value) = &seq.next_element::<String>()? {
|
||||||
execs.push(Exec::try_from(value.as_str()).map_err(de::Error::custom)?);
|
execs.push(parse(value).map_err(de::Error::custom)?);
|
||||||
}
|
}
|
||||||
Ok(execs)
|
Ok(execs)
|
||||||
}
|
}
|
||||||
|
|
@ -80,39 +52,9 @@ impl Exec {
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
Ok(vec![Exec::try_from(value).map_err(de::Error::custom)?])
|
Ok(vec![parse(value).map_err(de::Error::custom)?])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializer.deserialize_any(ExecVisitor)
|
deserializer.deserialize_any(ExecVisitor)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Exec {
|
|
||||||
#[inline]
|
|
||||||
pub fn call(cwd: &str, args: Vec<String>) -> Self {
|
|
||||||
Exec { cmd: cwd.to_owned(), args, ..Default::default() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn call_named(cwd: &str, named: BTreeMap<String, String>) -> Self {
|
|
||||||
Exec { cmd: cwd.to_owned(), named, ..Default::default() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn vec(self) -> Vec<Self> { vec![self] }
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn with(mut self, name: impl ToString, value: impl ToString) -> Self {
|
|
||||||
self.named.insert(name.to_string(), value.to_string());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn with_bool(mut self, name: impl ToString, state: bool) -> Self {
|
|
||||||
if state {
|
|
||||||
self.named.insert(name.to_string(), Default::default());
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ mod key;
|
||||||
mod keymap;
|
mod keymap;
|
||||||
|
|
||||||
pub use control::*;
|
pub use control::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
pub use exec::*;
|
pub use exec::*;
|
||||||
pub use key::*;
|
pub use key::*;
|
||||||
pub use keymap::*;
|
pub use keymap::*;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::completion::Completion;
|
use crate::completion::Completion;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{Exec, Layer};
|
||||||
use yazi_shared::Layer;
|
|
||||||
|
|
||||||
use crate::{completion::Completion, emit, input::Input};
|
use crate::{completion::Completion, emit, input::Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{mem, ops::ControlFlow};
|
use std::{mem, ops::ControlFlow};
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::completion::Completion;
|
use crate::completion::Completion;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
|
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{Exec, Layer};
|
||||||
use yazi_shared::Layer;
|
|
||||||
|
|
||||||
use crate::{completion::Completion, emit};
|
use crate::{completion::Completion, emit};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ use std::{collections::BTreeMap, ffi::OsString};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use tokio::sync::{mpsc::{self, UnboundedSender}, oneshot};
|
use tokio::sync::{mpsc::{self, UnboundedSender}, oneshot};
|
||||||
use yazi_config::{keymap::Exec, open::Opener, popup::{InputOpt, SelectOpt}};
|
use yazi_config::{open::Opener, popup::{InputOpt, SelectOpt}};
|
||||||
use yazi_shared::{fs::Url, InputError, Layer, RoCell};
|
use yazi_shared::{fs::Url, Exec, InputError, Layer, RoCell};
|
||||||
|
|
||||||
use super::files::FilesOp;
|
use super::files::FilesOp;
|
||||||
use crate::{preview::PreviewLock, tasks::TasksProgress};
|
use crate::{preview::PreviewLock, tasks::TasksProgress};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::help::Help;
|
use crate::help::Help;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::help::Help;
|
use crate::help::Help;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use yazi_config::{keymap::Exec, popup::{Offset, Origin, Position}};
|
use yazi_config::popup::{Offset, Origin, Position};
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{help::Help, input::Input};
|
use crate::{help::Help, input::Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{CharKind, Exec};
|
||||||
use yazi_shared::CharKind;
|
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{Exec, InputError};
|
||||||
use yazi_shared::InputError;
|
|
||||||
|
|
||||||
use crate::{completion::Completion, input::Input};
|
use crate::{completion::Completion, input::Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::path::MAIN_SEPARATOR;
|
use std::path::MAIN_SEPARATOR;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{Exec, Layer};
|
||||||
use yazi_shared::Layer;
|
|
||||||
|
|
||||||
use crate::{emit, input::Input};
|
use crate::{emit, input::Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{op::InputOp, Input};
|
use crate::input::{op::InputOp, Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}};
|
use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{CharKind, Exec};
|
||||||
use yazi_shared::CharKind;
|
|
||||||
|
|
||||||
use crate::input::{op::InputOp, Input};
|
use crate::input::{op::InputOp, Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{op::InputOp, Input, InputMode};
|
use crate::input::{op::InputOp, Input, InputMode};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::ops::RangeBounds;
|
use std::ops::RangeBounds;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::{CharKind, Exec};
|
||||||
use yazi_shared::CharKind;
|
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{op::InputOp, snap::InputSnap, Input};
|
use crate::input::{op::InputOp, snap::InputSnap, Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{external, input::{op::InputOp, Input}};
|
use crate::{external, input::{op::InputOp, Input}};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use yazi_config::keymap::{Exec, Key};
|
use yazi_config::keymap::Key;
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{Input, InputMode};
|
use crate::input::{Input, InputMode};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{Input, InputMode};
|
use crate::input::{Input, InputMode};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{op::InputOp, Input, InputMode};
|
use crate::input::{op::InputOp, Input, InputMode};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::input::{op::InputOp, Input};
|
use crate::input::{op::InputOp, Input};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use std::path::{PathBuf, MAIN_SEPARATOR};
|
use std::path::{PathBuf, MAIN_SEPARATOR};
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
use yazi_config::popup::InputOpt;
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::{fs::Url, Exec};
|
||||||
|
|
||||||
use crate::{emit, files::{File, FilesOp}, manager::Manager};
|
use crate::{emit, files::{File, FilesOp}, manager::Manager};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::{fs::Url, Layer};
|
use yazi_shared::{fs::Url, Layer};
|
||||||
|
|
||||||
use crate::{emit, manager::Manager};
|
use crate::{emit, manager::Manager};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
|
||||||
use yazi_config::{keymap::Exec, popup::SelectOpt, OPEN};
|
use yazi_config::{popup::SelectOpt, OPEN};
|
||||||
use yazi_shared::MIME_DIR;
|
use yazi_shared::{Exec, MIME_DIR};
|
||||||
|
|
||||||
use crate::{emit, external, manager::Manager};
|
use crate::{emit, external, manager::Manager};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use yazi_config::{keymap::Exec, MANAGER};
|
use yazi_config::MANAGER;
|
||||||
use yazi_shared::{fs::Url, Layer, MIME_DIR};
|
use yazi_shared::{fs::Url, Exec, Layer, MIME_DIR};
|
||||||
|
|
||||||
use crate::{emit, manager::Manager};
|
use crate::{emit, manager::Manager};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
use yazi_config::popup::InputOpt;
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{emit, manager::Manager, tasks::Tasks};
|
use crate::{emit, manager::Manager, tasks::Tasks};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::Layer;
|
use yazi_shared::Layer;
|
||||||
|
|
||||||
use crate::{emit, manager::Manager};
|
use crate::{emit, manager::Manager};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use std::{collections::BTreeMap, ffi::OsStr, io::{stdout, BufWriter, Write}, pat
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
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::{keymap::Exec, popup::InputOpt, OPEN, PREVIEW};
|
use yazi_config::{popup::InputOpt, OPEN, PREVIEW};
|
||||||
use yazi_shared::{fs::{max_common_root, Url}, term::Term, Defer};
|
use yazi_shared::{fs::{max_common_root, Url}, term::Term, Defer, Exec};
|
||||||
|
|
||||||
use crate::{emit, external::{self, ShellOpt}, files::{File, FilesOp}, manager::Manager, Event, BLOCKER};
|
use crate::{emit, external::{self, ShellOpt}, files::{File, FilesOp}, manager::Manager, Event, BLOCKER};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::manager::Tabs;
|
use crate::manager::Tabs;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
use crate::{manager::Tabs, tab::Tab};
|
use crate::{manager::Tabs, tab::Tab};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::manager::Tabs;
|
use crate::manager::Tabs;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::manager::Tabs;
|
use crate::manager::Tabs;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::select::Select;
|
use crate::select::Select;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::select::Select;
|
use crate::select::Select;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tab::Tab, Step};
|
use crate::{manager::Manager, tab::Tab, Step};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use std::{mem, time::Duration};
|
||||||
|
|
||||||
use tokio::{fs, pin};
|
use tokio::{fs, pin};
|
||||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
use yazi_config::popup::InputOpt;
|
||||||
use yazi_shared::{fs::{expand_path, Url}, Debounce, InputError, Layer};
|
use yazi_shared::{fs::{expand_path, Url}, Debounce, Exec, InputError, Layer};
|
||||||
|
|
||||||
use crate::{completion::Completion, emit, manager::Manager, tab::Tab};
|
use crate::{completion::Completion, emit, manager::Manager, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{external, tab::Tab};
|
use crate::{external, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tab::Tab};
|
use crate::{manager::Manager, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::{Mode, Tab};
|
use crate::tab::{Mode, Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use std::time::Duration;
|
||||||
|
|
||||||
use tokio::pin;
|
use tokio::pin;
|
||||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
use yazi_config::popup::InputOpt;
|
||||||
use yazi_shared::{Debounce, InputError, Layer};
|
use yazi_shared::{Debounce, Exec, InputError, Layer};
|
||||||
|
|
||||||
use crate::{emit, tab::{Finder, FinderCase, Tab}};
|
use crate::{emit, tab::{Finder, FinderCase, Tab}};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tab::Tab};
|
use crate::{manager::Manager, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::{fs::ends_with_slash, Defer};
|
use yazi_shared::{fs::ends_with_slash, Defer};
|
||||||
|
|
||||||
use crate::{emit, external::{self, FzfOpt, ZoxideOpt}, tab::Tab, Event, BLOCKER};
|
use crate::{emit, external::{self, FzfOpt, ZoxideOpt}, tab::Tab, Event, BLOCKER};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{manager::Manager, tab::Tab};
|
use crate::{manager::Manager, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::{fs::{expand_path, Url}, Layer};
|
use yazi_shared::{fs::{expand_path, Url}, Layer};
|
||||||
|
|
||||||
use crate::{emit, files::{File, FilesOp}, manager::Manager, tab::Tab};
|
use crate::{emit, files::{File, FilesOp}, manager::Manager, tab::Tab};
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ use std::{mem, time::Duration};
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use tokio::pin;
|
use tokio::pin;
|
||||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
use yazi_config::popup::InputOpt;
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{emit, external, files::FilesOp, manager::Manager, tab::Tab};
|
use crate::{emit, external, files::FilesOp, manager::Manager, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use yazi_config::{keymap::Exec, open::Opener, popup::InputOpt};
|
use yazi_config::{open::Opener, popup::InputOpt};
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::{emit, tab::Tab};
|
use crate::{emit, tab::Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use yazi_config::{keymap::Exec, manager::SortBy};
|
use yazi_config::manager::SortBy;
|
||||||
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tab::{Mode, Tab};
|
use crate::tab::{Mode, Tab};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tasks::Tasks;
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tasks::Tasks;
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ 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_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
use yazi_shared::{term::Term, Defer};
|
use yazi_shared::{term::Term, Defer};
|
||||||
|
|
||||||
use crate::{emit, tasks::Tasks, Event, BLOCKER};
|
use crate::{emit, tasks::Tasks, Event, BLOCKER};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_shared::Exec;
|
||||||
|
|
||||||
use crate::tasks::Tasks;
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ use anyhow::{Ok, Result};
|
||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use ratatui::{backend::Backend, prelude::Rect};
|
use ratatui::{backend::Backend, prelude::Rect};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use yazi_config::{keymap::{Exec, Key}, BOOT};
|
use yazi_config::{keymap::Key, BOOT};
|
||||||
use yazi_core::{emit, files::FilesOp, input::InputMode, manager::Manager, preview::COLLISION, Ctx, Event};
|
use yazi_core::{emit, files::FilesOp, input::InputMode, manager::Manager, preview::COLLISION, Ctx, Event};
|
||||||
use yazi_shared::{term::Term, Layer};
|
use yazi_shared::{term::Term, Exec, Layer};
|
||||||
|
|
||||||
use crate::{Executor, Logs, Panic, Root, Signals};
|
use crate::{Executor, Logs, Panic, Root, Signals};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use yazi_config::{keymap::{Control, Exec, Key}, KEYMAP};
|
use yazi_config::{keymap::{Control, Key}, KEYMAP};
|
||||||
use yazi_core::{input::InputMode, Ctx};
|
use yazi_core::{input::InputMode, Ctx};
|
||||||
use yazi_shared::Layer;
|
use yazi_shared::{Exec, Layer};
|
||||||
|
|
||||||
pub(super) struct Executor<'a> {
|
pub(super) struct Executor<'a> {
|
||||||
cx: &'a mut Ctx,
|
cx: &'a mut Ctx,
|
||||||
|
|
|
||||||
54
yazi-shared/src/event.rs
Normal file
54
yazi-shared/src/event.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
use std::{any::Any, collections::BTreeMap, fmt::{self, Display}};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Exec {
|
||||||
|
pub cmd: String,
|
||||||
|
pub args: Vec<String>,
|
||||||
|
pub named: BTreeMap<String, String>,
|
||||||
|
pub data: Option<Box<dyn Any + Send>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Exec {
|
||||||
|
#[inline]
|
||||||
|
pub fn call(cwd: &str, args: Vec<String>) -> Self {
|
||||||
|
Exec { cmd: cwd.to_owned(), args, ..Default::default() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn call_named(cwd: &str, named: BTreeMap<String, String>) -> Self {
|
||||||
|
Exec { cmd: cwd.to_owned(), named, ..Default::default() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn vec(self) -> Vec<Self> { vec![self] }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn with(mut self, name: impl ToString, value: impl ToString) -> Self {
|
||||||
|
self.named.insert(name.to_string(), value.to_string());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn with_bool(mut self, name: impl ToString, state: bool) -> Self {
|
||||||
|
if state {
|
||||||
|
self.named.insert(name.to_string(), Default::default());
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Exec {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.cmd)?;
|
||||||
|
if !self.args.is_empty() {
|
||||||
|
write!(f, " {}", self.args.join(" "))?;
|
||||||
|
}
|
||||||
|
for (k, v) in &self.named {
|
||||||
|
write!(f, " --{k}")?;
|
||||||
|
if !v.is_empty() {
|
||||||
|
write!(f, "={v}")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ mod debounce;
|
||||||
mod defer;
|
mod defer;
|
||||||
mod env;
|
mod env;
|
||||||
mod errors;
|
mod errors;
|
||||||
|
mod event;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
mod layer;
|
mod layer;
|
||||||
mod mime;
|
mod mime;
|
||||||
|
|
@ -19,6 +20,7 @@ pub use debounce::*;
|
||||||
pub use defer::*;
|
pub use defer::*;
|
||||||
pub use env::*;
|
pub use env::*;
|
||||||
pub use errors::*;
|
pub use errors::*;
|
||||||
|
pub use event::*;
|
||||||
pub use layer::*;
|
pub use layer::*;
|
||||||
pub use mime::*;
|
pub use mime::*;
|
||||||
pub use natsort::*;
|
pub use natsort::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue