refactor: eliminate exec (#1045)

This commit is contained in:
三咲雅 · Misaki Masa 2024-05-16 18:20:47 +08:00 committed by GitHub
parent dcd23f2cd3
commit 2683b1d6a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 20 additions and 241 deletions

View File

@ -1,34 +0,0 @@
use serde::{Deserialize, Deserializer};
use crate::MERGED_YAZI;
#[derive(Debug)]
pub struct Headsup {
// TODO: remove this once Yazi 0.3 is released --
pub disable_exec_warn: bool,
}
impl Default for Headsup {
fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() }
}
impl<'de> Deserialize<'de> for Headsup {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Outer {
headsup: Shadow,
}
#[derive(Deserialize)]
struct Shadow {
#[serde(default)]
disable_exec_warn: bool,
}
let outer = Outer::deserialize(deserializer)?;
Ok(Self { disable_exec_warn: outer.headsup.disable_exec_warn })
}
}

View File

@ -1,3 +0,0 @@
mod headsup;
pub use headsup::*;

View File

@ -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>,
}
@ -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 })
}
}

View File

@ -2,7 +2,6 @@
use yazi_shared::{RoCell, Xdg};
pub mod headsup;
pub mod keymap;
mod layout;
mod log;
@ -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();
@ -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);
@ -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(())
}

View File

@ -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,
@ -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)]
@ -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"));
}

View File

@ -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 }
}
}

View File

@ -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,
}
@ -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,
})
}
}

View File

@ -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);
}
}

View File

@ -1,55 +0,0 @@
use std::time::Duration;
use yazi_proxy::{options::{NotifyLevel, NotifyOpt}, AppProxy};
use yazi_shared::{emit, event::Cmd, Layer};
use crate::tab::Tab;
pub struct Opt {
type_: OptType,
}
#[derive(PartialEq, Eq)]
pub enum OptType {
None,
Fzf,
Zoxide,
}
impl From<Cmd> for Opt {
fn from(mut c: Cmd) -> Self {
Self {
type_: match c.take_first_str().as_deref() {
Some("fzf") => OptType::Fzf,
Some("zoxide") => OptType::Zoxide,
_ => OptType::None,
},
}
}
}
impl Tab {
// TODO: Remove this once Yazi v0.2.7 is released
pub fn jump(&self, opt: impl Into<Opt>) {
AppProxy::notify(NotifyOpt {
title: "Jump".to_owned(),
content: r#"The `jump` command has been deprecated in Yazi v0.2.5.
Please replace `jump fzf` with `plugin fzf`, and `jump zoxide` with `plugin zoxide`, in your `keymap.toml`.
See https://github.com/sxyazi/yazi/issues/865 for more details."#.to_owned(),
level: NotifyLevel::Warn,
timeout: Duration::from_secs(15),
});
let opt = opt.into() as Opt;
if opt.type_ == OptType::None {
return;
}
if opt.type_ == OptType::Fzf {
emit!(Call(Cmd::args("plugin", vec!["fzf".to_owned()]), Layer::App));
} else {
emit!(Call(Cmd::args("plugin", vec!["zoxide".to_owned()]), Layer::App));
}
}
}

View File

@ -8,7 +8,6 @@ mod filter;
mod find;
mod forward;
mod hidden;
mod jump;
mod leave;
mod linemode;
mod preview;

View File

@ -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));
}
}

View File

@ -108,7 +108,6 @@ impl<'a> Executor<'a> {
on!(ACTIVE, hidden);
on!(ACTIVE, linemode);
on!(ACTIVE, search);
on!(ACTIVE, jump);
// Filter
on!(ACTIVE, filter);

View File

@ -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

View File

@ -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();