Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Mar 4, 2024
1 parent ceae44d commit 729bc7a
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 41 deletions.
16 changes: 13 additions & 3 deletions yazi-config/src/keymap/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ impl<'de> Deserialize<'de> for Control {
#[derive(Deserialize)]
pub struct Shadow {
pub on: Vec<Key>,
#[serde(deserialize_with = "super::run_deserialize")]
pub run: Vec<Cmd>,
pub run: Option<VecCmd>,
// TODO: remove this once Yazi 0.3 is released
pub exec: Option<VecCmd>,
pub desc: Option<String>,
}

let shadow = Shadow::deserialize(deserializer)?;

Ok(Self { on: shadow.on, run: shadow.run, desc: shadow.desc })
// TODO: remove this once Yazi 0.3 is released --
#[derive(Deserialize)]
struct VecCmd(#[serde(deserialize_with = "super::run_deserialize")] Vec<Cmd>);

let Some(run) = shadow.run.or(shadow.exec) else {
return Err(serde::de::Error::custom("missing field `run` within `[keymap]`"));
};
// TODO: -- remove this once Yazi 0.3 is released

Ok(Self { on: shadow.on, run: run.0, desc: shadow.desc })
}
}
31 changes: 14 additions & 17 deletions yazi-config/src/open/opener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use serde::{Deserialize, Deserializer};

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Opener {
// FIXME
pub exec: String,
pub run: String,
pub block: bool,
pub orphan: bool,
pub desc: String,
Expand Down Expand Up @@ -33,7 +32,9 @@ impl<'de> Deserialize<'de> for Opener {
{
#[derive(Deserialize)]
pub struct Shadow {
exec: String,
run: Option<String>,
// TODO: remove this once Yazi 0.3 is released --
exec: Option<String>,
#[serde(default)]
block: bool,
#[serde(default)]
Expand All @@ -44,22 +45,18 @@ impl<'de> Deserialize<'de> for Opener {
}

let shadow = Shadow::deserialize(deserializer)?;
if shadow.exec.is_empty() {
return Err(serde::de::Error::custom("`exec` cannot be empty"));

// TODO: remove this once Yazi 0.3 is released --
let run = shadow.run.or(shadow.exec).unwrap_or_default();
// TODO: -- remove this once Yazi 0.3 is released

if run.is_empty() {
return Err(serde::de::Error::custom("`run` cannot be empty"));
}

let desc =
shadow.desc.unwrap_or_else(|| shadow.exec.split_whitespace().next().unwrap().to_string());
let desc = shadow.desc.unwrap_or_else(|| run.split_whitespace().next().unwrap().to_string());

let spread =
shadow.exec.contains("$@") || shadow.exec.contains("%*") || shadow.exec.contains("$*");
Ok(Self {
exec: shadow.exec,
block: shadow.block,
orphan: shadow.orphan,
desc,
for_: shadow.for_,
spread,
})
let spread = run.contains("$@") || run.contains("%*") || run.contains("$*");
Ok(Self { run, block: shadow.block, orphan: shadow.orphan, desc, for_: shadow.for_, spread })
}
}
20 changes: 12 additions & 8 deletions yazi-config/src/plugin/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ impl<'de> Deserialize<'de> for PluginRule {
pub cond: Option<Condition>,
pub name: Option<Pattern>,
pub mime: Option<Pattern>,
// FIXME
#[serde(rename = "run")]
#[serde(deserialize_with = "super::run_deserialize")]
pub run: Cmd,
#[serde(rename = "exec")]
#[serde(deserialize_with = "super::run_deserialize")]
pub exec: Cmd,
pub run: Option<WrappedCmd>,
pub exec: Option<WrappedCmd>,
#[serde(default)]
pub sync: bool,
#[serde(default)]
Expand All @@ -52,12 +47,21 @@ impl<'de> Deserialize<'de> for PluginRule {

let shadow = Shadow::deserialize(deserializer)?;

// TODO: -- remove this once Yazi 0.3 is released
#[derive(Deserialize)]
struct WrappedCmd(#[serde(deserialize_with = "super::run_deserialize")] Cmd);

let Some(run) = shadow.run.or(shadow.exec) else {
return Err(serde::de::Error::custom("missing field `run` within `[plugin]`"));
};
// TODO: remove this once Yazi 0.3 is released --

Ok(Self {
id: shadow.id,
cond: shadow.cond,
name: shadow.name,
mime: shadow.mime,
cmd: shadow.run, // FIXME
cmd: run.0,
sync: shadow.sync,
multi: shadow.multi,
prio: shadow.prio,
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Manager {
AppProxy::stop().await;

let mut child = external::shell(ShellOpt {
cmd: (*opener.exec).into(),
cmd: (*opener.run).into(),
args: vec![OsString::new(), tmp.to_owned().into()],
piped: false,
orphan: false,
Expand Down
12 changes: 6 additions & 6 deletions yazi-core/src/tab/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use yazi_shared::event::Cmd;
use crate::tab::Tab;

pub struct Opt {
exec: String,
run: String,
block: bool,
confirm: bool,
}

impl From<Cmd> for Opt {
fn from(mut c: Cmd) -> Self {
Self {
exec: c.take_first().unwrap_or_default(),
run: c.take_first().unwrap_or_default(),
block: c.named.contains_key("block"),
confirm: c.named.contains_key("confirm"),
}
Expand All @@ -30,16 +30,16 @@ impl Tab {
let selected = self.hovered_and_selected().into_iter().cloned().collect();

tokio::spawn(async move {
if !opt.confirm || opt.exec.is_empty() {
let mut result = InputProxy::show(InputCfg::shell(opt.block).with_value(opt.exec));
if !opt.confirm || opt.run.is_empty() {
let mut result = InputProxy::show(InputCfg::shell(opt.block).with_value(opt.run));
match result.recv().await {
Some(Ok(e)) => opt.exec = e,
Some(Ok(e)) => opt.run = e,
_ => return,
}
}

TasksProxy::open_with(selected, Opener {
exec: opt.exec,
run: opt.run,
block: opt.block,
orphan: false,
desc: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) struct App {
}

impl App {
pub(crate) async fn run() -> Result<()> {
pub(crate) async fn serve() -> Result<()> {
let term = Term::start()?;
let signals = Signals::start()?;

Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/help/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Widget for Bindings<'_> {
let col1: Vec<_> =
bindings.iter().map(|c| ListItem::new(c.on()).style(THEME.help.on)).collect();

// Exec
// Run
let col2: Vec<_> =
bindings.iter().map(|c| ListItem::new(c.run()).style(THEME.help.run)).collect();

Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ async fn main() -> anyhow::Result<()> {

yazi_core::init();

app::App::run().await
app::App::serve().await
}
2 changes: 1 addition & 1 deletion yazi-plugin/src/bindings/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> TryFrom<mlua::Table<'a>> for Position {
offset: Offset {
x: t.raw_get("x").unwrap_or_default(),
y: t.raw_get("y").unwrap_or_default(),
width: t.raw_get("w").unwrap_or_default(),
width: t.raw_get("w")?,
height: 3,
},
}))
Expand Down
5 changes: 3 additions & 2 deletions yazi-scheduler/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Scheduler {

micro: async_priority_channel::Sender<BoxFuture<'static, ()>, u8>,
prog: mpsc::UnboundedSender<TaskProg>,
// FIXME
pub running: Arc<Mutex<Running>>,
}

Expand Down Expand Up @@ -334,7 +335,7 @@ impl Scheduler {

pub fn process_open(&self, opener: &Opener, args: &[impl AsRef<OsStr>]) {
let name = {
let s = format!("Execute `{}`", opener.exec);
let s = format!("Run `{}`", opener.run);
let args = args.iter().map(|a| a.as_ref().to_string_lossy()).collect::<Vec<_>>().join(" ");
if args.is_empty() { s } else { format!("{s} with `{args}`") }
};
Expand Down Expand Up @@ -364,7 +365,7 @@ impl Scheduler {
process
.open(ProcessOpOpen {
id,
cmd: opener.exec.into(),
cmd: opener.run.into(),
args,
block: opener.block,
orphan: opener.orphan,
Expand Down

0 comments on commit 729bc7a

Please sign in to comment.