Skip to content

Commit

Permalink
refactor: eliminate exec (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed May 16, 2024
1 parent dcd23f2 commit 2683b1d
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 241 deletions.
34 changes: 0 additions & 34 deletions yazi-config/src/headsup/headsup.rs

This file was deleted.

3 changes: 0 additions & 3 deletions yazi-config/src/headsup/mod.rs

This file was deleted.

38 changes: 4 additions & 34 deletions yazi-config/src/keymap/control.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::{borrow::Cow, collections::VecDeque, sync::atomic::Ordering};
use std::{borrow::Cow, collections::VecDeque};

use serde::{Deserialize, Deserializer};
use serde::Deserialize;
use yazi_shared::event::Cmd;

use super::Key;
use crate::DEPRECATED_EXEC;

#[derive(Debug, Default)]
#[derive(Debug, Default, Deserialize)]
pub struct Control {
pub on: Vec<Key>,
#[serde(deserialize_with = "super::run_deserialize")]
pub run: Vec<Cmd>,
pub desc: Option<String>,
}
Expand Down Expand Up @@ -40,33 +40,3 @@ impl Control {
|| self.on().to_lowercase().contains(&s)
}
}

// TODO: remove this once Yazi 0.3 is released
impl<'de> Deserialize<'de> for Control {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
pub struct Shadow {
pub on: Vec<Key>,
pub run: Option<VecCmd>,
pub exec: Option<VecCmd>,
pub desc: Option<String>,
}

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

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

Ok(Self { on: shadow.on, run: run.0, desc: shadow.desc })
}
}
20 changes: 0 additions & 20 deletions yazi-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use yazi_shared::{RoCell, Xdg};

pub mod headsup;
pub mod keymap;
mod layout;
mod log;
Expand All @@ -24,17 +23,12 @@ 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();
Expand All @@ -55,7 +49,6 @@ pub fn init() -> anyhow::Result<()> {

LAYOUT.with(Default::default);

HEADSUP.with(Default::default);
KEYMAP.with(Default::default);
LOG.with(Default::default);
MANAGER.with(Default::default);
Expand All @@ -68,18 +61,5 @@ pub fn init() -> anyhow::Result<()> {
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) {
eprintln!(
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.
"#
);
}
Ok(())
}
16 changes: 2 additions & 14 deletions yazi-config/src/open/opener.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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,
Expand Down Expand Up @@ -36,9 +32,7 @@ impl<'de> Deserialize<'de> for Opener {
{
#[derive(Deserialize)]
pub struct Shadow {
run: Option<String>,
// TODO: remove this once Yazi 0.3 is released --
exec: Option<String>,
run: String,
#[serde(default)]
block: bool,
#[serde(default)]
Expand All @@ -50,13 +44,7 @@ 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

let run = shadow.run;
if run.is_empty() {
return Err(serde::de::Error::custom("`run` cannot be empty"));
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-config/src/plugin/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub struct PluginProps {

impl From<&PluginRule> for PluginProps {
fn from(rule: &PluginRule) -> Self {
Self { id: rule.id, name: rule.cmd.name.to_owned(), multi: rule.multi, prio: rule.prio }
Self { id: rule.id, name: rule.run.name.to_owned(), multi: rule.multi, prio: rule.prio }
}
}
63 changes: 9 additions & 54 deletions yazi-config/src/plugin/rule.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use std::sync::atomic::Ordering;

use serde::{Deserialize, Deserializer};
use serde::Deserialize;
use yazi_shared::{event::Cmd, Condition};

use crate::{Pattern, Priority, DEPRECATED_EXEC};
use crate::{Pattern, Priority};

#[derive(Debug)]
#[derive(Debug, Deserialize)]
pub struct PluginRule {
#[serde(skip)]
pub id: u8,
pub cond: Option<Condition>,
pub name: Option<Pattern>,
pub mime: Option<Pattern>,
pub cmd: Cmd,
#[serde(deserialize_with = "super::run_deserialize")]
pub run: Cmd,
#[serde(default)]
pub sync: bool,
#[serde(default)]
pub multi: bool,
#[serde(default)]
pub prio: Priority,
}

Expand All @@ -24,51 +27,3 @@ impl PluginRule {
#[inline]
pub fn any_dir(&self) -> bool { self.name.as_ref().is_some_and(|p| p.any_dir()) }
}

// TODO: remove this once Yazi 0.3 is released
impl<'de> Deserialize<'de> for PluginRule {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
pub struct Shadow {
#[serde(default)]
pub id: u8,
pub cond: Option<Condition>,
pub name: Option<Pattern>,
pub mime: Option<Pattern>,
pub run: Option<WrappedCmd>,
pub exec: Option<WrappedCmd>,
#[serde(default)]
pub sync: bool,
#[serde(default)]
pub multi: bool,
#[serde(default)]
pub prio: Priority,
}

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

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

Ok(Self {
id: shadow.id,
cond: shadow.cond,
name: shadow.name,
mime: shadow.mime,
cmd: run.0,
sync: shadow.sync,
multi: shadow.multi,
prio: shadow.prio,
})
}
}
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ impl Manager {
};

let opt = opt.into() as Opt;
isolate::seek_sync(&previewer.cmd, hovered.clone(), opt.units);
isolate::seek_sync(&previewer.run, hovered.clone(), opt.units);
}
}
55 changes: 0 additions & 55 deletions yazi-core/src/tab/commands/jump.rs

This file was deleted.

1 change: 0 additions & 1 deletion yazi-core/src/tab/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod filter;
mod find;
mod forward;
mod hidden;
mod jump;
mod leave;
mod linemode;
mod preview;
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/src/tab/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ impl Preview {

self.abort();
if previewer.sync {
isolate::peek_sync(&previewer.cmd, file, self.skip);
isolate::peek_sync(&previewer.run, file, self.skip);
} else {
self.previewer_ct = Some(isolate::peek(&previewer.cmd, file, self.skip));
self.previewer_ct = Some(isolate::peek(&previewer.run, file, self.skip));
}
}

Expand Down
1 change: 0 additions & 1 deletion yazi-fm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl<'a> Executor<'a> {
on!(ACTIVE, hidden);
on!(ACTIVE, linemode);
on!(ACTIVE, search);
on!(ACTIVE, jump);

// Filter
on!(ACTIVE, filter);
Expand Down
20 changes: 0 additions & 20 deletions yazi-plugin/preset/components/header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ function Header:tabs()
return ui.Line(spans)
end

-- TODO: remove this function after v0.2.5 release
function Header:layout(area)
if not ya.deprecated_header_layout then
ya.deprecated_header_layout = true
ya.notify {
title = "Deprecated API",
content = "`Header:layout()` is deprecated, please apply the latest `Header:render()` in your `init.lua`",
timeout = 5,
level = "warn",
}
end

self.area = area

return ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({ ui.Constraint.Percentage(50), ui.Constraint.Percentage(50) })
:split(area)
end

function Header:render(area)
self.area = area

Expand Down
2 changes: 1 addition & 1 deletion yazi-scheduler/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl Scheduler {
pub fn preload_paged(&self, rule: &PluginRule, targets: Vec<&yazi_shared::fs::File>) {
let id = self.ongoing.lock().add(
TaskKind::Preload,
format!("Run preloader `{}` with {} target(s)", rule.cmd.name, targets.len()),
format!("Run preloader `{}` with {} target(s)", rule.run.name, targets.len()),
);

let plugin = rule.into();
Expand Down

0 comments on commit 2683b1d

Please sign in to comment.