diff --git a/Cargo.lock b/Cargo.lock index fbf5857e..d43a550d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "avif-serialize" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19135c0c7a60bfee564dbe44ab5ce0557c6bf3884e5291a50be76a15640c4fbd" +checksum = "2ea8ef51aced2b9191c08197f55450d830876d9933f8f48a429b354f1d496b42" dependencies = [ "arrayvec", ] @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.27" +version = "1.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" dependencies = [ "jobserver", "libc", @@ -879,18 +879,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "filetime" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" -dependencies = [ - "cfg-if", - "libc", - "libredox", - "windows-sys 0.59.0", -] - [[package]] name = "flate2" version = "1.1.2" @@ -1325,9 +1313,9 @@ checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libfuzzer-sys" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75" +checksum = "5037190e1f70cbeef565bd267599242926f724d3b8a9f510fd7e0b540cfa4404" dependencies = [ "arbitrary", "cc", @@ -1341,7 +1329,6 @@ checksum = "1580801010e535496706ba011c15f8532df6b42297d2e471fec38ceadd8c0638" dependencies = [ "bitflags 2.9.1", "libc", - "redox_syscall", ] [[package]] @@ -1558,12 +1545,11 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "notify" -version = "8.0.0" +version = "8.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943" +checksum = "3163f59cd3fa0e9ef8c32f242966a7b9994fd7378366099593e0e73077cd8c97" dependencies = [ "bitflags 2.9.1", - "filetime", "fsevent-sys", "inotify", "kqueue", @@ -1572,7 +1558,7 @@ dependencies = [ "mio", "notify-types", "walkdir", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -2677,9 +2663,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.46.0" +version = "1.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1140bb80481756a8cbe10541f37433b459c5aa1e727b4c020fbfebdc25bf3ec4" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" dependencies = [ "backtrace", "bytes", @@ -3469,13 +3455,19 @@ dependencies = [ name = "yazi-binding" version = "25.6.11" dependencies = [ + "ansi-to-tui", "mlua", "paste", "ratatui", "serde_json", + "tokio", + "tracing", + "unicode-width 0.2.0", + "yazi-adapter", "yazi-config", "yazi-fs", "yazi-macro", + "yazi-proxy", "yazi-shared", ] @@ -3555,7 +3547,6 @@ name = "yazi-core" version = "25.6.11" dependencies = [ "anyhow", - "bitflags 2.9.1", "crossterm 0.29.0", "futures", "indexmap", @@ -3577,6 +3568,7 @@ dependencies = [ "yazi-dds", "yazi-fs", "yazi-macro", + "yazi-parser", "yazi-plugin", "yazi-proxy", "yazi-scheduler", @@ -3693,14 +3685,31 @@ version = "25.6.11" name = "yazi-packing" version = "25.5.28" +[[package]] +name = "yazi-parser" +version = "25.6.11" +dependencies = [ + "anyhow", + "bitflags 2.9.1", + "mlua", + "tokio", + "yazi-binding", + "yazi-boot", + "yazi-config", + "yazi-dds", + "yazi-fs", + "yazi-macro", + "yazi-proxy", + "yazi-shared", + "yazi-widgets", +] + [[package]] name = "yazi-plugin" version = "25.6.11" dependencies = [ - "ansi-to-tui", "anyhow", "base64", - "clipboard-win", "crossterm 0.29.0", "futures", "globset", @@ -3726,10 +3735,12 @@ dependencies = [ "yazi-dds", "yazi-fs", "yazi-macro", + "yazi-parser", "yazi-prebuilt", "yazi-proxy", "yazi-shared", "yazi-term", + "yazi-widgets", ] [[package]] @@ -3812,16 +3823,21 @@ dependencies = [ name = "yazi-widgets" version = "25.6.11" dependencies = [ + "base64", + "clipboard-win", "crossterm 0.29.0", "futures", + "parking_lot", "ratatui", + "tokio", "unicode-width 0.2.0", + "yazi-binding", "yazi-codegen", "yazi-config", "yazi-macro", - "yazi-plugin", "yazi-proxy", "yazi-shared", + "yazi-term", ] [[package]] @@ -3861,9 +3877,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7384255a918371b5af158218d131530f694de9ad3815ebdd0453a940485cb0fa" +checksum = "2c9e525af0a6a658e031e95f14b7f889976b74a11ba0eca5a5fc9ac8a1c43a6a" dependencies = [ "zune-core", ] diff --git a/Cargo.toml b/Cargo.toml index 9889e782..444577f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ scopeguard = "1.2.0" serde = { version = "1.0.219", features = [ "derive" ] } serde_json = "1.0.140" syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] } -tokio = { version = "1.46.0", features = [ "full" ] } +tokio = { version = "1.46.1", features = [ "full" ] } tokio-stream = "0.1.17" tokio-util = "0.7.15" toml = { version = "0.8.23" } diff --git a/yazi-binding/Cargo.toml b/yazi-binding/Cargo.toml index 954915b9..a6cf4d2f 100644 --- a/yazi-binding/Cargo.toml +++ b/yazi-binding/Cargo.toml @@ -9,13 +9,21 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-config = { path = "../yazi-config", version = "25.6.11" } -yazi-fs = { path = "../yazi-fs", version = "25.6.11" } -yazi-macro = { path = "../yazi-macro", version = "25.6.11" } -yazi-shared = { path = "../yazi-shared", version = "25.6.11" } +yazi-adapter = { path = "../yazi-adapter", version = "25.6.11" } +yazi-config = { path = "../yazi-config", version = "25.6.11" } +yazi-fs = { path = "../yazi-fs", version = "25.6.11" } +yazi-macro = { path = "../yazi-macro", version = "25.6.11" } +yazi-proxy = { path = "../yazi-proxy", version = "25.6.11" } +yazi-shared = { path = "../yazi-shared", version = "25.6.11" } # External dependencies -mlua = { workspace = true } -paste = { workspace = true } -ratatui = { workspace = true } -serde_json = { workspace = true } +ansi-to-tui = { workspace = true } +mlua = { workspace = true } +paste = { workspace = true } +ratatui = { workspace = true } +serde_json = { workspace = true } +tokio = { workspace = true } +unicode-width = { workspace = true } + +# Logging +tracing = { workspace = true } diff --git a/yazi-plugin/src/bindings/cha.rs b/yazi-binding/src/cha.rs similarity index 100% rename from yazi-plugin/src/bindings/cha.rs rename to yazi-binding/src/cha.rs diff --git a/yazi-plugin/src/composer.rs b/yazi-binding/src/composer.rs similarity index 100% rename from yazi-plugin/src/composer.rs rename to yazi-binding/src/composer.rs diff --git a/yazi-plugin/src/elements/align.rs b/yazi-binding/src/elements/align.rs similarity index 100% rename from yazi-plugin/src/elements/align.rs rename to yazi-binding/src/elements/align.rs diff --git a/yazi-plugin/src/elements/area.rs b/yazi-binding/src/elements/area.rs similarity index 100% rename from yazi-plugin/src/elements/area.rs rename to yazi-binding/src/elements/area.rs diff --git a/yazi-plugin/src/elements/bar.rs b/yazi-binding/src/elements/bar.rs similarity index 100% rename from yazi-plugin/src/elements/bar.rs rename to yazi-binding/src/elements/bar.rs diff --git a/yazi-plugin/src/elements/border.rs b/yazi-binding/src/elements/border.rs similarity index 91% rename from yazi-plugin/src/elements/border.rs rename to yazi-binding/src/elements/border.rs index bbdc7fd7..1c3324aa 100644 --- a/yazi-plugin/src/elements/border.rs +++ b/yazi-binding/src/elements/border.rs @@ -14,13 +14,13 @@ const QUADRANT_OUTSIDE: u8 = 5; #[derive(Clone, Debug, Default)] pub struct Border { - pub(crate) area: Area, + pub area: Area, - pub(crate) edge: Edge, - pub(crate) r#type: ratatui::widgets::BorderType, - pub(crate) style: ratatui::style::Style, + pub edge: Edge, + pub r#type: ratatui::widgets::BorderType, + pub style: ratatui::style::Style, - pub(crate) titles: Vec<(ratatui::widgets::block::Position, ratatui::text::Line<'static>)>, + pub titles: Vec<(ratatui::widgets::block::Position, ratatui::text::Line<'static>)>, } impl Border { diff --git a/yazi-plugin/src/elements/cell.rs b/yazi-binding/src/elements/cell.rs similarity index 100% rename from yazi-plugin/src/elements/cell.rs rename to yazi-binding/src/elements/cell.rs diff --git a/yazi-plugin/src/elements/clear.rs b/yazi-binding/src/elements/clear.rs similarity index 100% rename from yazi-plugin/src/elements/clear.rs rename to yazi-binding/src/elements/clear.rs diff --git a/yazi-plugin/src/elements/constraint.rs b/yazi-binding/src/elements/constraint.rs similarity index 100% rename from yazi-plugin/src/elements/constraint.rs rename to yazi-binding/src/elements/constraint.rs diff --git a/yazi-plugin/src/elements/edge.rs b/yazi-binding/src/elements/edge.rs similarity index 100% rename from yazi-plugin/src/elements/edge.rs rename to yazi-binding/src/elements/edge.rs diff --git a/yazi-plugin/src/elements/elements.rs b/yazi-binding/src/elements/elements.rs similarity index 97% rename from yazi-plugin/src/elements/elements.rs rename to yazi-binding/src/elements/elements.rs index 86813f11..25c10674 100644 --- a/yazi-plugin/src/elements/elements.rs +++ b/yazi-binding/src/elements/elements.rs @@ -22,7 +22,7 @@ pub fn compose(lua: &Lua) -> mlua::Result { b"Rect" => super::Rect::compose(lua)?, b"Row" => super::Row::compose(lua)?, b"Span" => super::Span::compose(lua)?, - b"Style" => yazi_binding::Style::compose(lua)?, + b"Style" => crate::Style::compose(lua)?, b"Table" => super::Table::compose(lua)?, b"Text" => super::Text::compose(lua)?, b"Wrap" => super::Wrap::compose(lua)?, diff --git a/yazi-plugin/src/elements/gauge.rs b/yazi-binding/src/elements/gauge.rs similarity index 98% rename from yazi-plugin/src/elements/gauge.rs rename to yazi-binding/src/elements/gauge.rs index 0547c83a..13aabaa6 100644 --- a/yazi-plugin/src/elements/gauge.rs +++ b/yazi-binding/src/elements/gauge.rs @@ -1,8 +1,8 @@ use mlua::{AnyUserData, ExternalError, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value}; use ratatui::widgets::Widget; -use yazi_binding::Style; use super::{Area, Span}; +use crate::Style; #[derive(Clone, Debug, Default)] pub struct Gauge { diff --git a/yazi-plugin/src/elements/layout.rs b/yazi-binding/src/elements/layout.rs similarity index 100% rename from yazi-plugin/src/elements/layout.rs rename to yazi-binding/src/elements/layout.rs diff --git a/yazi-plugin/src/elements/line.rs b/yazi-binding/src/elements/line.rs similarity index 99% rename from yazi-plugin/src/elements/line.rs rename to yazi-binding/src/elements/line.rs index 20796bea..ec6287d4 100644 --- a/yazi-plugin/src/elements/line.rs +++ b/yazi-binding/src/elements/line.rs @@ -107,7 +107,7 @@ impl UserData for Line { fn add_methods>(methods: &mut M) { crate::impl_area_method!(methods); crate::impl_style_method!(methods, inner.style); - yazi_binding::impl_style_shorthands!(methods, inner.style); + crate::impl_style_shorthands!(methods, inner.style); methods.add_method("width", |_, me, ()| Ok(me.inner.width())); methods.add_function_mut("align", |_, (ud, align): (AnyUserData, Align)| { diff --git a/yazi-plugin/src/elements/list.rs b/yazi-binding/src/elements/list.rs similarity index 100% rename from yazi-plugin/src/elements/list.rs rename to yazi-binding/src/elements/list.rs diff --git a/yazi-plugin/src/elements/mod.rs b/yazi-binding/src/elements/mod.rs similarity index 100% rename from yazi-plugin/src/elements/mod.rs rename to yazi-binding/src/elements/mod.rs diff --git a/yazi-plugin/src/elements/pad.rs b/yazi-binding/src/elements/pad.rs similarity index 100% rename from yazi-plugin/src/elements/pad.rs rename to yazi-binding/src/elements/pad.rs diff --git a/yazi-plugin/src/elements/pos.rs b/yazi-binding/src/elements/pos.rs similarity index 100% rename from yazi-plugin/src/elements/pos.rs rename to yazi-binding/src/elements/pos.rs diff --git a/yazi-plugin/src/elements/rect.rs b/yazi-binding/src/elements/rect.rs similarity index 100% rename from yazi-plugin/src/elements/rect.rs rename to yazi-binding/src/elements/rect.rs diff --git a/yazi-plugin/src/elements/renderable.rs b/yazi-binding/src/elements/renderable.rs similarity index 97% rename from yazi-plugin/src/elements/renderable.rs rename to yazi-binding/src/elements/renderable.rs index 7f643277..0f86bb8b 100644 --- a/yazi-plugin/src/elements/renderable.rs +++ b/yazi-binding/src/elements/renderable.rs @@ -1,10 +1,9 @@ use std::any::TypeId; use mlua::{AnyUserData, ExternalError}; -use yazi_binding::Error; use super::{Bar, Border, Clear, Gauge, Line, List, Table, Text}; -use crate::elements::Rect; +use crate::{Error, elements::Rect}; #[derive(Clone, Debug)] pub enum Renderable { diff --git a/yazi-plugin/src/elements/row.rs b/yazi-binding/src/elements/row.rs similarity index 100% rename from yazi-plugin/src/elements/row.rs rename to yazi-binding/src/elements/row.rs diff --git a/yazi-plugin/src/elements/span.rs b/yazi-binding/src/elements/span.rs similarity index 97% rename from yazi-plugin/src/elements/span.rs rename to yazi-binding/src/elements/span.rs index 95e4bcef..e7a1ef74 100644 --- a/yazi-plugin/src/elements/span.rs +++ b/yazi-binding/src/elements/span.rs @@ -69,7 +69,7 @@ impl TryFrom for Span { impl UserData for Span { fn add_methods>(methods: &mut M) { crate::impl_style_method!(methods, 0.style); - yazi_binding::impl_style_shorthands!(methods, 0.style); + crate::impl_style_shorthands!(methods, 0.style); methods.add_method("visible", |_, Span(me), ()| { Ok(me.content.chars().any(|c| c.width().unwrap_or(0) > 0)) diff --git a/yazi-plugin/src/elements/table.rs b/yazi-binding/src/elements/table.rs similarity index 95% rename from yazi-plugin/src/elements/table.rs rename to yazi-binding/src/elements/table.rs index 0e3d878d..f96dcb0f 100644 --- a/yazi-plugin/src/elements/table.rs +++ b/yazi-binding/src/elements/table.rs @@ -1,16 +1,15 @@ use mlua::{AnyUserData, ExternalError, IntoLua, Lua, MetaMethod, UserData, Value}; use ratatui::widgets::StatefulWidget; -use yazi_binding::Style; use super::{Area, Row}; -use crate::elements::Constraint; +use crate::{Style, elements::Constraint}; const EXPECTED: &str = "expected a table of Rows"; // --- Table #[derive(Clone, Debug, Default)] pub struct Table { - pub(crate) area: Area, + pub area: Area, rows: Vec, header: Option>, @@ -84,15 +83,15 @@ impl Table { } #[inline] - pub(crate) fn len(&self) -> usize { self.rows.len() } + pub fn len(&self) -> usize { self.rows.len() } - pub(crate) fn select(&mut self, idx: Option) { + pub fn select(&mut self, idx: Option) { self .state .select(idx.map(|i| if self.rows.is_empty() { 0 } else { i.min(self.rows.len() - 1) })); } - pub(crate) fn selected(&self) -> Option { + pub fn selected(&self) -> Option { if self.rows.is_empty() { None } else { Some(self.state.selected()?.min(self.rows.len() - 1)) } } } diff --git a/yazi-plugin/src/elements/text.rs b/yazi-binding/src/elements/text.rs similarity index 97% rename from yazi-plugin/src/elements/text.rs rename to yazi-binding/src/elements/text.rs index 710d37ab..c96e0d57 100644 --- a/yazi-plugin/src/elements/text.rs +++ b/yazi-binding/src/elements/text.rs @@ -3,10 +3,9 @@ use std::{any::TypeId, mem}; use ansi_to_tui::IntoText; use mlua::{AnyUserData, ExternalError, ExternalResult, IntoLua, Lua, MetaMethod, Table, UserData, Value}; use ratatui::widgets::Widget; -use yazi_binding::Error; use super::{Area, Line, Span, Wrap}; -use crate::elements::Align; +use crate::{Error, elements::Align}; const EXPECTED: &str = "expected a string, Line, Span, or a table of them"; @@ -112,7 +111,7 @@ impl UserData for Text { fn add_methods>(methods: &mut M) { crate::impl_area_method!(methods); crate::impl_style_method!(methods, inner.style); - yazi_binding::impl_style_shorthands!(methods, inner.style); + crate::impl_style_shorthands!(methods, inner.style); methods.add_function_mut("align", |_, (ud, align): (AnyUserData, Align)| { ud.borrow_mut::()?.inner.alignment = Some(align.0); diff --git a/yazi-plugin/src/elements/utils.rs b/yazi-binding/src/elements/utils.rs similarity index 99% rename from yazi-plugin/src/elements/utils.rs rename to yazi-binding/src/elements/utils.rs index 4997cd65..739015ac 100644 --- a/yazi-plugin/src/elements/utils.rs +++ b/yazi-binding/src/elements/utils.rs @@ -6,7 +6,7 @@ use yazi_macro::render; use yazi_proxy::{AppProxy, HIDER}; use super::{Line, Rect, Span}; -use crate::bindings::{Permit, PermitRef}; +use crate::{Permit, PermitRef}; pub(super) struct Utils; diff --git a/yazi-plugin/src/elements/wrap.rs b/yazi-binding/src/elements/wrap.rs similarity index 100% rename from yazi-plugin/src/elements/wrap.rs rename to yazi-binding/src/elements/wrap.rs diff --git a/yazi-plugin/src/file/file.rs b/yazi-binding/src/file.rs similarity index 94% rename from yazi-plugin/src/file/file.rs rename to yazi-binding/src/file.rs index e23db4b6..b692ef31 100644 --- a/yazi-plugin/src/file/file.rs +++ b/yazi-binding/src/file.rs @@ -1,9 +1,8 @@ use std::ops::Deref; use mlua::{ExternalError, FromLua, Lua, Table, UserData, UserDataFields, UserDataMethods, UserDataRef, Value}; -use yazi_binding::Url; -use crate::{bindings::Cha, impl_file_fields, impl_file_methods}; +use crate::{Cha, Url, impl_file_fields, impl_file_methods}; pub type FileRef = UserDataRef; diff --git a/yazi-binding/src/lib.rs b/yazi-binding/src/lib.rs index 575ff39e..ecff73bc 100644 --- a/yazi-binding/src/lib.rs +++ b/yazi-binding/src/lib.rs @@ -1,3 +1,7 @@ +#![allow(clippy::unit_arg)] + mod macros; -yazi_macro::mod_flat!(color error icon id stage style url urn); +yazi_macro::mod_pub!(elements); + +yazi_macro::mod_flat!(cha color composer error file icon id permit runtime stage style url urn); diff --git a/yazi-binding/src/macros.rs b/yazi-binding/src/macros.rs index efb021c5..08f00ed0 100644 --- a/yazi-binding/src/macros.rs +++ b/yazi-binding/src/macros.rs @@ -1,3 +1,30 @@ +#[macro_export] +macro_rules! runtime { + ($lua:ident) => {{ + use mlua::ExternalError; + $lua.app_data_ref::<$crate::Runtime>().ok_or_else(|| "Runtime not found".into_lua_err()) + }}; +} + +#[macro_export] +macro_rules! runtime_mut { + ($lua:ident) => {{ + use mlua::ExternalError; + $lua.app_data_mut::<$crate::Runtime>().ok_or_else(|| "Runtime not found".into_lua_err()) + }}; +} + +#[macro_export] +macro_rules! deprecate { + ($lua:ident, $tt:tt) => {{ + let id = match $crate::runtime!($lua)?.current() { + Some(id) => &format!("`{id}.yazi` plugin"), + None => "`init.lua` config", + }; + yazi_proxy::deprecate!(format!($tt, id)); + }}; +} + #[macro_export] macro_rules! cached_field { ($fields:ident, $key:ident, $value:expr) => { @@ -18,6 +45,34 @@ macro_rules! cached_field { }; } +#[macro_export] +macro_rules! impl_area_method { + ($methods:ident) => { + $methods.add_function_mut( + "area", + |lua, (ud, area): (mlua::AnyUserData, Option)| { + use mlua::IntoLua; + if let Some(v) = area { + ud.borrow_mut::()?.area = $crate::elements::Area::try_from(v)?; + ud.into_lua(lua) + } else { + ud.borrow::()?.area.into_lua(lua) + } + }, + ); + }; +} + +#[macro_export] +macro_rules! impl_style_method { + ($methods:ident, $($field:tt).+) => { + $methods.add_function_mut("style", |_, (ud, value): (mlua::AnyUserData, mlua::Value)| { + ud.borrow_mut::()?.$($field).+ = $crate::Style::try_from(value)?.0; + Ok(ud) + }); + }; +} + #[macro_export] macro_rules! impl_style_shorthands { ($methods:ident, $($field:tt).+) => { @@ -85,3 +140,32 @@ macro_rules! impl_style_shorthands { }); }; } + +#[macro_export] +macro_rules! impl_file_fields { + ($fields:ident) => { + $crate::cached_field!($fields, cha, |_, me| Ok($crate::Cha(me.cha))); + $crate::cached_field!($fields, url, |_, me| Ok($crate::Url::new(me.url_owned()))); + $crate::cached_field!($fields, link_to, |_, me| Ok(me.link_to.clone().map($crate::Url::new))); + + $crate::cached_field!($fields, name, |lua, me| { + Some(me.name()) + .filter(|s| !s.is_empty()) + .map(|s| lua.create_string(s.as_encoded_bytes())) + .transpose() + }); + }; +} + +#[macro_export] +macro_rules! impl_file_methods { + ($methods:ident) => { + $methods.add_method("hash", |_, me, ()| Ok(me.hash_u64())); + + $methods.add_method("icon", |_, me, ()| { + use $crate::Icon; + // TODO: use a cache + Ok(yazi_config::THEME.icon.matches(me).map(Icon::from)) + }); + }; +} diff --git a/yazi-plugin/src/bindings/permit.rs b/yazi-binding/src/permit.rs similarity index 100% rename from yazi-plugin/src/bindings/permit.rs rename to yazi-binding/src/permit.rs diff --git a/yazi-plugin/src/runtime.rs b/yazi-binding/src/runtime.rs similarity index 100% rename from yazi-plugin/src/runtime.rs rename to yazi-binding/src/runtime.rs diff --git a/yazi-core/Cargo.toml b/yazi-core/Cargo.toml index 367c4646..4e1d4a34 100644 --- a/yazi-core/Cargo.toml +++ b/yazi-core/Cargo.toml @@ -16,6 +16,7 @@ yazi-config = { path = "../yazi-config", version = "25.6.11" } yazi-dds = { path = "../yazi-dds", version = "25.6.11" } yazi-fs = { path = "../yazi-fs", version = "25.6.11" } yazi-macro = { path = "../yazi-macro", version = "25.6.11" } +yazi-parser = { path = "../yazi-parser", version = "25.6.11" } yazi-plugin = { path = "../yazi-plugin", version = "25.6.11" } yazi-proxy = { path = "../yazi-proxy", version = "25.6.11" } yazi-scheduler = { path = "../yazi-scheduler", version = "25.6.11" } @@ -25,11 +26,10 @@ yazi-widgets = { path = "../yazi-widgets", version = "25.6.11" } # External dependencies anyhow = { workspace = true } -bitflags = { workspace = true } crossterm = { workspace = true } futures = { workspace = true } indexmap = { workspace = true } -notify = { version = "8.0.0", default-features = false, features = [ "macos_fsevent" ] } +notify = { version = "8.1.0", default-features = false, features = [ "macos_fsevent" ] } parking_lot = { workspace = true } ratatui = { workspace = true } scopeguard = { workspace = true } diff --git a/yazi-core/src/cmp/commands/arrow.rs b/yazi-core/src/cmp/commands/arrow.rs index 6e00842e..eb81556c 100644 --- a/yazi-core/src/cmp/commands/arrow.rs +++ b/yazi-core/src/cmp/commands/arrow.rs @@ -1,22 +1,12 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; -use yazi_widgets::{Scrollable, Step}; +use yazi_parser::cmp::ArrowOpt; +use yazi_widgets::Scrollable; use crate::cmp::Cmp; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - impl Cmp { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { render!(self.scroll(opt.step)); } } diff --git a/yazi-core/src/cmp/commands/close.rs b/yazi-core/src/cmp/commands/close.rs index 6e1d3c46..e6d06b32 100644 --- a/yazi-core/src/cmp/commands/close.rs +++ b/yazi-core/src/cmp/commands/close.rs @@ -1,25 +1,14 @@ use std::mem; use yazi_macro::render; +use yazi_parser::cmp::CloseOpt; use yazi_proxy::InputProxy; -use yazi_shared::event::CmdCow; use crate::cmp::Cmp; -struct Opt { - submit: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } -} -impl From for Opt { - fn from(submit: bool) -> Self { Self { submit } } -} - impl Cmp { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt) { + pub fn close(&mut self, opt: CloseOpt) { if let Some(s) = self.selected().filter(|_| opt.submit) { InputProxy::complete(s, self.ticket); } diff --git a/yazi-core/src/cmp/commands/show.rs b/yazi-core/src/cmp/commands/show.rs index 23b933a3..1ede77d8 100644 --- a/yazi-core/src/cmp/commands/show.rs +++ b/yazi-core/src/cmp/commands/show.rs @@ -1,38 +1,17 @@ -use std::{borrow::Cow, mem, ops::ControlFlow, path::PathBuf}; +use std::{mem, ops::ControlFlow}; use yazi_macro::render; +use yazi_parser::cmp::ShowOpt; use yazi_proxy::options::CmpItem; -use yazi_shared::{Id, event::{Cmd, CmdCow, Data}, osstr_contains, osstr_starts_with}; +use yazi_shared::{osstr_contains, osstr_starts_with}; use crate::cmp::Cmp; const LIMIT: usize = 30; -struct Opt { - cache: Vec, - cache_name: PathBuf, - word: Cow<'static, str>, - ticket: Id, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - cache: c.take_any("cache").unwrap_or_default(), - cache_name: c.take_any("cache-name").unwrap_or_default(), - word: c.take_str("word").unwrap_or_default(), - ticket: c.get("ticket").and_then(Data::as_id).unwrap_or_default(), - } - } -} - -impl From for Opt { - fn from(c: Cmd) -> Self { Self::from(CmdCow::from(c)) } -} - impl Cmp { #[yazi_codegen::command] - pub fn show(&mut self, opt: Opt) { + pub fn show(&mut self, opt: ShowOpt) { if self.ticket != opt.ticket { return; } diff --git a/yazi-core/src/cmp/commands/trigger.rs b/yazi-core/src/cmp/commands/trigger.rs index d74f3640..01534fba 100644 --- a/yazi-core/src/cmp/commands/trigger.rs +++ b/yazi-core/src/cmp/commands/trigger.rs @@ -1,30 +1,17 @@ -use std::{borrow::Cow, ffi::OsString, mem, path::{MAIN_SEPARATOR_STR, Path, PathBuf}}; +use std::{ffi::OsString, mem, path::{MAIN_SEPARATOR_STR, Path, PathBuf}}; use tokio::fs; use yazi_fs::{CWD, expand_path}; use yazi_macro::{emit, render}; +use yazi_parser::cmp::TriggerOpt; use yazi_proxy::options::CmpItem; -use yazi_shared::{Id, event::{Cmd, CmdCow, Data}, natsort}; +use yazi_shared::{event::Cmd, natsort}; use crate::cmp::Cmp; -struct Opt { - word: Cow<'static, str>, - ticket: Id, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - word: c.take_first_str().unwrap_or_default(), - ticket: c.get("ticket").and_then(Data::as_id).unwrap_or_default(), - } - } -} - impl Cmp { #[yazi_codegen::command] - pub fn trigger(&mut self, opt: Opt) { + pub fn trigger(&mut self, opt: TriggerOpt) { if opt.ticket < self.ticket { return; } diff --git a/yazi-core/src/confirm/commands/arrow.rs b/yazi-core/src/confirm/commands/arrow.rs index 64dbb5dc..ef36a514 100644 --- a/yazi-core/src/confirm/commands/arrow.rs +++ b/yazi-core/src/confirm/commands/arrow.rs @@ -1,22 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; -use yazi_widgets::Step; +use yazi_parser::confirm::ArrowOpt; use crate::{confirm::Confirm, mgr::Mgr}; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - impl Confirm { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt, mgr: &Mgr) { + pub fn arrow(&mut self, opt: ArrowOpt, mgr: &Mgr) { let area = mgr.area(self.position); let len = self.list.line_count(area.width); diff --git a/yazi-core/src/confirm/commands/close.rs b/yazi-core/src/confirm/commands/close.rs index c9b52c80..42e1010f 100644 --- a/yazi-core/src/confirm/commands/close.rs +++ b/yazi-core/src/confirm/commands/close.rs @@ -1,22 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::confirm::CloseOpt; use crate::confirm::Confirm; -struct Opt { - submit: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } -} -impl From for Opt { - fn from(submit: bool) -> Self { Self { submit } } -} - impl Confirm { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt) { + pub fn close(&mut self, opt: CloseOpt) { if let Some(cb) = self.callback.take() { _ = cb.send(opt.submit); } diff --git a/yazi-core/src/confirm/commands/show.rs b/yazi-core/src/confirm/commands/show.rs index c4b6e076..7f80a2a8 100644 --- a/yazi-core/src/confirm/commands/show.rs +++ b/yazi-core/src/confirm/commands/show.rs @@ -1,26 +1,11 @@ -use tokio::sync::oneshot; -use yazi_config::popup::ConfirmCfg; use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::confirm::ShowOpt; use crate::confirm::Confirm; -pub struct Opt { - cfg: ConfirmCfg, - tx: oneshot::Sender, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) - } -} - impl Confirm { - pub fn show(&mut self, opt: impl TryInto) { - let Ok(opt): Result = opt.try_into() else { + pub fn show(&mut self, opt: impl TryInto) { + let Ok(opt): Result = opt.try_into() else { return; }; diff --git a/yazi-core/src/help/commands/arrow.rs b/yazi-core/src/help/commands/arrow.rs index 903bdf2b..84eaea31 100644 --- a/yazi-core/src/help/commands/arrow.rs +++ b/yazi-core/src/help/commands/arrow.rs @@ -1,27 +1,13 @@ use yazi_adapter::Dimension; use yazi_macro::render; -use yazi_shared::event::CmdCow; -use yazi_widgets::{Scrollable, Step}; +use yazi_parser::help::ArrowOpt; +use yazi_widgets::Scrollable; use crate::help::{HELP_MARGIN, Help}; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - -impl From for Opt { - fn from(n: isize) -> Self { Self { step: n.into() } } -} - impl Help { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { render!(self.scroll(opt.step)); } } diff --git a/yazi-core/src/input/commands/close.rs b/yazi-core/src/input/commands/close.rs index 816c012f..9be627b0 100644 --- a/yazi-core/src/input/commands/close.rs +++ b/yazi-core/src/input/commands/close.rs @@ -1,23 +1,13 @@ use yazi_macro::render; +use yazi_parser::input::CloseOpt; use yazi_proxy::CmpProxy; -use yazi_shared::{errors::InputError, event::CmdCow}; +use yazi_shared::errors::InputError; use crate::input::Input; -struct Opt { - submit: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } -} -impl From for Opt { - fn from(submit: bool) -> Self { Self { submit } } -} - impl Input { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt) { + pub fn close(&mut self, opt: CloseOpt) { self.visible = false; self.ticket.next(); diff --git a/yazi-core/src/input/commands/escape.rs b/yazi-core/src/input/commands/escape.rs index 03811ddb..6ba4a548 100644 --- a/yazi-core/src/input/commands/escape.rs +++ b/yazi-core/src/input/commands/escape.rs @@ -1,22 +1,13 @@ use yazi_macro::render; +use yazi_parser::input::EscapeOpt; use yazi_proxy::CmpProxy; -use yazi_shared::event::CmdCow; use yazi_widgets::input::InputOp; use crate::input::Input; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} - impl Input { #[yazi_codegen::command] - pub fn escape(&mut self, _: Opt) { + pub fn escape(&mut self, _: EscapeOpt) { use yazi_widgets::input::InputMode as M; let mode = self.snap().mode; diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index 80b29355..d925ef36 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -1,27 +1,14 @@ -use tokio::sync::mpsc; -use yazi_config::{YAZI, popup::InputCfg}; +use yazi_config::YAZI; use yazi_macro::render; -use yazi_shared::{errors::InputError, event::CmdCow}; +use yazi_parser::input::ShowOpt; +use yazi_shared::errors::InputError; use yazi_widgets::input::InputCallback; use crate::input::Input; -pub struct Opt { - cfg: InputCfg, - tx: mpsc::UnboundedSender>, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) - } -} - impl Input { - pub fn show(&mut self, opt: impl TryInto) { - let Ok(opt): Result = opt.try_into() else { return }; + pub fn show(&mut self, opt: impl TryInto) { + let Ok(opt): Result = opt.try_into() else { return }; self.close(false); self.visible = true; diff --git a/yazi-core/src/mgr/commands/close.rs b/yazi-core/src/mgr/commands/close.rs index becfd17a..45802450 100644 --- a/yazi-core/src/mgr/commands/close.rs +++ b/yazi-core/src/mgr/commands/close.rs @@ -1,17 +1,10 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::CloseOpt; -use crate::{mgr::{Mgr, commands::quit}, tasks::Tasks}; - -#[derive(Default)] -struct Opt(quit::Opt); - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self(c.into()) } -} +use crate::{mgr::Mgr, tasks::Tasks}; impl Mgr { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt, tasks: &Tasks) { + pub fn close(&mut self, opt: CloseOpt, tasks: &Tasks) { if self.tabs.len() > 1 { return self.tabs.close(self.tabs.cursor); } diff --git a/yazi-core/src/mgr/commands/create.rs b/yazi-core/src/mgr/commands/create.rs index 4307ab5f..d216670c 100644 --- a/yazi-core/src/mgr/commands/create.rs +++ b/yazi-core/src/mgr/commands/create.rs @@ -2,23 +2,15 @@ use anyhow::Result; use tokio::fs; use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, realname}; +use yazi_parser::mgr::CreateOpt; use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER}; -use yazi_shared::{event::CmdCow, url::{Url, UrnBuf}}; +use yazi_shared::url::{Url, UrnBuf}; use crate::mgr::Mgr; -struct Opt { - dir: bool, - force: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } -} - impl Mgr { #[yazi_codegen::command] - pub fn create(&self, opt: Opt) { + pub fn create(&self, opt: CreateOpt) { let cwd = self.cwd().to_owned(); let mut input = InputProxy::show(InputCfg::create(opt.dir)); diff --git a/yazi-core/src/mgr/commands/hardlink.rs b/yazi-core/src/mgr/commands/hardlink.rs index 892262d0..16a9c302 100644 --- a/yazi-core/src/mgr/commands/hardlink.rs +++ b/yazi-core/src/mgr/commands/hardlink.rs @@ -1,19 +1,10 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::HardlinkOpt; use crate::{mgr::Mgr, tasks::Tasks}; -struct Opt { - force: bool, - follow: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } -} - impl Mgr { #[yazi_codegen::command] - pub fn hardlink(&mut self, opt: Opt, tasks: &Tasks) { + pub fn hardlink(&mut self, opt: HardlinkOpt, tasks: &Tasks) { if self.yanked.cut { return; } diff --git a/yazi-core/src/mgr/commands/link.rs b/yazi-core/src/mgr/commands/link.rs index a7ca7490..f4339d9c 100644 --- a/yazi-core/src/mgr/commands/link.rs +++ b/yazi-core/src/mgr/commands/link.rs @@ -1,19 +1,10 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::LinkOpt; use crate::{mgr::Mgr, tasks::Tasks}; -struct Opt { - relative: bool, - force: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { relative: c.bool("relative"), force: c.bool("force") } } -} - impl Mgr { #[yazi_codegen::command] - pub fn link(&mut self, opt: Opt, tasks: &Tasks) { + pub fn link(&mut self, opt: LinkOpt, tasks: &Tasks) { if self.yanked.cut { return; } diff --git a/yazi-core/src/mgr/commands/open.rs b/yazi-core/src/mgr/commands/open.rs index b48f2549..6906b8c9 100644 --- a/yazi-core/src/mgr/commands/open.rs +++ b/yazi-core/src/mgr/commands/open.rs @@ -3,27 +3,16 @@ use std::{borrow::Cow, iter}; use tracing::error; use yazi_config::{YAZI, popup::PickCfg}; use yazi_fs::File; +use yazi_parser::mgr::OpenOpt; use yazi_plugin::isolate; use yazi_proxy::{MgrProxy, PickProxy, TasksProxy, options::OpenDoOpt}; use yazi_shared::{MIME_DIR, event::CmdCow, url::Url}; use crate::{mgr::Mgr, tab::Folder, tasks::Tasks}; -#[derive(Clone, Copy)] -pub(super) struct Opt { - pub(super) interactive: bool, - pub(super) hovered: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { interactive: c.bool("interactive"), hovered: c.bool("hovered") } - } -} - impl Mgr { #[yazi_codegen::command] - pub fn open(&mut self, opt: Opt, tasks: &Tasks) { + pub fn open(&mut self, opt: OpenOpt, tasks: &Tasks) { if !self.active_mut().try_escape_visual() { return; } diff --git a/yazi-core/src/mgr/commands/paste.rs b/yazi-core/src/mgr/commands/paste.rs index 39c05838..6a94101f 100644 --- a/yazi-core/src/mgr/commands/paste.rs +++ b/yazi-core/src/mgr/commands/paste.rs @@ -1,19 +1,10 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::PasteOpt; use crate::{mgr::Mgr, tasks::Tasks}; -struct Opt { - force: bool, - follow: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } -} - impl Mgr { #[yazi_codegen::command] - pub fn paste(&mut self, opt: Opt, tasks: &Tasks) { + pub fn paste(&mut self, opt: PasteOpt, tasks: &Tasks) { let (src, dest) = (self.yanked.iter().collect::>(), self.cwd()); if self.yanked.cut { diff --git a/yazi-core/src/mgr/commands/peek.rs b/yazi-core/src/mgr/commands/peek.rs index 307579d5..3c33d447 100644 --- a/yazi-core/src/mgr/commands/peek.rs +++ b/yazi-core/src/mgr/commands/peek.rs @@ -1,33 +1,11 @@ +use yazi_parser::mgr::PeekOpt; use yazi_proxy::HIDER; -use yazi_shared::{event::{CmdCow, Data}, url::Url}; use crate::mgr::Mgr; -#[derive(Debug, Default)] -struct Opt { - skip: Option, - force: bool, - only_if: Option, - upper_bound: bool, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - skip: c.first().and_then(Data::as_usize), - force: c.bool("force"), - only_if: c.take_url("only-if"), - upper_bound: c.bool("upper-bound"), - } - } -} -impl From for Opt { - fn from(force: bool) -> Self { Self { force, ..Default::default() } } -} - impl Mgr { #[yazi_codegen::command] - pub fn peek(&mut self, opt: Opt) { + pub fn peek(&mut self, opt: PeekOpt) { let Some(hovered) = self.hovered().cloned() else { return self.active_mut().preview.reset(); }; diff --git a/yazi-core/src/mgr/commands/quit.rs b/yazi-core/src/mgr/commands/quit.rs index 58234303..fc664142 100644 --- a/yazi-core/src/mgr/commands/quit.rs +++ b/yazi-core/src/mgr/commands/quit.rs @@ -4,35 +4,15 @@ use tokio::{select, time}; use yazi_boot::ARGS; use yazi_config::popup::ConfirmCfg; use yazi_macro::emit; +use yazi_parser::mgr::{OpenOpt, QuitOpt}; use yazi_proxy::ConfirmProxy; -use yazi_shared::{event::{CmdCow, Data, EventQuit}, url::Url}; +use yazi_shared::{event::EventQuit, url::Url}; use crate::{mgr::Mgr, tasks::Tasks}; -#[derive(Default)] -pub(super) struct Opt { - pub(super) code: i32, - pub(super) no_cwd_file: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { - code: c.get("code").and_then(Data::as_i32).unwrap_or_default(), - no_cwd_file: c.bool("no-cwd-file"), - } - } -} - -impl From for EventQuit { - fn from(value: Opt) -> Self { - EventQuit { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() } - } -} - impl Mgr { #[yazi_codegen::command] - pub fn quit(&self, opt: Opt, tasks: &Tasks) { + pub fn quit(&self, opt: QuitOpt, tasks: &Tasks) { let event = opt.into(); let ongoing = tasks.ongoing().clone(); @@ -74,7 +54,7 @@ impl Mgr { }); } - pub(super) fn quit_with_selected<'a, I>(opt: super::open::Opt, selected: I) -> bool + pub(super) fn quit_with_selected<'a, I>(opt: OpenOpt, selected: I) -> bool where I: Iterator, { diff --git a/yazi-core/src/mgr/commands/remove.rs b/yazi-core/src/mgr/commands/remove.rs index 19a27289..922ad344 100644 --- a/yazi-core/src/mgr/commands/remove.rs +++ b/yazi-core/src/mgr/commands/remove.rs @@ -1,30 +1,12 @@ use yazi_config::popup::ConfirmCfg; +use yazi_parser::mgr::RemoveOpt; use yazi_proxy::{ConfirmProxy, MgrProxy}; -use yazi_shared::{event::CmdCow, url::Url}; use crate::{mgr::Mgr, tasks::Tasks}; -struct Opt { - force: bool, - permanently: bool, - hovered: bool, - targets: Vec, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - force: c.bool("force"), - permanently: c.bool("permanently"), - hovered: c.bool("hovered"), - targets: c.take_any("targets").unwrap_or_default(), - } - } -} - impl Mgr { #[yazi_codegen::command] - pub fn remove(&mut self, mut opt: Opt, tasks: &Tasks) { + pub fn remove(&mut self, mut opt: RemoveOpt, tasks: &Tasks) { if !self.active_mut().try_escape_visual() { return; } @@ -55,7 +37,7 @@ impl Mgr { } #[yazi_codegen::command] - pub fn remove_do(&mut self, opt: Opt, tasks: &Tasks) { + pub fn remove_do(&mut self, opt: RemoveOpt, tasks: &Tasks) { self.tabs.iter_mut().for_each(|t| { t.selected.remove_many(&opt.targets); }); diff --git a/yazi-core/src/mgr/commands/rename.rs b/yazi-core/src/mgr/commands/rename.rs index 48ebb73a..4f3701e1 100644 --- a/yazi-core/src/mgr/commands/rename.rs +++ b/yazi-core/src/mgr/commands/rename.rs @@ -1,37 +1,18 @@ -use std::borrow::Cow; - use anyhow::Result; use tokio::fs; use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_dds::Pubsub; use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, paths_to_same_file, realname}; use yazi_macro::err; +use yazi_parser::mgr::RenameOpt; use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER}; -use yazi_shared::{Id, event::CmdCow, url::{Url, UrnBuf}}; +use yazi_shared::{Id, url::{Url, UrnBuf}}; use crate::mgr::Mgr; -struct Opt { - hovered: bool, - force: bool, - empty: Cow<'static, str>, - cursor: Cow<'static, str>, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - hovered: c.bool("hovered"), - force: c.bool("force"), - empty: c.take_str("empty").unwrap_or_default(), - cursor: c.take_str("cursor").unwrap_or_default(), - } - } -} - impl Mgr { #[yazi_codegen::command] - pub fn rename(&mut self, opt: Opt) { + pub fn rename(&mut self, opt: RenameOpt) { if !self.active_mut().try_escape_visual() { return; } else if !opt.hovered && !self.active().selected.is_empty() { diff --git a/yazi-core/src/mgr/commands/seek.rs b/yazi-core/src/mgr/commands/seek.rs index b56e9a55..fc637996 100644 --- a/yazi-core/src/mgr/commands/seek.rs +++ b/yazi-core/src/mgr/commands/seek.rs @@ -1,21 +1,12 @@ use yazi_config::YAZI; +use yazi_parser::mgr::SeekOpt; use yazi_plugin::isolate; -use yazi_shared::event::{CmdCow, Data}; use crate::mgr::Mgr; -#[derive(Debug)] -struct Opt { - units: i16, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { units: c.first().and_then(Data::as_i16).unwrap_or(0) } } -} - impl Mgr { #[yazi_codegen::command] - pub fn seek(&mut self, opt: Opt) { + pub fn seek(&mut self, opt: SeekOpt) { let Some(hovered) = self.hovered() else { return self.active_mut().preview.reset(); }; diff --git a/yazi-core/src/mgr/commands/spot.rs b/yazi-core/src/mgr/commands/spot.rs index 8105e186..67cca11a 100644 --- a/yazi-core/src/mgr/commands/spot.rs +++ b/yazi-core/src/mgr/commands/spot.rs @@ -1,18 +1,10 @@ -use yazi_shared::event::{CmdCow, Data}; +use yazi_parser::mgr::SpotOpt; use crate::mgr::Mgr; -struct Opt { - skip: Option, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { skip: c.get("skip").and_then(Data::as_usize) } } -} - impl Mgr { #[yazi_codegen::command] - pub fn spot(&mut self, opt: Opt) { + pub fn spot(&mut self, opt: SpotOpt) { let Some(hovered) = self.hovered().cloned() else { return; }; diff --git a/yazi-core/src/mgr/commands/tab_close.rs b/yazi-core/src/mgr/commands/tab_close.rs index 59cc62df..c9d644e1 100644 --- a/yazi-core/src/mgr/commands/tab_close.rs +++ b/yazi-core/src/mgr/commands/tab_close.rs @@ -1,23 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::{CmdCow, Data}; +use yazi_parser::mgr::TabCloseOpt; use crate::mgr::Tabs; -struct Opt { - idx: usize, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { idx: c.first().and_then(Data::as_usize).unwrap_or(0) } } -} - -impl From for Opt { - fn from(idx: usize) -> Self { Self { idx } } -} - impl Tabs { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt) { + pub fn close(&mut self, opt: TabCloseOpt) { let len = self.items.len(); if len < 2 || opt.idx >= len { return; diff --git a/yazi-core/src/mgr/commands/tab_create.rs b/yazi-core/src/mgr/commands/tab_create.rs index 44347adf..432388d9 100644 --- a/yazi-core/src/mgr/commands/tab_create.rs +++ b/yazi-core/src/mgr/commands/tab_create.rs @@ -1,35 +1,14 @@ -use yazi_boot::BOOT; -use yazi_fs::expand_path; use yazi_macro::render; +use yazi_parser::{mgr::TabCreateOpt, tab::CdSource}; use yazi_proxy::AppProxy; -use yazi_shared::{event::CmdCow, url::Url}; -use crate::{mgr::Tabs, tab::{Tab, commands::CdSource}}; +use crate::{mgr::Tabs, tab::Tab}; const MAX_TABS: usize = 9; -struct Opt { - wd: Option, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - if c.bool("current") { - return Self { wd: None }; - } - let Some(mut wd) = c.take_first_url() else { - return Self { wd: Some(Url::from(&BOOT.cwds[0])) }; - }; - if wd.is_regular() && !c.bool("raw") { - wd = Url::from(expand_path(wd)); - } - Self { wd: Some(wd) } - } -} - impl Tabs { #[yazi_codegen::command] - pub fn create(&mut self, opt: Opt) { + pub fn create(&mut self, opt: TabCreateOpt) { if self.items.len() >= MAX_TABS { AppProxy::notify_warn("Too many tabs", "You can only open up to 9 tabs at the same time."); return; diff --git a/yazi-core/src/mgr/commands/tab_swap.rs b/yazi-core/src/mgr/commands/tab_swap.rs index 11c111ca..003fa34a 100644 --- a/yazi-core/src/mgr/commands/tab_swap.rs +++ b/yazi-core/src/mgr/commands/tab_swap.rs @@ -1,19 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::{CmdCow, Data}; +use yazi_parser::mgr::TabSwapOpt; use crate::mgr::Tabs; -struct Opt { - step: isize, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } -} - impl Tabs { #[yazi_codegen::command] - pub fn swap(&mut self, opt: Opt) { + pub fn swap(&mut self, opt: TabSwapOpt) { let idx = opt.step.saturating_add_unsigned(self.cursor).rem_euclid(self.items.len() as _) as _; if idx == self.cursor { return; diff --git a/yazi-core/src/mgr/commands/tab_switch.rs b/yazi-core/src/mgr/commands/tab_switch.rs index c174ebdf..1508f454 100644 --- a/yazi-core/src/mgr/commands/tab_switch.rs +++ b/yazi-core/src/mgr/commands/tab_switch.rs @@ -1,22 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::{CmdCow, Data}; +use yazi_parser::mgr::TabSwitchOpt; use crate::mgr::Tabs; -struct Opt { - step: isize, - relative: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(Data::as_isize).unwrap_or(0), relative: c.bool("relative") } - } -} - impl Tabs { #[yazi_codegen::command] - pub fn switch(&mut self, opt: Opt) { + pub fn switch(&mut self, opt: TabSwitchOpt) { let idx = if opt.relative { opt.step.saturating_add_unsigned(self.cursor).rem_euclid(self.items.len() as _) as _ } else { diff --git a/yazi-core/src/mgr/commands/unyank.rs b/yazi-core/src/mgr/commands/unyank.rs index 054a17bb..e63efdd5 100644 --- a/yazi-core/src/mgr/commands/unyank.rs +++ b/yazi-core/src/mgr/commands/unyank.rs @@ -1,20 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::UnyankOpt; use crate::mgr::Mgr; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} - impl Mgr { #[yazi_codegen::command] - pub fn unyank(&mut self, _: Opt) { + pub fn unyank(&mut self, _: UnyankOpt) { let repeek = self.hovered().is_some_and(|f| f.is_dir() && self.yanked.contains_in(&f.url)); self.yanked.clear(); diff --git a/yazi-core/src/mgr/commands/update_files.rs b/yazi-core/src/mgr/commands/update_files.rs index e8754c93..3a3dec1c 100644 --- a/yazi-core/src/mgr/commands/update_files.rs +++ b/yazi-core/src/mgr/commands/update_files.rs @@ -1,23 +1,11 @@ use yazi_fs::FilesOp; use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::UpdateFilesOpt; use crate::{mgr::{LINKED, Mgr}, tab::Folder, tasks::Tasks}; -pub struct Opt { - op: FilesOp, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { op: c.take_any("op").ok_or(())? }) - } -} - impl Mgr { - pub fn update_files(&mut self, opt: impl TryInto, tasks: &Tasks) { + pub fn update_files(&mut self, opt: impl TryInto, tasks: &Tasks) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-core/src/mgr/commands/update_mimes.rs b/yazi-core/src/mgr/commands/update_mimes.rs index 36937cc5..59e09524 100644 --- a/yazi-core/src/mgr/commands/update_mimes.rs +++ b/yazi-core/src/mgr/commands/update_mimes.rs @@ -2,25 +2,13 @@ use std::collections::HashMap; use tracing::error; use yazi_macro::render; -use yazi_shared::event::{CmdCow, Data, DataKey}; +use yazi_parser::mgr::UpdateMimesOpt; use crate::{mgr::{LINKED, Mgr}, tasks::Tasks}; -pub struct Opt { - updates: HashMap, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { updates: c.try_take("updates").and_then(Data::into_dict).ok_or(())? }) - } -} - impl Mgr { - pub fn update_mimes(&mut self, opt: impl TryInto, tasks: &Tasks) { - let Ok(opt): Result = opt.try_into() else { + pub fn update_mimes(&mut self, opt: impl TryInto, tasks: &Tasks) { + let Ok(opt): Result = opt.try_into() else { return error!("invalid arguments for update_mimes"); }; diff --git a/yazi-core/src/mgr/commands/update_paged.rs b/yazi-core/src/mgr/commands/update_paged.rs index 95dd080f..4cf25b32 100644 --- a/yazi-core/src/mgr/commands/update_paged.rs +++ b/yazi-core/src/mgr/commands/update_paged.rs @@ -1,26 +1,10 @@ -use yazi_shared::{event::{CmdCow, Data}, url::Url}; +use yazi_parser::mgr::UpdatePagedOpt; use crate::{mgr::Mgr, tasks::Tasks}; -#[derive(Default)] -pub struct Opt { - page: Option, - only_if: Option, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { page: c.first().and_then(Data::as_usize), only_if: c.take_url("only-if") } - } -} - -impl From<()> for Opt { - fn from(_: ()) -> Self { Self::default() } -} - impl Mgr { - pub fn update_paged(&mut self, opt: impl TryInto, tasks: &Tasks) { - let Ok(opt): Result = opt.try_into() else { + pub fn update_paged(&mut self, opt: impl TryInto, tasks: &Tasks) { + let Ok(opt): Result = opt.try_into() else { return; }; diff --git a/yazi-core/src/mgr/commands/update_tasks.rs b/yazi-core/src/mgr/commands/update_tasks.rs index e32e4757..e70e6962 100644 --- a/yazi-core/src/mgr/commands/update_tasks.rs +++ b/yazi-core/src/mgr/commands/update_tasks.rs @@ -1,21 +1,9 @@ -use yazi_shared::{event::CmdCow, url::Url}; +use yazi_parser::mgr::UpdateTasksOpt; use crate::mgr::Mgr; -pub struct Opt { - urls: Vec, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { urls: c.take_any("urls").ok_or(())? }) - } -} - impl Mgr { - pub fn update_tasks(&mut self, opt: impl TryInto) { + pub fn update_tasks(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-core/src/mgr/commands/update_yanked.rs b/yazi-core/src/mgr/commands/update_yanked.rs index 09488d29..4cd8f5c2 100644 --- a/yazi-core/src/mgr/commands/update_yanked.rs +++ b/yazi-core/src/mgr/commands/update_yanked.rs @@ -1,30 +1,10 @@ -use std::collections::HashSet; - use yazi_macro::render; -use yazi_shared::{event::CmdCow, url::Url}; +use yazi_parser::mgr::UpdateYankedOpt; use crate::mgr::{Mgr, Yanked}; -#[derive(Default)] -pub struct Opt { - cut: bool, - urls: HashSet, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - if let Some(iter) = c.take_any::("urls") { - Ok(Self { urls: iter.urls.into_iter().collect(), cut: iter.cut }) - } else { - Err(()) - } - } -} - impl Mgr { - pub fn update_yanked(&mut self, opt: impl TryInto) { + pub fn update_yanked(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return }; if opt.urls.is_empty() && self.yanked.is_empty() { diff --git a/yazi-core/src/mgr/commands/watch.rs b/yazi-core/src/mgr/commands/watch.rs index 1e493c03..48fcd16b 100644 --- a/yazi-core/src/mgr/commands/watch.rs +++ b/yazi-core/src/mgr/commands/watch.rs @@ -1,21 +1,12 @@ use std::collections::HashSet; -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::WatchOpt; use crate::mgr::Mgr; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from((): ()) -> Self { Self } -} - impl Mgr { #[yazi_codegen::command] - pub fn watch(&mut self, _: Opt) { + pub fn watch(&mut self, _: WatchOpt) { let mut to_watch = HashSet::with_capacity(3 * self.tabs.len()); for tab in self.tabs.iter() { to_watch.insert(tab.cwd()); diff --git a/yazi-core/src/mgr/commands/yank.rs b/yazi-core/src/mgr/commands/yank.rs index de5af15e..24d779b3 100644 --- a/yazi-core/src/mgr/commands/yank.rs +++ b/yazi-core/src/mgr/commands/yank.rs @@ -1,19 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::mgr::YankOpt; use crate::mgr::{Mgr, Yanked}; -struct Opt { - cut: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut") } } -} - impl Mgr { #[yazi_codegen::command] - pub fn yank(&mut self, opt: Opt) { + pub fn yank(&mut self, opt: YankOpt) { if !self.active_mut().try_escape_visual() { return; } diff --git a/yazi-core/src/mgr/tabs.rs b/yazi-core/src/mgr/tabs.rs index ec517cb8..a1c23563 100644 --- a/yazi-core/src/mgr/tabs.rs +++ b/yazi-core/src/mgr/tabs.rs @@ -4,10 +4,11 @@ use yazi_boot::BOOT; use yazi_dds::Pubsub; use yazi_fs::File; use yazi_macro::err; +use yazi_parser::tab::CdSource; use yazi_proxy::MgrProxy; use yazi_shared::{Id, url::Url}; -use crate::tab::{Folder, Tab, commands::CdSource}; +use crate::tab::{Folder, Tab}; pub struct Tabs { pub cursor: usize, diff --git a/yazi-core/src/notify/commands/tick.rs b/yazi-core/src/notify/commands/tick.rs index 0577aa38..b289d94e 100644 --- a/yazi-core/src/notify/commands/tick.rs +++ b/yazi-core/src/notify/commands/tick.rs @@ -1,36 +1,13 @@ use std::time::Duration; use ratatui::layout::Rect; +use yazi_parser::notify::TickOpt; use yazi_proxy::AppProxy; -use yazi_shared::event::{Cmd, CmdCow, Data}; use crate::notify::Notify; -pub struct Opt { - interval: Duration, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(c: CmdCow) -> Result { - let interval = c.first().and_then(Data::as_f64).ok_or(())?; - if interval < 0.0 { - return Err(()); - } - - Ok(Self { interval: Duration::from_secs_f64(interval) }) - } -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(c: Cmd) -> Result { Self::try_from(CmdCow::from(c)) } -} - impl Notify { - pub fn tick(&mut self, opt: impl TryInto, area: Rect) { + pub fn tick(&mut self, opt: impl TryInto, area: Rect) { self.tick_handle.take().map(|h| h.abort()); let Ok(opt) = opt.try_into() else { return; diff --git a/yazi-core/src/pick/commands/arrow.rs b/yazi-core/src/pick/commands/arrow.rs index a97e9325..979d4c16 100644 --- a/yazi-core/src/pick/commands/arrow.rs +++ b/yazi-core/src/pick/commands/arrow.rs @@ -1,23 +1,13 @@ use yazi_config::YAZI; use yazi_macro::render; -use yazi_shared::event::CmdCow; -use yazi_widgets::{Scrollable, Step}; +use yazi_parser::pick::ArrowOpt; +use yazi_widgets::Scrollable; use crate::pick::Pick; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - impl Pick { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { render!(self.scroll(opt.step)); } } diff --git a/yazi-core/src/pick/commands/close.rs b/yazi-core/src/pick/commands/close.rs index b6333423..bbd29ffd 100644 --- a/yazi-core/src/pick/commands/close.rs +++ b/yazi-core/src/pick/commands/close.rs @@ -1,23 +1,12 @@ use anyhow::anyhow; use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::pick::CloseOpt; use crate::pick::Pick; -struct Opt { - submit: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } -} -impl From for Opt { - fn from(submit: bool) -> Self { Self { submit } } -} - impl Pick { #[yazi_codegen::command] - pub fn close(&mut self, opt: Opt) { + pub fn close(&mut self, opt: CloseOpt) { if let Some(cb) = self.callback.take() { _ = cb.send(if opt.submit { Ok(self.cursor) } else { Err(anyhow!("canceled")) }); } diff --git a/yazi-core/src/pick/commands/show.rs b/yazi-core/src/pick/commands/show.rs index c177acd9..c1edc25c 100644 --- a/yazi-core/src/pick/commands/show.rs +++ b/yazi-core/src/pick/commands/show.rs @@ -1,25 +1,10 @@ -use tokio::sync::oneshot; -use yazi_config::popup::PickCfg; use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::pick::ShowOpt; use crate::pick::Pick; -pub struct Opt { - cfg: PickCfg, - tx: oneshot::Sender>, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) - } -} - impl Pick { - pub fn show(&mut self, opt: impl TryInto) { + pub fn show(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-core/src/spot/commands/arrow.rs b/yazi-core/src/spot/commands/arrow.rs index 87764962..e1eef324 100644 --- a/yazi-core/src/spot/commands/arrow.rs +++ b/yazi-core/src/spot/commands/arrow.rs @@ -1,23 +1,12 @@ use yazi_macro::render; +use yazi_parser::spot::ArrowOpt; use yazi_proxy::MgrProxy; -use yazi_shared::event::CmdCow; -use yazi_widgets::Step; use crate::spot::Spot; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - impl Spot { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { let Some(lock) = &mut self.lock else { return }; let new = opt.step.add(self.skip, lock.len().unwrap_or(u16::MAX as _), 0); diff --git a/yazi-core/src/spot/commands/close.rs b/yazi-core/src/spot/commands/close.rs index c6fb6b52..01212740 100644 --- a/yazi-core/src/spot/commands/close.rs +++ b/yazi-core/src/spot/commands/close.rs @@ -1,17 +1,8 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::spot::CloseOpt; use crate::spot::Spot; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} - impl Spot { #[yazi_codegen::command] - pub fn close(&mut self, _: Opt) { self.reset(); } + pub fn close(&mut self, _: CloseOpt) { self.reset(); } } diff --git a/yazi-core/src/spot/commands/copy.rs b/yazi-core/src/spot/commands/copy.rs index 29044d2b..7dd5ffed 100644 --- a/yazi-core/src/spot/commands/copy.rs +++ b/yazi-core/src/spot/commands/copy.rs @@ -1,21 +1,11 @@ -use std::borrow::Cow; - -use yazi_plugin::CLIPBOARD; -use yazi_shared::event::CmdCow; +use yazi_parser::spot::CopyOpt; +use yazi_widgets::CLIPBOARD; use crate::spot::Spot; -struct Opt { - r#type: Cow<'static, str>, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { Self { r#type: c.take_first_str().unwrap_or_default() } } -} - impl Spot { #[yazi_codegen::command] - pub fn copy(&mut self, opt: Opt) { + pub fn copy(&mut self, opt: CopyOpt) { let Some(lock) = &self.lock else { return }; let Some(table) = lock.table() else { return }; diff --git a/yazi-core/src/spot/commands/swipe.rs b/yazi-core/src/spot/commands/swipe.rs index fe624bec..02f9e2b6 100644 --- a/yazi-core/src/spot/commands/swipe.rs +++ b/yazi-core/src/spot/commands/swipe.rs @@ -1,21 +1,11 @@ -use std::borrow::Cow; - +use yazi_parser::spot::SwipeOpt; use yazi_proxy::{MgrProxy, TabProxy}; -use yazi_shared::event::CmdCow; use crate::spot::Spot; -struct Opt { - step: Cow<'static, str>, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { Self { step: c.take_first_str().unwrap_or_default() } } -} - impl Spot { #[yazi_codegen::command] - pub fn swipe(&mut self, opt: Opt) { + pub fn swipe(&mut self, opt: SwipeOpt) { TabProxy::arrow(opt.step); MgrProxy::spot(None); } diff --git a/yazi-core/src/spot/spot.rs b/yazi-core/src/spot/spot.rs index fde9741c..3c2400d7 100644 --- a/yazi-core/src/spot/spot.rs +++ b/yazi-core/src/spot/spot.rs @@ -4,7 +4,8 @@ use tokio_util::sync::CancellationToken; use yazi_config::YAZI; use yazi_fs::File; use yazi_macro::render; -use yazi_plugin::{isolate, utils::SpotLock}; +use yazi_parser::tab::SpotLock; +use yazi_plugin::isolate; use yazi_shared::url::Url; #[derive(Default)] diff --git a/yazi-core/src/tab/commands/arrow.rs b/yazi-core/src/tab/commands/arrow.rs index 3b9372ef..e385e275 100644 --- a/yazi-core/src/tab/commands/arrow.rs +++ b/yazi-core/src/tab/commands/arrow.rs @@ -1,27 +1,12 @@ use yazi_macro::render; +use yazi_parser::tab::ArrowOpt; use yazi_proxy::MgrProxy; -use yazi_shared::event::CmdCow; -use yazi_widgets::Step; use crate::tab::Tab; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - -impl From for Opt { - fn from(n: isize) -> Self { Self { step: n.into() } } -} - impl Tab { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { if !self.current.arrow(opt.step) { return; } diff --git a/yazi-core/src/tab/commands/back.rs b/yazi-core/src/tab/commands/back.rs index 8318ae86..a5129398 100644 --- a/yazi-core/src/tab/commands/back.rs +++ b/yazi-core/src/tab/commands/back.rs @@ -1,6 +1,6 @@ +use yazi_parser::tab::CdSource; use yazi_shared::event::CmdCow; -use super::cd::CdSource; use crate::tab::Tab; impl Tab { diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index 4a417747..8961ee9c 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -6,34 +6,15 @@ use yazi_config::popup::InputCfg; use yazi_dds::Pubsub; use yazi_fs::{File, FilesOp, expand_path}; use yazi_macro::{err, render}; +use yazi_parser::tab::CdOpt; use yazi_proxy::{CmpProxy, InputProxy, MgrProxy, TabProxy}; -use yazi_shared::{Debounce, errors::InputError, event::CmdCow, url::Url}; +use yazi_shared::{Debounce, errors::InputError, url::Url}; use crate::tab::Tab; -struct Opt { - target: Url, - interactive: bool, - source: CdSource, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - let mut target = c.take_first_url().unwrap_or_default(); - if target.is_regular() && !c.bool("raw") { - target = Url::from(expand_path(target)); - } - Self { target, interactive: c.bool("interactive"), source: CdSource::Cd } - } -} - -impl From<(Url, CdSource)> for Opt { - fn from((target, source): (Url, CdSource)) -> Self { Self { target, interactive: false, source } } -} - impl Tab { #[yazi_codegen::command] - pub fn cd(&mut self, opt: Opt) { + pub fn cd(&mut self, opt: CdOpt) { if !self.try_escape_visual() { return; } @@ -111,20 +92,3 @@ impl Tab { }); } } - -// --- OptSource -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum CdSource { - Tab, - Cd, - Reveal, - Enter, - Leave, - Forward, - Back, -} - -impl CdSource { - #[inline] - fn big_jump(self) -> bool { self == Self::Cd || self == Self::Reveal } -} diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index 9c5d396f..cd0b9621 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -1,29 +1,13 @@ -use std::{borrow::Cow, ffi::{OsStr, OsString}, path::Path}; +use std::{ffi::OsString, path::Path}; -use yazi_plugin::CLIPBOARD; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::CopyOpt; +use yazi_widgets::CLIPBOARD; use crate::tab::Tab; -struct Opt { - r#type: Cow<'static, str>, - separator: Separator, - hovered: bool, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - r#type: c.take_first_str().unwrap_or_default(), - separator: c.str("separator").unwrap_or_default().into(), - hovered: c.bool("hovered"), - } - } -} - impl Tab { #[yazi_codegen::command] - pub fn copy(&mut self, opt: Opt) { + pub fn copy(&mut self, opt: CopyOpt) { if !self.try_escape_visual() { return; } @@ -57,32 +41,3 @@ impl Tab { futures::executor::block_on(CLIPBOARD.set(s)); } } - -// --- Separator -#[derive(Clone, Copy, PartialEq, Eq)] -enum Separator { - Auto, - Unix, -} - -impl From<&str> for Separator { - fn from(value: &str) -> Self { - match value { - "unix" => Self::Unix, - _ => Self::Auto, - } - } -} - -impl Separator { - fn transform + ?Sized>(self, p: &T) -> Cow<'_, OsStr> { - #[cfg(windows)] - if self == Self::Unix { - return match yazi_fs::backslash_to_slash(p.as_ref()) { - Cow::Owned(p) => Cow::Owned(p.into_os_string()), - Cow::Borrowed(p) => Cow::Borrowed(p.as_os_str()), - }; - } - Cow::Borrowed(p.as_ref().as_os_str()) - } -} diff --git a/yazi-core/src/tab/commands/enter.rs b/yazi-core/src/tab/commands/enter.rs index ec373e5d..860ad5be 100644 --- a/yazi-core/src/tab/commands/enter.rs +++ b/yazi-core/src/tab/commands/enter.rs @@ -1,6 +1,6 @@ +use yazi_parser::tab::CdSource; use yazi_shared::event::CmdCow; -use super::cd::CdSource; use crate::tab::Tab; impl Tab { diff --git a/yazi-core/src/tab/commands/escape.rs b/yazi-core/src/tab/commands/escape.rs index bd1234d2..6d70f942 100644 --- a/yazi-core/src/tab/commands/escape.rs +++ b/yazi-core/src/tab/commands/escape.rs @@ -1,39 +1,12 @@ -use bitflags::bitflags; use yazi_macro::{render, render_and}; +use yazi_parser::tab::{EscapeOpt, FilterOpt}; use yazi_proxy::{AppProxy, MgrProxy}; -use yazi_shared::event::CmdCow; use crate::tab::Tab; -bitflags! { - struct Opt: u8 { - const FIND = 0b00001; - const VISUAL = 0b00010; - const FILTER = 0b00100; - const SELECT = 0b01000; - const SEARCH = 0b10000; - } -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - c.args.iter().fold(Opt::empty(), |acc, (k, v)| { - match (k.as_str().unwrap_or(""), v.as_bool().unwrap_or(false)) { - ("all", true) => Self::all(), - ("find", true) => acc | Self::FIND, - ("visual", true) => acc | Self::VISUAL, - ("filter", true) => acc | Self::FILTER, - ("select", true) => acc | Self::SELECT, - ("search", true) => acc | Self::SEARCH, - _ => acc, - } - }) - } -} - impl Tab { #[yazi_codegen::command] - pub fn escape(&mut self, opt: Opt) { + pub fn escape(&mut self, opt: EscapeOpt) { if opt.is_empty() { _ = self.escape_find() || self.escape_visual() @@ -43,19 +16,19 @@ impl Tab { return; } - if opt.contains(Opt::FIND) { + if opt.contains(EscapeOpt::FIND) { self.escape_find(); } - if opt.contains(Opt::VISUAL) { + if opt.contains(EscapeOpt::VISUAL) { self.escape_visual(); } - if opt.contains(Opt::FILTER) { + if opt.contains(EscapeOpt::FILTER) { self.escape_filter(); } - if opt.contains(Opt::SELECT) { + if opt.contains(EscapeOpt::SELECT) { self.escape_select(); } - if opt.contains(Opt::SEARCH) { + if opt.contains(EscapeOpt::SEARCH) { self.escape_search(); } } @@ -76,7 +49,7 @@ impl Tab { return false; } - self.filter_do(super::filter::Opt::default()); + self.filter_do(FilterOpt::default()); render_and!(true) } diff --git a/yazi-core/src/tab/commands/filter.rs b/yazi-core/src/tab/commands/filter.rs index d5af509a..c1f73741 100644 --- a/yazi-core/src/tab/commands/filter.rs +++ b/yazi-core/src/tab/commands/filter.rs @@ -1,35 +1,19 @@ -use std::{borrow::Cow, time::Duration}; +use std::time::Duration; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; use yazi_config::popup::InputCfg; use yazi_fs::FilterCase; use yazi_macro::emit; +use yazi_parser::tab::FilterOpt; use yazi_proxy::InputProxy; -use yazi_shared::{Debounce, errors::InputError, event::{Cmd, CmdCow}}; +use yazi_shared::{Debounce, errors::InputError, event::Cmd}; use crate::tab::Tab; -#[derive(Default)] -pub(super) struct Opt { - pub query: Cow<'static, str>, - pub case: FilterCase, - pub done: bool, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - query: c.take_first_str().unwrap_or_default(), - case: FilterCase::from(&*c), - done: c.bool("done"), - } - } -} - impl Tab { #[yazi_codegen::command] - pub fn filter(&mut self, opt: Opt) { + pub fn filter(&mut self, opt: FilterOpt) { let input = InputProxy::show(InputCfg::filter()); tokio::spawn(async move { diff --git a/yazi-core/src/tab/commands/filter_do.rs b/yazi-core/src/tab/commands/filter_do.rs index fefd4b5e..3582de8d 100644 --- a/yazi-core/src/tab/commands/filter_do.rs +++ b/yazi-core/src/tab/commands/filter_do.rs @@ -1,13 +1,13 @@ use yazi_fs::Filter; use yazi_macro::render; +use yazi_parser::tab::FilterOpt; use yazi_proxy::MgrProxy; -use super::filter::Opt; use crate::tab::Tab; impl Tab { #[yazi_codegen::command] - pub fn filter_do(&mut self, opt: Opt) { + pub fn filter_do(&mut self, opt: FilterOpt) { let filter = if opt.query.is_empty() { None } else if let Ok(f) = Filter::new(&opt.query, opt.case) { diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index 6537730f..d1478ad8 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -1,30 +1,19 @@ -use std::{borrow::Cow, time::Duration}; +use std::time::Duration; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; use yazi_config::popup::InputCfg; use yazi_fs::FilterCase; use yazi_macro::emit; +use yazi_parser::tab::FindOpt; use yazi_proxy::InputProxy; -use yazi_shared::{Debounce, errors::InputError, event::{Cmd, CmdCow}}; +use yazi_shared::{Debounce, errors::InputError, event::Cmd}; use crate::tab::Tab; -pub(super) struct Opt { - pub(super) query: Option>, - pub(super) prev: bool, - pub(super) case: FilterCase, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { query: c.take_first_str(), prev: c.bool("previous"), case: FilterCase::from(&*c) } - } -} - impl Tab { #[yazi_codegen::command] - pub fn find(&mut self, opt: Opt) { + pub fn find(&mut self, opt: FindOpt) { let input = InputProxy::show(InputCfg::find(opt.prev)); tokio::spawn(async move { diff --git a/yazi-core/src/tab/commands/find_arrow.rs b/yazi-core/src/tab/commands/find_arrow.rs index 925ab260..1bee33b3 100644 --- a/yazi-core/src/tab/commands/find_arrow.rs +++ b/yazi-core/src/tab/commands/find_arrow.rs @@ -1,19 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::FindArrowOpt; use crate::tab::Tab; -struct Opt { - prev: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { prev: c.bool("previous") } } -} - impl Tab { #[yazi_codegen::command] - pub fn find_arrow(&mut self, opt: Opt) { + pub fn find_arrow(&mut self, opt: FindArrowOpt) { let Some(finder) = &mut self.finder else { return; }; diff --git a/yazi-core/src/tab/commands/find_do.rs b/yazi-core/src/tab/commands/find_do.rs index 732a9c60..db160f9c 100644 --- a/yazi-core/src/tab/commands/find_do.rs +++ b/yazi-core/src/tab/commands/find_do.rs @@ -1,11 +1,11 @@ use yazi_macro::render; +use yazi_parser::tab::FindOpt; -use super::find::Opt; use crate::tab::{Finder, Tab}; impl Tab { #[yazi_codegen::command] - pub fn find_do(&mut self, opt: Opt) { + pub fn find_do(&mut self, opt: FindOpt) { let Some(query) = opt.query else { return; }; diff --git a/yazi-core/src/tab/commands/follow.rs b/yazi-core/src/tab/commands/follow.rs index 8fb43361..2f33bc16 100644 --- a/yazi-core/src/tab/commands/follow.rs +++ b/yazi-core/src/tab/commands/follow.rs @@ -1,17 +1,11 @@ use yazi_fs::clean_url; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::FollowOpt; use crate::tab::Tab; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} - impl Tab { #[yazi_codegen::command] - pub fn follow(&mut self, _: Opt) { + pub fn follow(&mut self, _: FollowOpt) { let Some(file) = self.hovered() else { return }; let Some(link_to) = &file.link_to else { return }; diff --git a/yazi-core/src/tab/commands/forward.rs b/yazi-core/src/tab/commands/forward.rs index 00feb0b8..c8de0525 100644 --- a/yazi-core/src/tab/commands/forward.rs +++ b/yazi-core/src/tab/commands/forward.rs @@ -1,6 +1,6 @@ +use yazi_parser::tab::CdSource; use yazi_shared::event::CmdCow; -use super::cd::CdSource; use crate::tab::Tab; impl Tab { diff --git a/yazi-core/src/tab/commands/hover.rs b/yazi-core/src/tab/commands/hover.rs index 18ba2c18..0091767a 100644 --- a/yazi-core/src/tab/commands/hover.rs +++ b/yazi-core/src/tab/commands/hover.rs @@ -1,23 +1,13 @@ use yazi_dds::Pubsub; use yazi_macro::{err, render}; -use yazi_shared::{event::CmdCow, url::{Url, Urn}}; +use yazi_parser::tab::HoverOpt; +use yazi_shared::url::{Url, Urn}; use crate::tab::Tab; -struct Opt { - url: Option, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { Self { url: c.take_first_url() } } -} -impl From> for Opt { - fn from(url: Option) -> Self { Self { url } } -} - impl Tab { #[yazi_codegen::command] - pub fn hover(&mut self, opt: Opt) { + pub fn hover(&mut self, opt: HoverOpt) { if let Some(u) = opt.url { self.hover_do(u); } else { diff --git a/yazi-core/src/tab/commands/leave.rs b/yazi-core/src/tab/commands/leave.rs index 6f6cf307..44fbd654 100644 --- a/yazi-core/src/tab/commands/leave.rs +++ b/yazi-core/src/tab/commands/leave.rs @@ -1,19 +1,10 @@ -use yazi_shared::event::CmdCow; +use yazi_parser::tab::{CdSource, LeaveOpt}; -use super::cd::CdSource; use crate::tab::Tab; -struct Opt; -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} - impl Tab { #[yazi_codegen::command] - pub fn leave(&mut self, _: Opt) { + pub fn leave(&mut self, _: LeaveOpt) { self .current .hovered() diff --git a/yazi-core/src/tab/commands/reveal.rs b/yazi-core/src/tab/commands/reveal.rs index 3ce76b72..31930271 100644 --- a/yazi-core/src/tab/commands/reveal.rs +++ b/yazi-core/src/tab/commands/reveal.rs @@ -1,38 +1,12 @@ -use yazi_fs::{File, FilesOp, expand_path}; +use yazi_fs::{File, FilesOp}; +use yazi_parser::tab::RevealOpt; use yazi_proxy::MgrProxy; -use yazi_shared::{event::CmdCow, url::Url}; -use super::cd::CdSource; use crate::tab::Tab; -struct Opt { - target: Url, - source: CdSource, - no_dummy: bool, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - let mut target = c.take_first_url().unwrap_or_default(); - if target.is_regular() && !c.bool("raw") { - target = Url::from(expand_path(target)); - } - - Self { target, source: CdSource::Reveal, no_dummy: c.bool("no-dummy") } - } -} - -impl From for Opt { - fn from(target: Url) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } } -} - -impl From<(Url, CdSource)> for Opt { - fn from((target, source): (Url, CdSource)) -> Self { Self { target, source, no_dummy: false } } -} - impl Tab { #[yazi_codegen::command] - pub fn reveal(&mut self, opt: Opt) { + pub fn reveal(&mut self, opt: RevealOpt) { let Some((parent, child)) = opt.target.pair() else { return; }; diff --git a/yazi-core/src/tab/commands/shell.rs b/yazi-core/src/tab/commands/shell.rs index 5476691f..00343c78 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -1,54 +1,19 @@ use std::{borrow::Cow, fmt::Display}; -use anyhow::bail; use yazi_config::{opener::OpenerRule, popup::InputCfg}; +use yazi_parser::tab::ShellOpt; use yazi_proxy::{AppProxy, InputProxy, TasksProxy}; -use yazi_shared::{event::{CmdCow, Data}, url::Url}; use crate::tab::Tab; -pub struct Opt { - run: Cow<'static, str>, - cwd: Option, - - block: bool, - orphan: bool, - interactive: bool, - - cursor: Option, -} - -impl TryFrom for Opt { - type Error = anyhow::Error; - - fn try_from(mut c: CmdCow) -> Result { - let me = Self { - run: c.take_first_str().unwrap_or_default(), - cwd: c.take_url("cwd"), - - block: c.bool("block"), - orphan: c.bool("orphan"), - interactive: c.bool("interactive"), - - cursor: c.get("cursor").and_then(Data::as_usize), - }; - - if me.cursor.is_some_and(|c| c > me.run.chars().count()) { - bail!("The cursor position is out of bounds."); - } - - Ok(me) - } -} - impl Tab { - pub fn shell(&mut self, opt: impl TryInto) { + pub fn shell(&mut self, opt: impl TryInto) { if !self.try_escape_visual() { return; } let mut opt = match opt.try_into() { - Ok(o) => o as Opt, + Ok(o) => o as ShellOpt, Err(e) => return AppProxy::notify_warn("`shell` command", e), }; diff --git a/yazi-core/src/tab/commands/toggle.rs b/yazi-core/src/tab/commands/toggle.rs index e0f6e860..54cae9b2 100644 --- a/yazi-core/src/tab/commands/toggle.rs +++ b/yazi-core/src/tab/commands/toggle.rs @@ -1,30 +1,12 @@ use yazi_macro::render_and; +use yazi_parser::tab::ToggleOpt; use yazi_proxy::AppProxy; -use yazi_shared::{event::CmdCow, url::Url}; use crate::tab::Tab; -struct Opt { - url: Option, - state: Option, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - Self { - url: c.take_first_url(), - state: match c.str("state") { - Some("on") => Some(true), - Some("off") => Some(false), - _ => None, - }, - } - } -} - impl Tab { #[yazi_codegen::command] - pub fn toggle(&mut self, opt: Opt) { + pub fn toggle(&mut self, opt: ToggleOpt) { let Some(url) = opt.url.as_ref().or(self.current.hovered().map(|h| &h.url)) else { return; }; diff --git a/yazi-core/src/tab/commands/toggle_all.rs b/yazi-core/src/tab/commands/toggle_all.rs index 4228bf6b..3e87061e 100644 --- a/yazi-core/src/tab/commands/toggle_all.rs +++ b/yazi-core/src/tab/commands/toggle_all.rs @@ -1,42 +1,12 @@ use yazi_macro::render; +use yazi_parser::tab::ToggleAllOpt; use yazi_proxy::AppProxy; -use yazi_shared::{event::CmdCow, url::Url}; use crate::tab::Tab; -struct Opt { - urls: Vec, - state: Option, -} - -impl From for Opt { - fn from(mut c: CmdCow) -> Self { - let mut urls = Vec::with_capacity(c.len()); - for i in 0..c.len() { - match c.take_url(i) { - Some(url) => urls.push(url), - None => break, - } - } - - Self { - urls, - state: match c.str("state") { - Some("on") => Some(true), - Some("off") => Some(false), - _ => None, - }, - } - } -} - -impl From> for Opt { - fn from(state: Option) -> Self { Self { urls: vec![], state } } -} - impl Tab { #[yazi_codegen::command] - pub fn toggle_all(&mut self, opt: Opt) { + pub fn toggle_all(&mut self, opt: ToggleAllOpt) { use yazi_shared::Either::*; let it = self.current.files.iter().map(|f| &f.url); diff --git a/yazi-core/src/tab/commands/update_peeked.rs b/yazi-core/src/tab/commands/update_peeked.rs index 96e9520c..eb66f770 100644 --- a/yazi-core/src/tab/commands/update_peeked.rs +++ b/yazi-core/src/tab/commands/update_peeked.rs @@ -1,28 +1,15 @@ use yazi_macro::render; -use yazi_plugin::utils::PreviewLock; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::UpdatePeekedOpt; use crate::tab::Tab; -pub struct Opt { - lock: PreviewLock, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { lock: c.take_any("lock").ok_or(())? }) - } -} - impl Tab { - pub fn update_peeked(&mut self, opt: impl TryInto) { + pub fn update_peeked(&mut self, opt: impl TryInto) { let Some(hovered) = self.hovered().map(|h| &h.url) else { return self.preview.reset(); }; - let Ok(opt) = opt.try_into() else { + let Ok(opt): Result = opt.try_into() else { return; }; diff --git a/yazi-core/src/tab/commands/update_spotted.rs b/yazi-core/src/tab/commands/update_spotted.rs index f952d365..f96fadb7 100644 --- a/yazi-core/src/tab/commands/update_spotted.rs +++ b/yazi-core/src/tab/commands/update_spotted.rs @@ -1,28 +1,15 @@ use yazi_macro::render; -use yazi_plugin::utils::SpotLock; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::UpdateSpottedOpt; use crate::tab::Tab; -pub struct Opt { - lock: SpotLock, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { lock: c.take_any("lock").ok_or(())? }) - } -} - impl Tab { - pub fn update_spotted(&mut self, opt: impl TryInto) { + pub fn update_spotted(&mut self, opt: impl TryInto) { let Some(hovered) = self.hovered().map(|h| &h.url) else { return self.spot.reset(); }; - let Ok(mut opt): Result = opt.try_into() else { + let Ok(mut opt): Result = opt.try_into() else { return; }; diff --git a/yazi-core/src/tab/commands/visual_mode.rs b/yazi-core/src/tab/commands/visual_mode.rs index 5e6cbc60..f85db655 100644 --- a/yazi-core/src/tab/commands/visual_mode.rs +++ b/yazi-core/src/tab/commands/visual_mode.rs @@ -1,21 +1,13 @@ use std::collections::BTreeSet; use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::tab::VisualModeOpt; use crate::tab::{Mode, Tab}; -struct Opt { - unset: bool, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { Self { unset: c.bool("unset") } } -} - impl Tab { #[yazi_codegen::command] - pub fn visual_mode(&mut self, opt: Opt) { + pub fn visual_mode(&mut self, opt: VisualModeOpt) { let idx = self.current.cursor; if opt.unset { self.mode = Mode::Unset(idx, BTreeSet::from([idx])); diff --git a/yazi-core/src/tab/preview.rs b/yazi-core/src/tab/preview.rs index 4e30110e..bb777965 100644 --- a/yazi-core/src/tab/preview.rs +++ b/yazi-core/src/tab/preview.rs @@ -7,7 +7,8 @@ use yazi_adapter::ADAPTOR; use yazi_config::YAZI; use yazi_fs::{File, Files, FilesOp, cha::Cha}; use yazi_macro::render; -use yazi_plugin::{external::Highlighter, isolate, utils::PreviewLock}; +use yazi_parser::tab::PreviewLock; +use yazi_plugin::{external::Highlighter, isolate}; use yazi_shared::{MIME_DIR, url::Url}; #[derive(Default)] diff --git a/yazi-core/src/tasks/commands/arrow.rs b/yazi-core/src/tasks/commands/arrow.rs index f77d7115..7b451061 100644 --- a/yazi-core/src/tasks/commands/arrow.rs +++ b/yazi-core/src/tasks/commands/arrow.rs @@ -1,26 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; -use yazi_widgets::Step; +use yazi_parser::tasks::ArrowOpt; use crate::tasks::Tasks; -struct Opt { - step: Step, -} - -impl From for Opt { - fn from(c: CmdCow) -> Self { - Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } - } -} - -impl From for Opt { - fn from(n: isize) -> Self { Self { step: n.into() } } -} - impl Tasks { #[yazi_codegen::command] - pub fn arrow(&mut self, opt: Opt) { + pub fn arrow(&mut self, opt: ArrowOpt) { let old = self.cursor; self.cursor = opt.step.add(self.cursor, self.summaries.len(), Self::limit()); diff --git a/yazi-core/src/tasks/commands/close.rs b/yazi-core/src/tasks/commands/close.rs index e43a9804..3dcb708d 100644 --- a/yazi-core/src/tasks/commands/close.rs +++ b/yazi-core/src/tasks/commands/close.rs @@ -1,20 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::tasks::CloseOpt; use crate::tasks::Tasks; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} - impl Tasks { #[yazi_codegen::command] - pub fn close(&mut self, _: Opt) { + pub fn close(&mut self, _: CloseOpt) { if !self.visible { return; } diff --git a/yazi-core/src/tasks/commands/show.rs b/yazi-core/src/tasks/commands/show.rs index 10eb7339..f8c6959e 100644 --- a/yazi-core/src/tasks/commands/show.rs +++ b/yazi-core/src/tasks/commands/show.rs @@ -1,20 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::CmdCow; +use yazi_parser::tasks::ShowOpt; use crate::tasks::Tasks; -struct Opt; - -impl From for Opt { - fn from(_: CmdCow) -> Self { Self } -} -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} - impl Tasks { #[yazi_codegen::command] - pub fn show(&mut self, _: Opt) { + pub fn show(&mut self, _: ShowOpt) { if self.visible { return; } diff --git a/yazi-core/src/which/commands/callback.rs b/yazi-core/src/which/commands/callback.rs index 313fb6cc..7526db92 100644 --- a/yazi-core/src/which/commands/callback.rs +++ b/yazi-core/src/which/commands/callback.rs @@ -1,27 +1,10 @@ -use tokio::sync::mpsc; use tracing::error; -use yazi_shared::event::{CmdCow, Data}; +use yazi_parser::which::CallbackOpt; use crate::which::Which; -pub struct Opt { - tx: mpsc::Sender, - idx: usize, -} - -impl TryFrom for Opt { - type Error = (); - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { - tx: c.take_any("tx").ok_or(())?, - idx: c.first().and_then(Data::as_usize).ok_or(())?, - }) - } -} - impl Which { - pub fn callback(&mut self, opt: impl TryInto) { + pub fn callback(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-core/src/which/commands/show.rs b/yazi-core/src/which/commands/show.rs index 5d45dd7b..2dcacf11 100644 --- a/yazi-core/src/which/commands/show.rs +++ b/yazi-core/src/which/commands/show.rs @@ -1,24 +1,12 @@ -use yazi_config::{KEYMAP, keymap::{Chord, Key}}; +use yazi_config::{KEYMAP, keymap::Key}; use yazi_macro::render; -use yazi_shared::{Layer, event::CmdCow}; +use yazi_parser::which::ShowOpt; +use yazi_shared::Layer; use crate::which::{Which, WhichSorter}; -pub struct Opt { - cands: Vec, - silent: bool, -} - -impl TryFrom for Opt { - type Error = anyhow::Error; - - fn try_from(mut c: CmdCow) -> Result { - Ok(Self { cands: c.take_any("candidates").unwrap_or_default(), silent: c.bool("silent") }) - } -} - impl Which { - pub fn show(&mut self, opt: impl TryInto) { + pub fn show(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-fm/src/app/commands/accept_payload.rs b/yazi-fm/src/app/commands/accept_payload.rs index af460b04..96c1349a 100644 --- a/yazi-fm/src/app/commands/accept_payload.rs +++ b/yazi-fm/src/app/commands/accept_payload.rs @@ -1,7 +1,8 @@ use mlua::IntoLua; use tracing::error; +use yazi_binding::runtime_mut; use yazi_dds::{LOCAL, Payload, REMOTE}; -use yazi_plugin::{LUA, runtime_mut}; +use yazi_plugin::LUA; use yazi_shared::event::CmdCow; use crate::{app::App, lives::Lives}; diff --git a/yazi-fm/src/app/commands/mouse.rs b/yazi-fm/src/app/commands/mouse.rs index 0d969d28..61523f1e 100644 --- a/yazi-fm/src/app/commands/mouse.rs +++ b/yazi-fm/src/app/commands/mouse.rs @@ -21,7 +21,7 @@ impl App { let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return }; let res = Lives::scope(&self.cx, move || { - let area = yazi_plugin::elements::Rect::from(size); + let area = yazi_binding::elements::Rect::from(size); let root = LUA.globals().raw_get::("Root")?.call_method::
("new", area)?; if matches!(event.kind, MouseEventKind::Down(_) if YAZI.mgr.mouse_events.draggable()) { diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index ba997c69..e03818dd 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -3,8 +3,9 @@ use std::fmt::Display; use mlua::ObjectLike; use scopeguard::defer; use tracing::{error, warn}; +use yazi_binding::runtime_mut; use yazi_dds::Sendable; -use yazi_plugin::{LUA, loader::{LOADER, Loader}, runtime_mut}; +use yazi_plugin::{LUA, loader::{LOADER, Loader}}; use yazi_proxy::{AppProxy, options::{PluginMode, PluginOpt}}; use crate::{app::App, lives::Lives}; diff --git a/yazi-fm/src/app/commands/reflow.rs b/yazi-fm/src/app/commands/reflow.rs index 5d944bdb..1663c061 100644 --- a/yazi-fm/src/app/commands/reflow.rs +++ b/yazi-fm/src/app/commands/reflow.rs @@ -34,9 +34,9 @@ impl App { let id: mlua::String = t.get("_id")?; match id.as_bytes().as_ref() { - b"current" => layout.current = *t.raw_get::("_area")?, - b"preview" => layout.preview = *t.raw_get::("_area")?, - b"progress" => layout.progress = *t.raw_get::("_area")?, + b"current" => layout.current = *t.raw_get::("_area")?, + b"preview" => layout.preview = *t.raw_get::("_area")?, + b"progress" => layout.progress = *t.raw_get::("_area")?, _ => {} } } diff --git a/yazi-fm/src/app/commands/render.rs b/yazi-fm/src/app/commands/render.rs index b0382de7..354970f2 100644 --- a/yazi-fm/src/app/commands/render.rs +++ b/yazi-fm/src/app/commands/render.rs @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicU8, Ordering}; use crossterm::{cursor::{MoveTo, SetCursorStyle, Show}, execute, queue, terminal::{BeginSynchronizedUpdate, EndSynchronizedUpdate}}; use ratatui::{CompletedFrame, backend::{Backend, CrosstermBackend}, buffer::Buffer, layout::Position}; -use yazi_plugin::elements::COLLISION; +use yazi_binding::elements::COLLISION; use yazi_shared::event::NEED_RENDER; use yazi_term::tty::TTY; diff --git a/yazi-fm/src/cmp/cmp.rs b/yazi-fm/src/cmp/cmp.rs index 3bf37ab9..310a20c5 100644 --- a/yazi-fm/src/cmp/cmp.rs +++ b/yazi-fm/src/cmp/cmp.rs @@ -52,7 +52,7 @@ impl Widget for Cmp<'_> { area.height = rect.height.saturating_sub(area.y).min(area.height); } - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); List::new(items) .block(Block::bordered().border_type(BorderType::Rounded).border_style(THEME.cmp.border)) .render(area, buf); diff --git a/yazi-fm/src/confirm/confirm.rs b/yazi-fm/src/confirm/confirm.rs index 63621ae4..1608510e 100644 --- a/yazi-fm/src/confirm/confirm.rs +++ b/yazi-fm/src/confirm/confirm.rs @@ -16,7 +16,7 @@ impl Widget for Confirm<'_> { let confirm = &self.cx.confirm; let area = self.cx.mgr.area(confirm.position); - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); Block::bordered() .border_type(BorderType::Rounded) diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 704f9e48..63da30c1 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -136,7 +136,7 @@ impl<'a> Executor<'a> { on!(ACTIVE, sort, &self.app.cx.tasks); // Tabs - on!(TABS, create); + on!(TABS, create); // TODO: use `tab_create` instead on!(TABS, close); on!(TABS, switch); on!(TABS, swap); diff --git a/yazi-fm/src/help/help.rs b/yazi-fm/src/help/help.rs index 7e03683b..8c9457d3 100644 --- a/yazi-fm/src/help/help.rs +++ b/yazi-fm/src/help/help.rs @@ -22,7 +22,7 @@ impl<'a> Help<'a> { impl Widget for Help<'_> { fn render(self, area: Rect, buf: &mut Buffer) { let help = &self.cx.help; - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area); Line::styled( diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index 4c85dcb4..c4553d09 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -16,7 +16,7 @@ impl Widget for Input<'_> { let input = &self.cx.input; let area = self.cx.mgr.area(input.position); - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); Block::bordered() .border_type(BorderType::Rounded) diff --git a/yazi-fm/src/lives/file.rs b/yazi-fm/src/lives/file.rs index 522e5177..8dbb8429 100644 --- a/yazi-fm/src/lives/file.rs +++ b/yazi-fm/src/lives/file.rs @@ -60,7 +60,7 @@ impl File { impl UserData for File { fn add_fields>(fields: &mut F) { - yazi_plugin::impl_file_fields!(fields); + yazi_binding::impl_file_fields!(fields); fields.add_field_method_get("idx", |_, me| Ok(me.idx + 1)); fields.add_field_method_get("is_hovered", |_, me| Ok(me.idx == me.folder.cursor)); @@ -70,7 +70,7 @@ impl UserData for File { } fn add_methods>(methods: &mut M) { - yazi_plugin::impl_file_methods!(methods); + yazi_binding::impl_file_methods!(methods); methods.add_method("size", |_, me, ()| { Ok(if me.is_dir() { me.folder.files.sizes.get(me.urn()).copied() } else { Some(me.len) }) diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index cf807a5f..57084c63 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -30,6 +30,8 @@ async fn main() -> anyhow::Result<()> { yazi_dds::init(); + yazi_widgets::init(); + yazi_plugin::init()?; yazi_core::init(); diff --git a/yazi-fm/src/mgr/modal.rs b/yazi-fm/src/mgr/modal.rs index cfc32451..225b5d73 100644 --- a/yazi-fm/src/mgr/modal.rs +++ b/yazi-fm/src/mgr/modal.rs @@ -1,7 +1,8 @@ use mlua::{ObjectLike, Table}; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; -use yazi_plugin::{LUA, elements::render_once}; +use yazi_binding::elements::render_once; +use yazi_plugin::LUA; use crate::Ctx; @@ -17,7 +18,7 @@ impl<'a> Modal<'a> { impl Widget for Modal<'_> { fn render(self, area: Rect, buf: &mut Buffer) { let mut f = || { - let area = yazi_plugin::elements::Rect::from(area); + let area = yazi_binding::elements::Rect::from(area); let root = LUA.globals().raw_get::
("Modal")?.call_method::
("new", area)?; render_once(root.call_method("children_redraw", ())?, buf, |p| self.cx.mgr.area(p)); diff --git a/yazi-fm/src/notify/notify.rs b/yazi-fm/src/notify/notify.rs index b1eca04a..fe0501c1 100644 --- a/yazi-fm/src/notify/notify.rs +++ b/yazi-fm/src/notify/notify.rs @@ -54,7 +54,7 @@ impl Widget for Notify<'_> { tiles[i].offset(Offset { x: (100 - m.percent) as i32 * tiles[i].width as i32 / 100, y: 0 }); rect.width -= rect.x - tiles[i].x; - yazi_plugin::elements::Clear::default().render(rect, buf); + yazi_binding::elements::Clear::default().render(rect, buf); Paragraph::new(m.content.as_str()) .wrap(Wrap { trim: false }) .block( diff --git a/yazi-fm/src/pick/pick.rs b/yazi-fm/src/pick/pick.rs index 694bfbb9..15b49cdb 100644 --- a/yazi-fm/src/pick/pick.rs +++ b/yazi-fm/src/pick/pick.rs @@ -16,7 +16,7 @@ impl Widget for Pick<'_> { let pick = &self.cx.pick; let area = self.cx.mgr.area(pick.position); - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); Block::bordered() .title(pick.title()) diff --git a/yazi-fm/src/root.rs b/yazi-fm/src/root.rs index bd80c142..b9f97452 100644 --- a/yazi-fm/src/root.rs +++ b/yazi-fm/src/root.rs @@ -1,7 +1,8 @@ use mlua::{ObjectLike, Table}; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; -use yazi_plugin::{LUA, elements::render_once}; +use yazi_binding::elements::render_once; +use yazi_plugin::LUA; use super::{cmp, confirm, help, input, mgr, pick, spot, tasks, which}; use crate::Ctx; @@ -14,7 +15,7 @@ impl<'a> Root<'a> { pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } } pub(super) fn reflow(area: Rect) -> mlua::Result
{ - let area = yazi_plugin::elements::Rect::from(area); + let area = yazi_binding::elements::Rect::from(area); let root = LUA.globals().raw_get::
("Root")?.call_method::
("new", area)?; root.call_method("reflow", ()) } @@ -23,7 +24,7 @@ impl<'a> Root<'a> { impl Widget for Root<'_> { fn render(self, area: Rect, buf: &mut Buffer) { let mut f = || { - let area = yazi_plugin::elements::Rect::from(area); + let area = yazi_binding::elements::Rect::from(area); let root = LUA.globals().raw_get::
("Root")?.call_method::
("new", area)?; render_once(root.call_method("redraw", ())?, buf, |p| self.cx.mgr.area(p)); diff --git a/yazi-fm/src/tasks/progress.rs b/yazi-fm/src/tasks/progress.rs index 91a38c84..e07a5004 100644 --- a/yazi-fm/src/tasks/progress.rs +++ b/yazi-fm/src/tasks/progress.rs @@ -1,8 +1,9 @@ use mlua::{ObjectLike, Table}; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; +use yazi_binding::elements::render_once; use yazi_config::LAYOUT; -use yazi_plugin::{LUA, elements::render_once}; +use yazi_plugin::LUA; use crate::Ctx; @@ -17,7 +18,7 @@ impl<'a> Progress<'a> { impl Widget for Progress<'_> { fn render(self, _: Rect, buf: &mut Buffer) { let mut f = || { - let area = yazi_plugin::elements::Rect::from(LAYOUT.get().progress); + let area = yazi_binding::elements::Rect::from(LAYOUT.get().progress); let progress = LUA.globals().raw_get::
("Progress")?.call_method::
("use", area)?; diff --git a/yazi-fm/src/tasks/tasks.rs b/yazi-fm/src/tasks/tasks.rs index cad890bc..2116125d 100644 --- a/yazi-fm/src/tasks/tasks.rs +++ b/yazi-fm/src/tasks/tasks.rs @@ -32,7 +32,7 @@ impl Widget for Tasks<'_> { fn render(self, area: Rect, buf: &mut Buffer) { let area = Self::area(area); - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); let block = Block::bordered() .title(Line::styled("Tasks", THEME.tasks.title)) .title_alignment(Alignment::Center) diff --git a/yazi-fm/src/which/which.rs b/yazi-fm/src/which/which.rs index a284e1e8..d2381f03 100644 --- a/yazi-fm/src/which/which.rs +++ b/yazi-fm/src/which/which.rs @@ -46,7 +46,7 @@ impl Widget for Which<'_> { .split(area) }; - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); Block::new().style(THEME.which.mask).render(area, buf); for y in 0..area.height { diff --git a/yazi-parser/Cargo.toml b/yazi-parser/Cargo.toml new file mode 100644 index 00000000..c6f3ab57 --- /dev/null +++ b/yazi-parser/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "yazi-parser" +version = "25.6.11" +edition = "2024" +license = "MIT" +authors = [ "sxyazi " ] +description = "Yazi command parser" +homepage = "https://yazi-rs.github.io" +repository = "https://github.com/sxyazi/yazi" + +[dependencies] +yazi-binding = { path = "../yazi-binding", version = "25.6.11" } +yazi-boot = { path = "../yazi-boot", version = "25.6.11" } +yazi-config = { path = "../yazi-config", version = "25.6.11" } +yazi-dds = { path = "../yazi-dds", version = "25.6.11" } +yazi-fs = { path = "../yazi-fs", version = "25.6.11" } +yazi-macro = { path = "../yazi-macro", version = "25.6.11" } +yazi-proxy = { path = "../yazi-proxy", version = "25.6.11" } +yazi-shared = { path = "../yazi-shared", version = "25.6.11" } +yazi-widgets = { path = "../yazi-widgets", version = "25.6.11" } + +# External dependencies +anyhow = { workspace = true } +bitflags = { workspace = true } +mlua = { workspace = true } +tokio = { workspace = true } diff --git a/yazi-parser/src/cmp/arrow.rs b/yazi-parser/src/cmp/arrow.rs new file mode 100644 index 00000000..c54d5acc --- /dev/null +++ b/yazi-parser/src/cmp/arrow.rs @@ -0,0 +1,12 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} diff --git a/yazi-parser/src/cmp/close.rs b/yazi-parser/src/cmp/close.rs new file mode 100644 index 00000000..fa516687 --- /dev/null +++ b/yazi-parser/src/cmp/close.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt { + pub submit: bool, +} + +impl From for CloseOpt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } +} + +impl From for CloseOpt { + fn from(submit: bool) -> Self { Self { submit } } +} diff --git a/yazi-parser/src/cmp/mod.rs b/yazi-parser/src/cmp/mod.rs new file mode 100644 index 00000000..e1a77788 --- /dev/null +++ b/yazi-parser/src/cmp/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow close show trigger); diff --git a/yazi-parser/src/cmp/show.rs b/yazi-parser/src/cmp/show.rs new file mode 100644 index 00000000..87c3ec74 --- /dev/null +++ b/yazi-parser/src/cmp/show.rs @@ -0,0 +1,26 @@ +use std::{borrow::Cow, path::PathBuf}; + +use yazi_proxy::options::CmpItem; +use yazi_shared::{Id, event::{Cmd, CmdCow, Data}}; + +pub struct ShowOpt { + pub cache: Vec, + pub cache_name: PathBuf, + pub word: Cow<'static, str>, + pub ticket: Id, +} + +impl From for ShowOpt { + fn from(mut c: CmdCow) -> Self { + Self { + cache: c.take_any("cache").unwrap_or_default(), + cache_name: c.take_any("cache-name").unwrap_or_default(), + word: c.take_str("word").unwrap_or_default(), + ticket: c.get("ticket").and_then(Data::as_id).unwrap_or_default(), + } + } +} + +impl From for ShowOpt { + fn from(c: Cmd) -> Self { Self::from(CmdCow::from(c)) } +} diff --git a/yazi-parser/src/cmp/trigger.rs b/yazi-parser/src/cmp/trigger.rs new file mode 100644 index 00000000..12bbb489 --- /dev/null +++ b/yazi-parser/src/cmp/trigger.rs @@ -0,0 +1,17 @@ +use std::borrow::Cow; + +use yazi_shared::{Id, event::{CmdCow, Data}}; + +pub struct TriggerOpt { + pub word: Cow<'static, str>, + pub ticket: Id, +} + +impl From for TriggerOpt { + fn from(mut c: CmdCow) -> Self { + Self { + word: c.take_first_str().unwrap_or_default(), + ticket: c.get("ticket").and_then(Data::as_id).unwrap_or_default(), + } + } +} diff --git a/yazi-parser/src/confirm/arrow.rs b/yazi-parser/src/confirm/arrow.rs new file mode 100644 index 00000000..c54d5acc --- /dev/null +++ b/yazi-parser/src/confirm/arrow.rs @@ -0,0 +1,12 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} diff --git a/yazi-parser/src/confirm/close.rs b/yazi-parser/src/confirm/close.rs new file mode 100644 index 00000000..fa516687 --- /dev/null +++ b/yazi-parser/src/confirm/close.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt { + pub submit: bool, +} + +impl From for CloseOpt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } +} + +impl From for CloseOpt { + fn from(submit: bool) -> Self { Self { submit } } +} diff --git a/yazi-parser/src/confirm/mod.rs b/yazi-parser/src/confirm/mod.rs new file mode 100644 index 00000000..e0fc92ad --- /dev/null +++ b/yazi-parser/src/confirm/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow close show); diff --git a/yazi-parser/src/confirm/show.rs b/yazi-parser/src/confirm/show.rs new file mode 100644 index 00000000..3eb3ada7 --- /dev/null +++ b/yazi-parser/src/confirm/show.rs @@ -0,0 +1,16 @@ +use tokio::sync::oneshot; +use yazi_config::popup::ConfirmCfg; +use yazi_shared::event::CmdCow; + +pub struct ShowOpt { + pub cfg: ConfirmCfg, + pub tx: oneshot::Sender, +} + +impl TryFrom for ShowOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) + } +} diff --git a/yazi-parser/src/help/arrow.rs b/yazi-parser/src/help/arrow.rs new file mode 100644 index 00000000..29a1e04d --- /dev/null +++ b/yazi-parser/src/help/arrow.rs @@ -0,0 +1,16 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} + +impl From for ArrowOpt { + fn from(n: isize) -> Self { Self { step: n.into() } } +} diff --git a/yazi-parser/src/help/escape.rs b/yazi-parser/src/help/escape.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/help/filter.rs b/yazi-parser/src/help/filter.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/help/mod.rs b/yazi-parser/src/help/mod.rs new file mode 100644 index 00000000..11f3a072 --- /dev/null +++ b/yazi-parser/src/help/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow escape filter); diff --git a/yazi-parser/src/input/close.rs b/yazi-parser/src/input/close.rs new file mode 100644 index 00000000..fa516687 --- /dev/null +++ b/yazi-parser/src/input/close.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt { + pub submit: bool, +} + +impl From for CloseOpt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } +} + +impl From for CloseOpt { + fn from(submit: bool) -> Self { Self { submit } } +} diff --git a/yazi-parser/src/input/escape.rs b/yazi-parser/src/input/escape.rs new file mode 100644 index 00000000..8f6b5301 --- /dev/null +++ b/yazi-parser/src/input/escape.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct EscapeOpt; + +impl From for EscapeOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for EscapeOpt { + fn from(_: ()) -> Self { Self } +} diff --git a/yazi-parser/src/input/mod.rs b/yazi-parser/src/input/mod.rs new file mode 100644 index 00000000..d23f3447 --- /dev/null +++ b/yazi-parser/src/input/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(close escape show); diff --git a/yazi-parser/src/input/show.rs b/yazi-parser/src/input/show.rs new file mode 100644 index 00000000..4f7fe9a9 --- /dev/null +++ b/yazi-parser/src/input/show.rs @@ -0,0 +1,16 @@ +use tokio::sync::mpsc; +use yazi_config::popup::InputCfg; +use yazi_shared::{errors::InputError, event::CmdCow}; + +pub struct ShowOpt { + pub cfg: InputCfg, + pub tx: mpsc::UnboundedSender>, +} + +impl TryFrom for ShowOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) + } +} diff --git a/yazi-parser/src/lib.rs b/yazi-parser/src/lib.rs new file mode 100644 index 00000000..af0da039 --- /dev/null +++ b/yazi-parser/src/lib.rs @@ -0,0 +1 @@ +yazi_macro::mod_pub!(cmp confirm help input mgr notify pick spot tab tasks which); diff --git a/yazi-parser/src/mgr/close.rs b/yazi-parser/src/mgr/close.rs new file mode 100644 index 00000000..bfc77c9d --- /dev/null +++ b/yazi-parser/src/mgr/close.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::CmdCow; + +use crate::mgr::QuitOpt; + +#[derive(Default)] +pub struct CloseOpt(pub QuitOpt); + +impl From for CloseOpt { + fn from(c: CmdCow) -> Self { Self(c.into()) } +} diff --git a/yazi-parser/src/mgr/create.rs b/yazi-parser/src/mgr/create.rs new file mode 100644 index 00000000..49b3fce9 --- /dev/null +++ b/yazi-parser/src/mgr/create.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::CmdCow; + +pub struct CreateOpt { + pub dir: bool, + pub force: bool, +} + +impl From for CreateOpt { + fn from(c: CmdCow) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } +} diff --git a/yazi-parser/src/mgr/hardlink.rs b/yazi-parser/src/mgr/hardlink.rs new file mode 100644 index 00000000..d02fb1d6 --- /dev/null +++ b/yazi-parser/src/mgr/hardlink.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::CmdCow; + +pub struct HardlinkOpt { + pub force: bool, + pub follow: bool, +} + +impl From for HardlinkOpt { + fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } +} diff --git a/yazi-parser/src/mgr/link.rs b/yazi-parser/src/mgr/link.rs new file mode 100644 index 00000000..dd76a50b --- /dev/null +++ b/yazi-parser/src/mgr/link.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::CmdCow; + +pub struct LinkOpt { + pub relative: bool, + pub force: bool, +} + +impl From for LinkOpt { + fn from(c: CmdCow) -> Self { Self { relative: c.bool("relative"), force: c.bool("force") } } +} diff --git a/yazi-parser/src/mgr/mod.rs b/yazi-parser/src/mgr/mod.rs new file mode 100644 index 00000000..c62d4b86 --- /dev/null +++ b/yazi-parser/src/mgr/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(close create hardlink link open paste peek quit remove rename seek spot tab_close tab_create tab_swap tab_switch unyank update_files update_mimes update_paged update_tasks update_yanked watch yank); diff --git a/yazi-parser/src/mgr/open.rs b/yazi-parser/src/mgr/open.rs new file mode 100644 index 00000000..9382d6db --- /dev/null +++ b/yazi-parser/src/mgr/open.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::CmdCow; + +#[derive(Clone, Copy)] +pub struct OpenOpt { + pub interactive: bool, + pub hovered: bool, +} + +impl From for OpenOpt { + fn from(c: CmdCow) -> Self { + Self { interactive: c.bool("interactive"), hovered: c.bool("hovered") } + } +} diff --git a/yazi-parser/src/mgr/paste.rs b/yazi-parser/src/mgr/paste.rs new file mode 100644 index 00000000..8ca75fad --- /dev/null +++ b/yazi-parser/src/mgr/paste.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::CmdCow; + +pub struct PasteOpt { + pub force: bool, + pub follow: bool, +} + +impl From for PasteOpt { + fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } +} diff --git a/yazi-parser/src/mgr/peek.rs b/yazi-parser/src/mgr/peek.rs new file mode 100644 index 00000000..fccc26f1 --- /dev/null +++ b/yazi-parser/src/mgr/peek.rs @@ -0,0 +1,24 @@ +use yazi_shared::{event::{CmdCow, Data}, url::Url}; + +#[derive(Debug, Default)] +pub struct PeekOpt { + pub skip: Option, + pub force: bool, + pub only_if: Option, + pub upper_bound: bool, +} + +impl From for PeekOpt { + fn from(mut c: CmdCow) -> Self { + Self { + skip: c.first().and_then(Data::as_usize), + force: c.bool("force"), + only_if: c.take_url("only-if"), + upper_bound: c.bool("upper-bound"), + } + } +} + +impl From for PeekOpt { + fn from(force: bool) -> Self { Self { force, ..Default::default() } } +} diff --git a/yazi-parser/src/mgr/quit.rs b/yazi-parser/src/mgr/quit.rs new file mode 100644 index 00000000..9dcad59c --- /dev/null +++ b/yazi-parser/src/mgr/quit.rs @@ -0,0 +1,22 @@ +use yazi_shared::event::{CmdCow, Data, EventQuit}; + +#[derive(Default)] +pub struct QuitOpt { + pub code: i32, + pub no_cwd_file: bool, +} + +impl From for QuitOpt { + fn from(c: CmdCow) -> Self { + Self { + code: c.get("code").and_then(Data::as_i32).unwrap_or_default(), + no_cwd_file: c.bool("no-cwd-file"), + } + } +} + +impl From for EventQuit { + fn from(value: QuitOpt) -> Self { + EventQuit { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() } + } +} diff --git a/yazi-parser/src/mgr/remove.rs b/yazi-parser/src/mgr/remove.rs new file mode 100644 index 00000000..dd425d77 --- /dev/null +++ b/yazi-parser/src/mgr/remove.rs @@ -0,0 +1,19 @@ +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct RemoveOpt { + pub force: bool, + pub permanently: bool, + pub hovered: bool, + pub targets: Vec, +} + +impl From for RemoveOpt { + fn from(mut c: CmdCow) -> Self { + Self { + force: c.bool("force"), + permanently: c.bool("permanently"), + hovered: c.bool("hovered"), + targets: c.take_any("targets").unwrap_or_default(), + } + } +} diff --git a/yazi-parser/src/mgr/rename.rs b/yazi-parser/src/mgr/rename.rs new file mode 100644 index 00000000..c4792921 --- /dev/null +++ b/yazi-parser/src/mgr/rename.rs @@ -0,0 +1,21 @@ +use std::borrow::Cow; + +use yazi_shared::event::CmdCow; + +pub struct RenameOpt { + pub hovered: bool, + pub force: bool, + pub empty: Cow<'static, str>, + pub cursor: Cow<'static, str>, +} + +impl From for RenameOpt { + fn from(mut c: CmdCow) -> Self { + Self { + hovered: c.bool("hovered"), + force: c.bool("force"), + empty: c.take_str("empty").unwrap_or_default(), + cursor: c.take_str("cursor").unwrap_or_default(), + } + } +} diff --git a/yazi-parser/src/mgr/seek.rs b/yazi-parser/src/mgr/seek.rs new file mode 100644 index 00000000..238e40dc --- /dev/null +++ b/yazi-parser/src/mgr/seek.rs @@ -0,0 +1,10 @@ +use yazi_shared::event::{CmdCow, Data}; + +#[derive(Debug)] +pub struct SeekOpt { + pub units: i16, +} + +impl From for SeekOpt { + fn from(c: CmdCow) -> Self { Self { units: c.first().and_then(Data::as_i16).unwrap_or(0) } } +} diff --git a/yazi-parser/src/mgr/spot.rs b/yazi-parser/src/mgr/spot.rs new file mode 100644 index 00000000..6618e84d --- /dev/null +++ b/yazi-parser/src/mgr/spot.rs @@ -0,0 +1,9 @@ +use yazi_shared::event::{CmdCow, Data}; + +pub struct SpotOpt { + pub skip: Option, +} + +impl From for SpotOpt { + fn from(c: CmdCow) -> Self { Self { skip: c.get("skip").and_then(Data::as_usize) } } +} diff --git a/yazi-parser/src/mgr/tab_close.rs b/yazi-parser/src/mgr/tab_close.rs new file mode 100644 index 00000000..546589f8 --- /dev/null +++ b/yazi-parser/src/mgr/tab_close.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::{CmdCow, Data}; + +pub struct TabCloseOpt { + pub idx: usize, +} + +impl From for TabCloseOpt { + fn from(c: CmdCow) -> Self { Self { idx: c.first().and_then(Data::as_usize).unwrap_or(0) } } +} + +impl From for TabCloseOpt { + fn from(idx: usize) -> Self { Self { idx } } +} diff --git a/yazi-parser/src/mgr/tab_create.rs b/yazi-parser/src/mgr/tab_create.rs new file mode 100644 index 00000000..64e352b4 --- /dev/null +++ b/yazi-parser/src/mgr/tab_create.rs @@ -0,0 +1,22 @@ +use yazi_boot::BOOT; +use yazi_fs::expand_path; +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct TabCreateOpt { + pub wd: Option, +} + +impl From for TabCreateOpt { + fn from(mut c: CmdCow) -> Self { + if c.bool("current") { + return Self { wd: None }; + } + let Some(mut wd) = c.take_first_url() else { + return Self { wd: Some(Url::from(&BOOT.cwds[0])) }; + }; + if wd.is_regular() && !c.bool("raw") { + wd = Url::from(expand_path(wd)); + } + Self { wd: Some(wd) } + } +} diff --git a/yazi-parser/src/mgr/tab_swap.rs b/yazi-parser/src/mgr/tab_swap.rs new file mode 100644 index 00000000..49e71df8 --- /dev/null +++ b/yazi-parser/src/mgr/tab_swap.rs @@ -0,0 +1,9 @@ +use yazi_shared::event::{CmdCow, Data}; + +pub struct TabSwapOpt { + pub step: isize, +} + +impl From for TabSwapOpt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +} diff --git a/yazi-parser/src/mgr/tab_switch.rs b/yazi-parser/src/mgr/tab_switch.rs new file mode 100644 index 00000000..680b8031 --- /dev/null +++ b/yazi-parser/src/mgr/tab_switch.rs @@ -0,0 +1,12 @@ +use yazi_shared::event::{CmdCow, Data}; + +pub struct TabSwitchOpt { + pub step: isize, + pub relative: bool, +} + +impl From for TabSwitchOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(Data::as_isize).unwrap_or(0), relative: c.bool("relative") } + } +} diff --git a/yazi-parser/src/mgr/unyank.rs b/yazi-parser/src/mgr/unyank.rs new file mode 100644 index 00000000..ce6a154e --- /dev/null +++ b/yazi-parser/src/mgr/unyank.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct UnyankOpt; + +impl From for UnyankOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for UnyankOpt { + fn from(_: ()) -> Self { Self } +} diff --git a/yazi-parser/src/mgr/update_files.rs b/yazi-parser/src/mgr/update_files.rs new file mode 100644 index 00000000..c4c7dfb1 --- /dev/null +++ b/yazi-parser/src/mgr/update_files.rs @@ -0,0 +1,14 @@ +use yazi_fs::FilesOp; +use yazi_shared::event::CmdCow; + +pub struct UpdateFilesOpt { + pub op: FilesOp, +} + +impl TryFrom for UpdateFilesOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { op: c.take_any("op").ok_or(())? }) + } +} diff --git a/yazi-parser/src/mgr/update_mimes.rs b/yazi-parser/src/mgr/update_mimes.rs new file mode 100644 index 00000000..637d1f6e --- /dev/null +++ b/yazi-parser/src/mgr/update_mimes.rs @@ -0,0 +1,15 @@ +use std::collections::HashMap; + +use yazi_shared::event::{CmdCow, Data, DataKey}; + +pub struct UpdateMimesOpt { + pub updates: HashMap, +} + +impl TryFrom for UpdateMimesOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { updates: c.try_take("updates").and_then(Data::into_dict).ok_or(())? }) + } +} diff --git a/yazi-parser/src/mgr/update_paged.rs b/yazi-parser/src/mgr/update_paged.rs new file mode 100644 index 00000000..7973a1b3 --- /dev/null +++ b/yazi-parser/src/mgr/update_paged.rs @@ -0,0 +1,17 @@ +use yazi_shared::{event::{CmdCow, Data}, url::Url}; + +#[derive(Default)] +pub struct UpdatePagedOpt { + pub page: Option, + pub only_if: Option, +} + +impl From for UpdatePagedOpt { + fn from(mut c: CmdCow) -> Self { + Self { page: c.first().and_then(Data::as_usize), only_if: c.take_url("only-if") } + } +} + +impl From<()> for UpdatePagedOpt { + fn from(_: ()) -> Self { Self::default() } +} diff --git a/yazi-parser/src/mgr/update_tasks.rs b/yazi-parser/src/mgr/update_tasks.rs new file mode 100644 index 00000000..c86e29f6 --- /dev/null +++ b/yazi-parser/src/mgr/update_tasks.rs @@ -0,0 +1,13 @@ +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct UpdateTasksOpt { + pub urls: Vec, +} + +impl TryFrom for UpdateTasksOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { urls: c.take_any("urls").ok_or(())? }) + } +} diff --git a/yazi-parser/src/mgr/update_yanked.rs b/yazi-parser/src/mgr/update_yanked.rs new file mode 100644 index 00000000..a1026b29 --- /dev/null +++ b/yazi-parser/src/mgr/update_yanked.rs @@ -0,0 +1,22 @@ +use std::collections::HashSet; + +use yazi_shared::{event::CmdCow, url::Url}; + +#[derive(Default)] +pub struct UpdateYankedOpt { + pub cut: bool, + pub urls: HashSet, +} + +impl TryFrom for UpdateYankedOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + // TODO: remove `BodyYankIter` + if let Some(iter) = c.take_any::("urls") { + Ok(Self { urls: iter.urls.into_iter().collect(), cut: iter.cut }) + } else { + Err(()) + } + } +} diff --git a/yazi-parser/src/mgr/watch.rs b/yazi-parser/src/mgr/watch.rs new file mode 100644 index 00000000..5bc2ca3a --- /dev/null +++ b/yazi-parser/src/mgr/watch.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct WatchOpt; + +impl From for WatchOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for WatchOpt { + fn from((): ()) -> Self { Self } +} diff --git a/yazi-parser/src/mgr/yank.rs b/yazi-parser/src/mgr/yank.rs new file mode 100644 index 00000000..6bfb1504 --- /dev/null +++ b/yazi-parser/src/mgr/yank.rs @@ -0,0 +1,9 @@ +use yazi_shared::event::CmdCow; + +pub struct YankOpt { + pub cut: bool, +} + +impl From for YankOpt { + fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut") } } +} diff --git a/yazi-parser/src/notify/mod.rs b/yazi-parser/src/notify/mod.rs new file mode 100644 index 00000000..b7ec7334 --- /dev/null +++ b/yazi-parser/src/notify/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(push tick); diff --git a/yazi-parser/src/notify/push.rs b/yazi-parser/src/notify/push.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/notify/tick.rs b/yazi-parser/src/notify/tick.rs new file mode 100644 index 00000000..f7d97951 --- /dev/null +++ b/yazi-parser/src/notify/tick.rs @@ -0,0 +1,26 @@ +use std::time::Duration; + +use yazi_shared::event::{Cmd, CmdCow, Data}; + +pub struct TickOpt { + pub interval: Duration, +} + +impl TryFrom for TickOpt { + type Error = (); + + fn try_from(c: CmdCow) -> Result { + let interval = c.first().and_then(Data::as_f64).ok_or(())?; + if interval < 0.0 { + return Err(()); + } + + Ok(Self { interval: Duration::from_secs_f64(interval) }) + } +} + +impl TryFrom for TickOpt { + type Error = (); + + fn try_from(c: Cmd) -> Result { Self::try_from(CmdCow::from(c)) } +} diff --git a/yazi-parser/src/pick/arrow.rs b/yazi-parser/src/pick/arrow.rs new file mode 100644 index 00000000..c54d5acc --- /dev/null +++ b/yazi-parser/src/pick/arrow.rs @@ -0,0 +1,12 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} diff --git a/yazi-parser/src/pick/close.rs b/yazi-parser/src/pick/close.rs new file mode 100644 index 00000000..fa516687 --- /dev/null +++ b/yazi-parser/src/pick/close.rs @@ -0,0 +1,13 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt { + pub submit: bool, +} + +impl From for CloseOpt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } +} + +impl From for CloseOpt { + fn from(submit: bool) -> Self { Self { submit } } +} diff --git a/yazi-parser/src/pick/mod.rs b/yazi-parser/src/pick/mod.rs new file mode 100644 index 00000000..e0fc92ad --- /dev/null +++ b/yazi-parser/src/pick/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow close show); diff --git a/yazi-parser/src/pick/show.rs b/yazi-parser/src/pick/show.rs new file mode 100644 index 00000000..8961bd4e --- /dev/null +++ b/yazi-parser/src/pick/show.rs @@ -0,0 +1,16 @@ +use tokio::sync::oneshot; +use yazi_config::popup::PickCfg; +use yazi_shared::event::CmdCow; + +pub struct ShowOpt { + pub cfg: PickCfg, + pub tx: oneshot::Sender>, +} + +impl TryFrom for ShowOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) + } +} diff --git a/yazi-parser/src/spot/arrow.rs b/yazi-parser/src/spot/arrow.rs new file mode 100644 index 00000000..c54d5acc --- /dev/null +++ b/yazi-parser/src/spot/arrow.rs @@ -0,0 +1,12 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} diff --git a/yazi-parser/src/spot/close.rs b/yazi-parser/src/spot/close.rs new file mode 100644 index 00000000..59462296 --- /dev/null +++ b/yazi-parser/src/spot/close.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt; + +impl From for CloseOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for CloseOpt { + fn from(_: ()) -> Self { Self } +} diff --git a/yazi-parser/src/spot/copy.rs b/yazi-parser/src/spot/copy.rs new file mode 100644 index 00000000..a4d19775 --- /dev/null +++ b/yazi-parser/src/spot/copy.rs @@ -0,0 +1,11 @@ +use std::borrow::Cow; + +use yazi_shared::event::CmdCow; + +pub struct CopyOpt { + pub r#type: Cow<'static, str>, +} + +impl From for CopyOpt { + fn from(mut c: CmdCow) -> Self { Self { r#type: c.take_first_str().unwrap_or_default() } } +} diff --git a/yazi-parser/src/spot/mod.rs b/yazi-parser/src/spot/mod.rs new file mode 100644 index 00000000..ac9dae93 --- /dev/null +++ b/yazi-parser/src/spot/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow close copy swipe); diff --git a/yazi-parser/src/spot/swipe.rs b/yazi-parser/src/spot/swipe.rs new file mode 100644 index 00000000..406a1d6d --- /dev/null +++ b/yazi-parser/src/spot/swipe.rs @@ -0,0 +1,11 @@ +use std::borrow::Cow; + +use yazi_shared::event::CmdCow; + +pub struct SwipeOpt { + pub step: Cow<'static, str>, +} + +impl From for SwipeOpt { + fn from(mut c: CmdCow) -> Self { Self { step: c.take_first_str().unwrap_or_default() } } +} diff --git a/yazi-parser/src/tab/arrow.rs b/yazi-parser/src/tab/arrow.rs new file mode 100644 index 00000000..29a1e04d --- /dev/null +++ b/yazi-parser/src/tab/arrow.rs @@ -0,0 +1,16 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} + +impl From for ArrowOpt { + fn from(n: isize) -> Self { Self { step: n.into() } } +} diff --git a/yazi-parser/src/tab/back.rs b/yazi-parser/src/tab/back.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/cd.rs b/yazi-parser/src/tab/cd.rs new file mode 100644 index 00000000..ab6e722a --- /dev/null +++ b/yazi-parser/src/tab/cd.rs @@ -0,0 +1,39 @@ +use yazi_fs::expand_path; +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct CdOpt { + pub target: Url, + pub interactive: bool, + pub source: CdSource, +} + +impl From for CdOpt { + fn from(mut c: CmdCow) -> Self { + let mut target = c.take_first_url().unwrap_or_default(); + if target.is_regular() && !c.bool("raw") { + target = Url::from(expand_path(target)); + } + Self { target, interactive: c.bool("interactive"), source: CdSource::Cd } + } +} + +impl From<(Url, CdSource)> for CdOpt { + fn from((target, source): (Url, CdSource)) -> Self { Self { target, interactive: false, source } } +} + +// --- Source +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum CdSource { + Tab, + Cd, + Reveal, + Enter, + Leave, + Forward, + Back, +} + +impl CdSource { + #[inline] + pub fn big_jump(self) -> bool { self == Self::Cd || self == Self::Reveal } +} diff --git a/yazi-parser/src/tab/copy.rs b/yazi-parser/src/tab/copy.rs new file mode 100644 index 00000000..02f54cdb --- /dev/null +++ b/yazi-parser/src/tab/copy.rs @@ -0,0 +1,48 @@ +use std::{borrow::Cow, ffi::OsStr, path::Path}; + +use yazi_shared::event::CmdCow; + +pub struct CopyOpt { + pub r#type: Cow<'static, str>, + pub separator: CopySeparator, + pub hovered: bool, +} + +impl From for CopyOpt { + fn from(mut c: CmdCow) -> Self { + Self { + r#type: c.take_first_str().unwrap_or_default(), + separator: c.str("separator").unwrap_or_default().into(), + hovered: c.bool("hovered"), + } + } +} + +// --- Separator +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum CopySeparator { + Auto, + Unix, +} + +impl From<&str> for CopySeparator { + fn from(value: &str) -> Self { + match value { + "unix" => Self::Unix, + _ => Self::Auto, + } + } +} + +impl CopySeparator { + pub fn transform + ?Sized>(self, p: &T) -> Cow<'_, OsStr> { + #[cfg(windows)] + if self == Self::Unix { + return match yazi_fs::backslash_to_slash(p.as_ref()) { + Cow::Owned(p) => Cow::Owned(p.into_os_string()), + Cow::Borrowed(p) => Cow::Borrowed(p.as_os_str()), + }; + } + Cow::Borrowed(p.as_ref().as_os_str()) + } +} diff --git a/yazi-parser/src/tab/enter.rs b/yazi-parser/src/tab/enter.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/escape.rs b/yazi-parser/src/tab/escape.rs new file mode 100644 index 00000000..10bef8cb --- /dev/null +++ b/yazi-parser/src/tab/escape.rs @@ -0,0 +1,28 @@ +use bitflags::bitflags; +use yazi_shared::event::CmdCow; + +bitflags! { + pub struct EscapeOpt: u8 { + const FIND = 0b00001; + const VISUAL = 0b00010; + const FILTER = 0b00100; + const SELECT = 0b01000; + const SEARCH = 0b10000; + } +} + +impl From for EscapeOpt { + fn from(c: CmdCow) -> Self { + c.args.iter().fold(EscapeOpt::empty(), |acc, (k, v)| { + match (k.as_str().unwrap_or(""), v.as_bool().unwrap_or(false)) { + ("all", true) => Self::all(), + ("find", true) => acc | Self::FIND, + ("visual", true) => acc | Self::VISUAL, + ("filter", true) => acc | Self::FILTER, + ("select", true) => acc | Self::SELECT, + ("search", true) => acc | Self::SEARCH, + _ => acc, + } + }) + } +} diff --git a/yazi-parser/src/tab/filter.rs b/yazi-parser/src/tab/filter.rs new file mode 100644 index 00000000..17ac3e1f --- /dev/null +++ b/yazi-parser/src/tab/filter.rs @@ -0,0 +1,21 @@ +use std::borrow::Cow; + +use yazi_fs::FilterCase; +use yazi_shared::event::CmdCow; + +#[derive(Default)] +pub struct FilterOpt { + pub query: Cow<'static, str>, + pub case: FilterCase, + pub done: bool, +} + +impl From for FilterOpt { + fn from(mut c: CmdCow) -> Self { + Self { + query: c.take_first_str().unwrap_or_default(), + case: FilterCase::from(&*c), + done: c.bool("done"), + } + } +} diff --git a/yazi-parser/src/tab/filter_do.rs b/yazi-parser/src/tab/filter_do.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/find.rs b/yazi-parser/src/tab/find.rs new file mode 100644 index 00000000..b6df3759 --- /dev/null +++ b/yazi-parser/src/tab/find.rs @@ -0,0 +1,16 @@ +use std::borrow::Cow; + +use yazi_fs::FilterCase; +use yazi_shared::event::CmdCow; + +pub struct FindOpt { + pub query: Option>, + pub prev: bool, + pub case: FilterCase, +} + +impl From for FindOpt { + fn from(mut c: CmdCow) -> Self { + Self { query: c.take_first_str(), prev: c.bool("previous"), case: FilterCase::from(&*c) } + } +} diff --git a/yazi-parser/src/tab/find_arrow.rs b/yazi-parser/src/tab/find_arrow.rs new file mode 100644 index 00000000..3936ae2b --- /dev/null +++ b/yazi-parser/src/tab/find_arrow.rs @@ -0,0 +1,9 @@ +use yazi_shared::event::CmdCow; + +pub struct FindArrowOpt { + pub prev: bool, +} + +impl From for FindArrowOpt { + fn from(c: CmdCow) -> Self { Self { prev: c.bool("previous") } } +} diff --git a/yazi-parser/src/tab/find_do.rs b/yazi-parser/src/tab/find_do.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/follow.rs b/yazi-parser/src/tab/follow.rs new file mode 100644 index 00000000..2edc8b92 --- /dev/null +++ b/yazi-parser/src/tab/follow.rs @@ -0,0 +1,7 @@ +use yazi_shared::event::CmdCow; + +pub struct FollowOpt; + +impl From for FollowOpt { + fn from(_: CmdCow) -> Self { Self } +} diff --git a/yazi-parser/src/tab/forward.rs b/yazi-parser/src/tab/forward.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/hidden.rs b/yazi-parser/src/tab/hidden.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/hover.rs b/yazi-parser/src/tab/hover.rs new file mode 100644 index 00000000..8975d333 --- /dev/null +++ b/yazi-parser/src/tab/hover.rs @@ -0,0 +1,13 @@ +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct HoverOpt { + pub url: Option, +} + +impl From for HoverOpt { + fn from(mut c: CmdCow) -> Self { Self { url: c.take_first_url() } } +} + +impl From> for HoverOpt { + fn from(url: Option) -> Self { Self { url } } +} diff --git a/yazi-parser/src/tab/leave.rs b/yazi-parser/src/tab/leave.rs new file mode 100644 index 00000000..62c868cf --- /dev/null +++ b/yazi-parser/src/tab/leave.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct LeaveOpt; + +impl From<()> for LeaveOpt { + fn from(_: ()) -> Self { Self } +} + +impl From for LeaveOpt { + fn from(_: CmdCow) -> Self { Self } +} diff --git a/yazi-parser/src/tab/linemode.rs b/yazi-parser/src/tab/linemode.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/mod.rs b/yazi-parser/src/tab/mod.rs new file mode 100644 index 00000000..e5f9291c --- /dev/null +++ b/yazi-parser/src/tab/mod.rs @@ -0,0 +1,28 @@ +yazi_macro::mod_flat!( + arrow + back + cd + copy + enter + escape + filter + filter_do + find + find_arrow + find_do + follow + forward + hidden + hover + leave + linemode + reveal + search + shell + sort + toggle + toggle_all + update_peeked + update_spotted + visual_mode +); diff --git a/yazi-parser/src/tab/reveal.rs b/yazi-parser/src/tab/reveal.rs new file mode 100644 index 00000000..c4d8d468 --- /dev/null +++ b/yazi-parser/src/tab/reveal.rs @@ -0,0 +1,29 @@ +use yazi_fs::expand_path; +use yazi_shared::{event::CmdCow, url::Url}; + +use crate::tab::CdSource; + +pub struct RevealOpt { + pub target: Url, + pub source: CdSource, + pub no_dummy: bool, +} + +impl From for RevealOpt { + fn from(mut c: CmdCow) -> Self { + let mut target = c.take_first_url().unwrap_or_default(); + if target.is_regular() && !c.bool("raw") { + target = Url::from(expand_path(target)); + } + + Self { target, source: CdSource::Reveal, no_dummy: c.bool("no-dummy") } + } +} + +impl From for RevealOpt { + fn from(target: Url) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } } +} + +impl From<(Url, CdSource)> for RevealOpt { + fn from((target, source): (Url, CdSource)) -> Self { Self { target, source, no_dummy: false } } +} diff --git a/yazi-parser/src/tab/search.rs b/yazi-parser/src/tab/search.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/shell.rs b/yazi-parser/src/tab/shell.rs new file mode 100644 index 00000000..ad059f72 --- /dev/null +++ b/yazi-parser/src/tab/shell.rs @@ -0,0 +1,38 @@ +use std::borrow::Cow; + +use anyhow::bail; +use yazi_shared::{event::{CmdCow, Data}, url::Url}; + +pub struct ShellOpt { + pub run: Cow<'static, str>, + pub cwd: Option, + + pub block: bool, + pub orphan: bool, + pub interactive: bool, + + pub cursor: Option, +} + +impl TryFrom for ShellOpt { + type Error = anyhow::Error; + + fn try_from(mut c: CmdCow) -> Result { + let me = Self { + run: c.take_first_str().unwrap_or_default(), + cwd: c.take_url("cwd"), + + block: c.bool("block"), + orphan: c.bool("orphan"), + interactive: c.bool("interactive"), + + cursor: c.get("cursor").and_then(Data::as_usize), + }; + + if me.cursor.is_some_and(|c| c > me.run.chars().count()) { + bail!("The cursor position is out of bounds."); + } + + Ok(me) + } +} diff --git a/yazi-parser/src/tab/sort.rs b/yazi-parser/src/tab/sort.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tab/toggle.rs b/yazi-parser/src/tab/toggle.rs new file mode 100644 index 00000000..45ff892f --- /dev/null +++ b/yazi-parser/src/tab/toggle.rs @@ -0,0 +1,19 @@ +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct ToggleOpt { + pub url: Option, + pub state: Option, +} + +impl From for ToggleOpt { + fn from(mut c: CmdCow) -> Self { + Self { + url: c.take_first_url(), + state: match c.str("state") { + Some("on") => Some(true), + Some("off") => Some(false), + _ => None, + }, + } + } +} diff --git a/yazi-parser/src/tab/toggle_all.rs b/yazi-parser/src/tab/toggle_all.rs new file mode 100644 index 00000000..03bcc071 --- /dev/null +++ b/yazi-parser/src/tab/toggle_all.rs @@ -0,0 +1,31 @@ +use yazi_shared::{event::CmdCow, url::Url}; + +pub struct ToggleAllOpt { + pub urls: Vec, + pub state: Option, +} + +impl From for ToggleAllOpt { + fn from(mut c: CmdCow) -> Self { + let mut urls = Vec::with_capacity(c.len()); + for i in 0..c.len() { + match c.take_url(i) { + Some(url) => urls.push(url), + None => break, + } + } + + Self { + urls, + state: match c.str("state") { + Some("on") => Some(true), + Some("off") => Some(false), + _ => None, + }, + } + } +} + +impl From> for ToggleAllOpt { + fn from(state: Option) -> Self { Self { urls: vec![], state } } +} diff --git a/yazi-parser/src/tab/update_peeked.rs b/yazi-parser/src/tab/update_peeked.rs new file mode 100644 index 00000000..856c3aab --- /dev/null +++ b/yazi-parser/src/tab/update_peeked.rs @@ -0,0 +1,44 @@ +use mlua::Table; +use yazi_binding::{FileRef, elements::{Rect, Renderable}}; +use yazi_shared::event::CmdCow; + +pub struct UpdatePeekedOpt { + pub lock: PreviewLock, +} + +impl TryFrom for UpdatePeekedOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { lock: c.take_any("lock").ok_or(())? }) + } +} + +// --- Lock +#[derive(Debug, Default)] +pub struct PreviewLock { + pub url: yazi_shared::url::Url, + pub cha: yazi_fs::cha::Cha, + pub mime: String, + + pub skip: usize, + pub area: Rect, + pub data: Vec, +} + +impl TryFrom
for PreviewLock { + type Error = mlua::Error; + + fn try_from(t: Table) -> Result { + let file: FileRef = t.raw_get("file")?; + Ok(Self { + url: file.url_owned(), + cha: file.cha, + mime: t.raw_get("mime")?, + + skip: t.raw_get("skip")?, + area: t.raw_get("area")?, + data: Default::default(), + }) + } +} diff --git a/yazi-parser/src/tab/update_spotted.rs b/yazi-parser/src/tab/update_spotted.rs new file mode 100644 index 00000000..4dd631ae --- /dev/null +++ b/yazi-parser/src/tab/update_spotted.rs @@ -0,0 +1,70 @@ +use mlua::Table; +use yazi_binding::{FileRef, elements::Renderable}; +use yazi_shared::{Id, event::CmdCow}; + +pub struct UpdateSpottedOpt { + pub lock: SpotLock, +} + +impl TryFrom for UpdateSpottedOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { lock: c.take_any("lock").ok_or(())? }) + } +} + +// --- Lock +pub struct SpotLock { + pub url: yazi_shared::url::Url, + pub cha: yazi_fs::cha::Cha, + pub mime: String, + + pub id: Id, + pub skip: usize, + pub data: Vec, +} + +impl TryFrom
for SpotLock { + type Error = mlua::Error; + + fn try_from(t: Table) -> Result { + let file: FileRef = t.raw_get("file")?; + Ok(Self { + url: file.url_owned(), + cha: file.cha, + mime: t.raw_get("mime")?, + + id: *t.raw_get::("id")?, + skip: t.raw_get("skip")?, + data: Default::default(), + }) + } +} + +impl SpotLock { + #[inline] + pub fn len(&self) -> Option { Some(self.table()?.len()) } + + pub fn select(&mut self, idx: Option) { + if let Some(t) = self.table_mut() { + t.select(idx); + } + } + + pub fn selected(&self) -> Option { self.table()?.selected() } + + pub fn table(&self) -> Option<&yazi_binding::elements::Table> { + self.data.iter().rev().find_map(|r| match r { + Renderable::Table(t) => Some(t.as_ref()), + _ => None, + }) + } + + pub fn table_mut(&mut self) -> Option<&mut yazi_binding::elements::Table> { + self.data.iter_mut().rev().find_map(|r| match r { + Renderable::Table(t) => Some(t.as_mut()), + _ => None, + }) + } +} diff --git a/yazi-parser/src/tab/visual_mode.rs b/yazi-parser/src/tab/visual_mode.rs new file mode 100644 index 00000000..c869eb21 --- /dev/null +++ b/yazi-parser/src/tab/visual_mode.rs @@ -0,0 +1,9 @@ +use yazi_shared::event::CmdCow; + +pub struct VisualModeOpt { + pub unset: bool, +} + +impl From for VisualModeOpt { + fn from(c: CmdCow) -> Self { Self { unset: c.bool("unset") } } +} diff --git a/yazi-parser/src/tasks/arrow.rs b/yazi-parser/src/tasks/arrow.rs new file mode 100644 index 00000000..29a1e04d --- /dev/null +++ b/yazi-parser/src/tasks/arrow.rs @@ -0,0 +1,16 @@ +use yazi_shared::event::CmdCow; +use yazi_widgets::Step; + +pub struct ArrowOpt { + pub step: Step, +} + +impl From for ArrowOpt { + fn from(c: CmdCow) -> Self { + Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() } + } +} + +impl From for ArrowOpt { + fn from(n: isize) -> Self { Self { step: n.into() } } +} diff --git a/yazi-parser/src/tasks/cancel.rs b/yazi-parser/src/tasks/cancel.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tasks/close.rs b/yazi-parser/src/tasks/close.rs new file mode 100644 index 00000000..59462296 --- /dev/null +++ b/yazi-parser/src/tasks/close.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct CloseOpt; + +impl From for CloseOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for CloseOpt { + fn from(_: ()) -> Self { Self } +} diff --git a/yazi-parser/src/tasks/inspect.rs b/yazi-parser/src/tasks/inspect.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tasks/mod.rs b/yazi-parser/src/tasks/mod.rs new file mode 100644 index 00000000..18559820 --- /dev/null +++ b/yazi-parser/src/tasks/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(arrow cancel close inspect open_with process_exec show); diff --git a/yazi-parser/src/tasks/open_with.rs b/yazi-parser/src/tasks/open_with.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tasks/process_exec.rs b/yazi-parser/src/tasks/process_exec.rs new file mode 100644 index 00000000..e69de29b diff --git a/yazi-parser/src/tasks/show.rs b/yazi-parser/src/tasks/show.rs new file mode 100644 index 00000000..7cf9070c --- /dev/null +++ b/yazi-parser/src/tasks/show.rs @@ -0,0 +1,11 @@ +use yazi_shared::event::CmdCow; + +pub struct ShowOpt; + +impl From for ShowOpt { + fn from(_: CmdCow) -> Self { Self } +} + +impl From<()> for ShowOpt { + fn from(_: ()) -> Self { Self } +} diff --git a/yazi-parser/src/which/callback.rs b/yazi-parser/src/which/callback.rs new file mode 100644 index 00000000..ab1e12ec --- /dev/null +++ b/yazi-parser/src/which/callback.rs @@ -0,0 +1,18 @@ +use tokio::sync::mpsc; +use yazi_shared::event::{CmdCow, Data}; + +pub struct CallbackOpt { + pub tx: mpsc::Sender, + pub idx: usize, +} + +impl TryFrom for CallbackOpt { + type Error = (); + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { + tx: c.take_any("tx").ok_or(())?, + idx: c.first().and_then(Data::as_usize).ok_or(())?, + }) + } +} diff --git a/yazi-parser/src/which/mod.rs b/yazi-parser/src/which/mod.rs new file mode 100644 index 00000000..ab7eaca0 --- /dev/null +++ b/yazi-parser/src/which/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(callback show); diff --git a/yazi-parser/src/which/show.rs b/yazi-parser/src/which/show.rs new file mode 100644 index 00000000..ec7fa392 --- /dev/null +++ b/yazi-parser/src/which/show.rs @@ -0,0 +1,15 @@ +use yazi_config::keymap::Chord; +use yazi_shared::event::CmdCow; + +pub struct ShowOpt { + pub cands: Vec, + pub silent: bool, +} + +impl TryFrom for ShowOpt { + type Error = anyhow::Error; + + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { cands: c.take_any("candidates").unwrap_or_default(), silent: c.bool("silent") }) + } +} diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index e3e183b6..ebd929ea 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -20,12 +20,13 @@ yazi-config = { path = "../yazi-config", version = "25.6.11" } yazi-dds = { path = "../yazi-dds", version = "25.6.11" } yazi-fs = { path = "../yazi-fs", version = "25.6.11" } yazi-macro = { path = "../yazi-macro", version = "25.6.11" } +yazi-parser = { path = "../yazi-parser", version = "25.6.11" } yazi-proxy = { path = "../yazi-proxy", version = "25.6.11" } yazi-shared = { path = "../yazi-shared", version = "25.6.11" } yazi-term = { path = "../yazi-term", version = "25.6.11" } +yazi-widgets = { path = "../yazi-widgets", version = "25.6.11" } # External dependencies -ansi-to-tui = { workspace = true } anyhow = { workspace = true } base64 = { workspace = true } crossterm = { workspace = true } @@ -50,8 +51,7 @@ libc = { workspace = true } uzers = { workspace = true } [target."cfg(windows)".dependencies] -clipboard-win = "5.4.0" -windows-sys = { version = "0.60.2", features = [ "Win32_System_JobObjects" ] } +windows-sys = { version = "0.60.2", features = [ "Win32_System_JobObjects" ] } [target.'cfg(target_os = "macos")'.dependencies] crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] } diff --git a/yazi-plugin/src/bindings/mod.rs b/yazi-plugin/src/bindings/mod.rs index d3d61fd7..6c802be4 100644 --- a/yazi-plugin/src/bindings/mod.rs +++ b/yazi-plugin/src/bindings/mod.rs @@ -1,3 +1,3 @@ #![allow(clippy::module_inception)] -yazi_macro::mod_flat!(calculator cha chan image input layer mouse permit range); +yazi_macro::mod_flat!(calculator chan image input layer mouse range); diff --git a/yazi-plugin/src/config/plugin.rs b/yazi-plugin/src/config/plugin.rs index 6e9d3430..5aff3789 100644 --- a/yazi-plugin/src/config/plugin.rs +++ b/yazi-plugin/src/config/plugin.rs @@ -1,9 +1,7 @@ use mlua::{Function, IntoLua, Lua, UserData, Value}; -use yazi_binding::{UrlRef, cached_field}; +use yazi_binding::{Composer, FileRef, UrlRef, cached_field}; use yazi_config::YAZI; -use crate::{Composer, file::FileRef}; - pub(super) struct Plugin; impl Plugin { diff --git a/yazi-plugin/src/config/runtime.rs b/yazi-plugin/src/config/runtime.rs index 18e5618e..62824938 100644 --- a/yazi-plugin/src/config/runtime.rs +++ b/yazi-plugin/src/config/runtime.rs @@ -1,10 +1,8 @@ use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value}; -use yazi_binding::Url; +use yazi_binding::{Composer, Url}; use yazi_boot::ARGS; use yazi_config::YAZI; -use crate::Composer; - pub const OPTS: SerializeOptions = SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false); diff --git a/yazi-plugin/src/config/term.rs b/yazi-plugin/src/config/term.rs index 510339c5..766d09f0 100644 --- a/yazi-plugin/src/config/term.rs +++ b/yazi-plugin/src/config/term.rs @@ -1,7 +1,6 @@ use mlua::{Function, IntoLua, IntoLuaMulti, Lua, Value}; use yazi_adapter::{Dimension, EMULATOR}; - -use crate::Composer; +use yazi_binding::Composer; pub(super) struct Term; diff --git a/yazi-plugin/src/config/theme.rs b/yazi-plugin/src/config/theme.rs index f30fab37..59e02503 100644 --- a/yazi-plugin/src/config/theme.rs +++ b/yazi-plugin/src/config/theme.rs @@ -1,9 +1,7 @@ use mlua::{IntoLua, Lua, Value}; -use yazi_binding::{Style, Url}; +use yazi_binding::{Composer, Style, Url}; use yazi_config::THEME; -use crate::Composer; - pub struct Theme; impl Theme { diff --git a/yazi-plugin/src/file/mod.rs b/yazi-plugin/src/file/mod.rs deleted file mode 100644 index b11417e9..00000000 --- a/yazi-plugin/src/file/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![allow(clippy::module_inception)] - -yazi_macro::mod_flat!(file); diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index 95c86e0f..2e5fc2ad 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -1,10 +1,10 @@ use globset::GlobBuilder; use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, Table, Value}; use tokio::fs; -use yazi_binding::{Error, Url, UrlRef}; +use yazi_binding::{Cha, Composer, Error, File, Url, UrlRef}; use yazi_fs::{mounts::PARTITIONS, remove_dir_clean}; -use crate::{Composer, bindings::{Cha, SizeCalculator}, file::File}; +use crate::bindings::SizeCalculator; pub fn compose(lua: &Lua) -> mlua::Result { Composer::make(lua, |lua, key| { diff --git a/yazi-plugin/src/fs/op.rs b/yazi-plugin/src/fs/op.rs index 1d6a338c..0fb91927 100644 --- a/yazi-plugin/src/fs/op.rs +++ b/yazi-plugin/src/fs/op.rs @@ -1,7 +1,5 @@ use mlua::{IntoLua, Lua, Table}; -use yazi_binding::{Id, Url, Urn}; - -use crate::{bindings::Cha, file::File}; +use yazi_binding::{Cha, File, Id, Url, Urn}; pub(super) struct FilesOp(yazi_fs::FilesOp); diff --git a/yazi-plugin/src/isolate/fetch.rs b/yazi-plugin/src/isolate/fetch.rs index 279b53e4..6253b627 100644 --- a/yazi-plugin/src/isolate/fetch.rs +++ b/yazi-plugin/src/isolate/fetch.rs @@ -1,11 +1,11 @@ use mlua::{ExternalResult, FromLua, IntoLua, Lua, ObjectLike, Value}; use tokio::runtime::Handle; -use yazi_binding::Error; +use yazi_binding::{Error, File}; use yazi_dds::Sendable; use yazi_shared::event::CmdCow; use super::slim_lua; -use crate::{file::File, loader::LOADER}; +use crate::loader::LOADER; pub async fn fetch( cmd: CmdCow, diff --git a/yazi-plugin/src/isolate/isolate.rs b/yazi-plugin/src/isolate/isolate.rs index 40afddc5..dd228728 100644 --- a/yazi-plugin/src/isolate/isolate.rs +++ b/yazi-plugin/src/isolate/isolate.rs @@ -1,22 +1,21 @@ use mlua::Lua; +use yazi_binding::Runtime; use yazi_macro::plugin_preset as preset; -use crate::runtime::Runtime; - pub fn slim_lua(name: &str) -> mlua::Result { let lua = Lua::new(); lua.set_app_data(Runtime::new(name)); // Base let globals = lua.globals(); - globals.raw_set("ui", crate::elements::compose(&lua)?)?; + globals.raw_set("ui", yazi_binding::elements::compose(&lua)?)?; globals.raw_set("ya", crate::utils::compose(&lua, true)?)?; globals.raw_set("fs", crate::fs::compose(&lua)?)?; globals.raw_set("rt", crate::config::Runtime::compose(&lua)?)?; globals.raw_set("th", crate::config::Theme::compose(&lua)?)?; - crate::bindings::Cha::install(&lua)?; - crate::file::File::install(&lua)?; + yazi_binding::Cha::install(&lua)?; + yazi_binding::File::install(&lua)?; yazi_binding::Url::install(&lua)?; yazi_binding::Error::install(&lua)?; diff --git a/yazi-plugin/src/isolate/peek.rs b/yazi-plugin/src/isolate/peek.rs index 07e732db..8da95248 100644 --- a/yazi-plugin/src/isolate/peek.rs +++ b/yazi-plugin/src/isolate/peek.rs @@ -4,13 +4,14 @@ use mlua::{ExternalError, HookTriggers, IntoLua, ObjectLike, VmState}; use tokio::{runtime::Handle, select}; use tokio_util::sync::CancellationToken; use tracing::error; +use yazi_binding::{File, elements::Rect}; use yazi_config::LAYOUT; use yazi_dds::Sendable; use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}}; use yazi_shared::event::Cmd; use super::slim_lua; -use crate::{elements::Rect, file::File, loader::LOADER}; +use crate::loader::LOADER; pub fn peek( cmd: &'static Cmd, diff --git a/yazi-plugin/src/isolate/preload.rs b/yazi-plugin/src/isolate/preload.rs index 97d0f6b3..8351a30b 100644 --- a/yazi-plugin/src/isolate/preload.rs +++ b/yazi-plugin/src/isolate/preload.rs @@ -1,13 +1,13 @@ use mlua::{ExternalError, ExternalResult, HookTriggers, IntoLua, ObjectLike, VmState}; use tokio::{runtime::Handle, select}; use tokio_util::sync::CancellationToken; -use yazi_binding::Error; +use yazi_binding::{Error, File, elements::Rect}; use yazi_config::LAYOUT; use yazi_dds::Sendable; use yazi_shared::event::Cmd; use super::slim_lua; -use crate::{elements::Rect, file::File, loader::LOADER}; +use crate::loader::LOADER; pub async fn preload( cmd: &'static Cmd, diff --git a/yazi-plugin/src/isolate/seek.rs b/yazi-plugin/src/isolate/seek.rs index de7db600..21f9f501 100644 --- a/yazi-plugin/src/isolate/seek.rs +++ b/yazi-plugin/src/isolate/seek.rs @@ -1,10 +1,9 @@ use mlua::{IntoLua, ObjectLike}; +use yazi_binding::{File, elements::Rect}; use yazi_config::LAYOUT; use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}}; use yazi_shared::event::Cmd; -use crate::{elements::Rect, file::File}; - pub fn seek_sync(cmd: &'static Cmd, file: yazi_fs::File, units: i16) { let cb: PluginCallback = Box::new(move |lua, plugin| { let job = lua.create_table_from([ diff --git a/yazi-plugin/src/isolate/spot.rs b/yazi-plugin/src/isolate/spot.rs index 9f03ad66..b563aedf 100644 --- a/yazi-plugin/src/isolate/spot.rs +++ b/yazi-plugin/src/isolate/spot.rs @@ -4,12 +4,12 @@ use mlua::{ExternalError, ExternalResult, HookTriggers, IntoLua, ObjectLike, VmS use tokio::{runtime::Handle, select}; use tokio_util::sync::CancellationToken; use tracing::error; -use yazi_binding::Id; +use yazi_binding::{File, Id}; use yazi_dds::Sendable; use yazi_shared::{Ids, event::Cmd}; use super::slim_lua; -use crate::{file::File, loader::LOADER}; +use crate::loader::LOADER; static IDS: Ids = Ids::new(); diff --git a/yazi-plugin/src/lib.rs b/yazi-plugin/src/lib.rs index 3999b243..cc581e8b 100644 --- a/yazi-plugin/src/lib.rs +++ b/yazi-plugin/src/lib.rs @@ -1,14 +1,10 @@ #![allow(clippy::if_same_then_else, clippy::unit_arg)] -mod macros; +yazi_macro::mod_pub!(bindings config external fs isolate loader process pubsub utils); -yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub utils); - -yazi_macro::mod_flat!(clipboard composer lua runtime twox); +yazi_macro::mod_flat!(lua twox); pub fn init() -> anyhow::Result<()> { - CLIPBOARD.with(<_>::default); - crate::loader::init(); crate::init_lua()?; Ok(()) diff --git a/yazi-plugin/src/loader/require.rs b/yazi-plugin/src/loader/require.rs index 0351953e..fcb3a707 100644 --- a/yazi-plugin/src/loader/require.rs +++ b/yazi-plugin/src/loader/require.rs @@ -1,9 +1,9 @@ use std::sync::Arc; use mlua::{ExternalResult, Function, IntoLua, Lua, MetaMethod, MultiValue, ObjectLike, Table, Value}; +use yazi_binding::runtime_mut; use super::LOADER; -use crate::runtime_mut; pub(super) struct Require; diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs index 3fea3abb..ebdb6791 100644 --- a/yazi-plugin/src/lua.rs +++ b/yazi-plugin/src/lua.rs @@ -1,11 +1,10 @@ use anyhow::{Context, Result}; use mlua::Lua; +use yazi_binding::Runtime; use yazi_boot::BOOT; use yazi_macro::plugin_preset as preset; use yazi_shared::RoCell; -use crate::runtime::Runtime; - pub static LUA: RoCell = RoCell::new(); pub(super) fn init_lua() -> Result<()> { @@ -21,7 +20,7 @@ fn stage_1(lua: &'static Lua) -> Result<()> { // Base let globals = lua.globals(); - globals.raw_set("ui", crate::elements::compose(lua)?)?; + globals.raw_set("ui", yazi_binding::elements::compose(lua)?)?; globals.raw_set("ya", crate::utils::compose(lua, false)?)?; globals.raw_set("fs", crate::fs::compose(lua)?)?; globals.raw_set("ps", crate::pubsub::compose(lua)?)?; @@ -29,9 +28,9 @@ fn stage_1(lua: &'static Lua) -> Result<()> { globals.raw_set("th", crate::config::Theme::compose(lua)?)?; yazi_binding::Error::install(lua)?; - crate::bindings::Cha::install(lua)?; + yazi_binding::Cha::install(lua)?; crate::loader::install(lua)?; - crate::file::File::install(lua)?; + yazi_binding::File::install(lua)?; yazi_binding::Url::install(lua)?; // Addons diff --git a/yazi-plugin/src/macros.rs b/yazi-plugin/src/macros.rs deleted file mode 100644 index 9585290d..00000000 --- a/yazi-plugin/src/macros.rs +++ /dev/null @@ -1,85 +0,0 @@ -#[macro_export] -macro_rules! impl_style_method { - ($methods:ident, $($field:tt).+) => { - $methods.add_function_mut("style", |_, (ud, value): (mlua::AnyUserData, mlua::Value)| { - ud.borrow_mut::()?.$($field).+ = yazi_binding::Style::try_from(value)?.0; - Ok(ud) - }); - }; -} - -#[macro_export] -macro_rules! impl_area_method { - ($methods:ident) => { - $methods.add_function_mut( - "area", - |lua, (ud, area): (mlua::AnyUserData, Option)| { - use mlua::IntoLua; - if let Some(v) = area { - ud.borrow_mut::()?.area = $crate::elements::Area::try_from(v)?; - ud.into_lua(lua) - } else { - ud.borrow::()?.area.into_lua(lua) - } - }, - ); - }; -} - -#[macro_export] -macro_rules! impl_file_fields { - ($fields:ident) => { - yazi_binding::cached_field!($fields, cha, |_, me| Ok($crate::bindings::Cha(me.cha))); - yazi_binding::cached_field!($fields, url, |_, me| Ok(yazi_binding::Url::new(me.url_owned()))); - yazi_binding::cached_field!($fields, link_to, |_, me| Ok( - me.link_to.clone().map(yazi_binding::Url::new) - )); - - yazi_binding::cached_field!($fields, name, |lua, me| { - Some(me.name()) - .filter(|s| !s.is_empty()) - .map(|s| lua.create_string(s.as_encoded_bytes())) - .transpose() - }); - }; -} - -#[macro_export] -macro_rules! impl_file_methods { - ($methods:ident) => { - $methods.add_method("hash", |_, me, ()| Ok(me.hash_u64())); - - $methods.add_method("icon", |_, me, ()| { - use yazi_binding::Icon; - // TODO: use a cache - Ok(yazi_config::THEME.icon.matches(me).map(Icon::from)) - }); - }; -} - -#[macro_export] -macro_rules! runtime { - ($lua:ident) => {{ - use mlua::ExternalError; - $lua.app_data_ref::<$crate::Runtime>().ok_or_else(|| "Runtime not found".into_lua_err()) - }}; -} - -#[macro_export] -macro_rules! runtime_mut { - ($lua:ident) => {{ - use mlua::ExternalError; - $lua.app_data_mut::<$crate::Runtime>().ok_or_else(|| "Runtime not found".into_lua_err()) - }}; -} - -#[macro_export] -macro_rules! deprecate { - ($lua:ident, $tt:tt) => {{ - let id = match $crate::runtime!($lua)?.current() { - Some(id) => &format!("`{id}.yazi` plugin"), - None => "`init.lua` config", - }; - yazi_proxy::deprecate!(format!($tt, id)); - }}; -} diff --git a/yazi-plugin/src/pubsub/mod.rs b/yazi-plugin/src/pubsub/mod.rs index c984157f..42d8c425 100644 --- a/yazi-plugin/src/pubsub/mod.rs +++ b/yazi-plugin/src/pubsub/mod.rs @@ -1,8 +1,7 @@ #![allow(clippy::module_inception)] use mlua::{IntoLua, Lua, Value}; - -use crate::Composer; +use yazi_binding::Composer; yazi_macro::mod_flat!(pubsub); diff --git a/yazi-plugin/src/pubsub/pubsub.rs b/yazi-plugin/src/pubsub/pubsub.rs index a3132923..750765e2 100644 --- a/yazi-plugin/src/pubsub/pubsub.rs +++ b/yazi-plugin/src/pubsub/pubsub.rs @@ -1,9 +1,7 @@ use mlua::{ExternalResult, Function, Lua, Value}; -use yazi_binding::Id; +use yazi_binding::{Id, runtime}; use yazi_dds::body::Body; -use crate::runtime; - pub struct Pubsub; impl Pubsub { diff --git a/yazi-plugin/src/utils/app.rs b/yazi-plugin/src/utils/app.rs index 11250a13..c3d07048 100644 --- a/yazi-plugin/src/utils/app.rs +++ b/yazi-plugin/src/utils/app.rs @@ -1,9 +1,8 @@ use mlua::{AnyUserData, ExternalError, Function, Lua}; -use yazi_binding::Id; +use yazi_binding::{Id, Permit, PermitRef, deprecate}; use yazi_proxy::{AppProxy, HIDER}; use super::Utils; -use crate::{bindings::{Permit, PermitRef}, deprecate}; impl Utils { pub(super) fn id(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/cache.rs b/yazi-plugin/src/utils/cache.rs index 9668db42..c5ffbdc5 100644 --- a/yazi-plugin/src/utils/cache.rs +++ b/yazi-plugin/src/utils/cache.rs @@ -1,11 +1,11 @@ use std::hash::Hash; use mlua::{Function, Lua, Table}; -use yazi_binding::Url; +use yazi_binding::{FileRef, Url}; use yazi_config::YAZI; use super::Utils; -use crate::{Twox128, file::FileRef}; +use crate::Twox128; impl Utils { pub(super) fn file_cache(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/call.rs b/yazi-plugin/src/utils/call.rs index 8dffbe93..564cc253 100644 --- a/yazi-plugin/src/utils/call.rs +++ b/yazi-plugin/src/utils/call.rs @@ -1,10 +1,10 @@ use mlua::{Function, Lua, Table}; +use yazi_binding::deprecate; use yazi_dds::Sendable; use yazi_macro::{emit, render}; use yazi_shared::{Layer, event::Cmd}; use super::Utils; -use crate::deprecate; impl Utils { pub(super) fn render(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/image.rs b/yazi-plugin/src/utils/image.rs index b1c700ab..5e840fa4 100644 --- a/yazi-plugin/src/utils/image.rs +++ b/yazi-plugin/src/utils/image.rs @@ -1,9 +1,9 @@ use mlua::{Function, IntoLuaMulti, Lua, Value}; use yazi_adapter::{ADAPTOR, Image}; -use yazi_binding::{Error, UrlRef}; +use yazi_binding::{Error, UrlRef, elements::Rect}; use super::Utils; -use crate::{bindings::ImageInfo, elements::Rect}; +use crate::bindings::ImageInfo; impl Utils { pub(super) fn image_info(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/layer.rs b/yazi-plugin/src/utils/layer.rs index f3c0ee48..a2abc27a 100644 --- a/yazi-plugin/src/utils/layer.rs +++ b/yazi-plugin/src/utils/layer.rs @@ -3,13 +3,14 @@ use std::{str::FromStr, time::Duration}; use mlua::{ExternalError, ExternalResult, Function, IntoLuaMulti, Lua, Table, Value}; use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; +use yazi_binding::{deprecate, elements::{Line, Pos, Text}}; use yazi_config::{keymap::{Chord, Key}, popup::{ConfirmCfg, InputCfg}}; use yazi_macro::emit; use yazi_proxy::{AppProxy, ConfirmProxy, InputProxy}; use yazi_shared::{Debounce, event::Cmd}; use super::Utils; -use crate::{bindings::InputRx, deprecate, elements::{Line, Pos, Text}}; +use crate::bindings::InputRx; impl Utils { pub(super) fn which(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/preview.rs b/yazi-plugin/src/utils/preview.rs index e3fd6784..55a95a61 100644 --- a/yazi-plugin/src/utils/preview.rs +++ b/yazi-plugin/src/utils/preview.rs @@ -1,39 +1,12 @@ use mlua::{AnyUserData, ExternalError, Function, IntoLuaMulti, Lua, Table, Value}; -use yazi_binding::Error; +use yazi_binding::{Error, elements::{Area, Renderable, Text}}; use yazi_config::YAZI; use yazi_macro::emit; +use yazi_parser::tab::PreviewLock; use yazi_shared::{errors::PeekError, event::Cmd}; use super::Utils; -use crate::{elements::{Area, Rect, Renderable, Text}, external::Highlighter, file::FileRef}; - -#[derive(Debug, Default)] -pub struct PreviewLock { - pub url: yazi_shared::url::Url, - pub cha: yazi_fs::cha::Cha, - pub mime: String, - - pub skip: usize, - pub area: Rect, - pub data: Vec, -} - -impl TryFrom
for PreviewLock { - type Error = mlua::Error; - - fn try_from(t: Table) -> Result { - let file: FileRef = t.raw_get("file")?; - Ok(Self { - url: file.url_owned(), - cha: file.cha, - mime: t.raw_get("mime")?, - - skip: t.raw_get("skip")?, - area: t.raw_get("area")?, - data: Default::default(), - }) - } -} +use crate::external::Highlighter; impl Utils { pub(super) fn preview_code(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/spot.rs b/yazi-plugin/src/utils/spot.rs index 17b680da..743573eb 100644 --- a/yazi-plugin/src/utils/spot.rs +++ b/yazi-plugin/src/utils/spot.rs @@ -1,77 +1,24 @@ use mlua::{AnyUserData, Function, Lua, Table}; +use yazi_binding::elements::{Edge, Renderable}; use yazi_config::THEME; use yazi_macro::emit; -use yazi_shared::{Id, event::Cmd}; +use yazi_parser::tab::SpotLock; +use yazi_shared::event::Cmd; use super::Utils; -use crate::{elements::{Edge, Renderable}, file::FileRef}; - -pub struct SpotLock { - pub url: yazi_shared::url::Url, - pub cha: yazi_fs::cha::Cha, - pub mime: String, - - pub id: Id, - pub skip: usize, - pub data: Vec, -} - -impl TryFrom
for SpotLock { - type Error = mlua::Error; - - fn try_from(t: Table) -> Result { - let file: FileRef = t.raw_get("file")?; - Ok(Self { - url: file.url_owned(), - cha: file.cha, - mime: t.raw_get("mime")?, - - id: *t.raw_get::("id")?, - skip: t.raw_get("skip")?, - data: Default::default(), - }) - } -} - -impl SpotLock { - #[inline] - pub fn len(&self) -> Option { Some(self.table()?.len()) } - - pub fn select(&mut self, idx: Option) { - if let Some(t) = self.table_mut() { - t.select(idx); - } - } - - pub fn selected(&self) -> Option { self.table()?.selected() } - - pub fn table(&self) -> Option<&crate::elements::Table> { - self.data.iter().rev().find_map(|r| match r { - Renderable::Table(t) => Some(t.as_ref()), - _ => None, - }) - } - - pub fn table_mut(&mut self) -> Option<&mut crate::elements::Table> { - self.data.iter_mut().rev().find_map(|r| match r { - Renderable::Table(t) => Some(t.as_mut()), - _ => None, - }) - } -} impl Utils { pub(super) fn spot_table(lua: &Lua) -> mlua::Result { lua.create_function(|_, (t, table): (mlua::Table, AnyUserData)| { let mut lock = SpotLock::try_from(t)?; - let mut table = crate::elements::Table::try_from(table)?; + let mut table = yazi_binding::elements::Table::try_from(table)?; let area = table.area; table.area = area.inner(ratatui::widgets::Padding::uniform(1)); lock.data = vec![ - Renderable::Clear(crate::elements::Clear { area }), - Renderable::Border(crate::elements::Border { + Renderable::Clear(yazi_binding::elements::Clear { area }), + Renderable::Border(yazi_binding::elements::Border { area, edge: Edge(ratatui::widgets::Borders::ALL), r#type: ratatui::widgets::BorderType::Rounded, diff --git a/yazi-plugin/src/utils/sync.rs b/yazi-plugin/src/utils/sync.rs index dededa66..5948dcfd 100644 --- a/yazi-plugin/src/utils/sync.rs +++ b/yazi-plugin/src/utils/sync.rs @@ -1,12 +1,13 @@ use futures::future::join_all; use mlua::{ExternalError, ExternalResult, Function, IntoLuaMulti, Lua, MultiValue, Value, Variadic}; use tokio::sync::oneshot; +use yazi_binding::{runtime, runtime_mut}; use yazi_dds::Sendable; use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}}; use yazi_shared::event::Data; use super::Utils; -use crate::{bindings::{MpscRx, MpscTx, MpscUnboundedRx, MpscUnboundedTx, OneshotRx, OneshotTx}, loader::LOADER, runtime, runtime_mut}; +use crate::{bindings::{MpscRx, MpscTx, MpscUnboundedRx, MpscUnboundedTx, OneshotRx, OneshotTx}, loader::LOADER}; impl Utils { pub(super) fn sync(lua: &Lua, isolate: bool) -> mlua::Result { diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index df701968..0fffee25 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -1,9 +1,10 @@ use mlua::{Function, Lua, Table}; use twox_hash::XxHash3_128; use unicode_width::UnicodeWidthChar; +use yazi_binding::deprecate; +use yazi_widgets::CLIPBOARD; use super::Utils; -use crate::{CLIPBOARD, deprecate}; impl Utils { pub(super) fn hash(lua: &Lua) -> mlua::Result { diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 7aa988a5..426ee7dc 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -1,6 +1,5 @@ use mlua::{IntoLua, Lua, Value}; - -use crate::Composer; +use yazi_binding::Composer; pub(super) struct Utils; diff --git a/yazi-widgets/Cargo.toml b/yazi-widgets/Cargo.toml index c6038573..3a575658 100644 --- a/yazi-widgets/Cargo.toml +++ b/yazi-widgets/Cargo.toml @@ -9,18 +9,25 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] +yazi-binding = { path = "../yazi-binding", version = "25.6.11" } yazi-codegen = { path = "../yazi-codegen", version = "25.6.11" } yazi-config = { path = "../yazi-config", version = "25.6.11" } yazi-macro = { path = "../yazi-macro", version = "25.6.11" } -yazi-plugin = { path = "../yazi-plugin", version = "25.6.11" } yazi-proxy = { path = "../yazi-proxy", version = "25.6.11" } yazi-shared = { path = "../yazi-shared", version = "25.6.11" } +yazi-term = { path = "../yazi-term", version = "25.6.11" } # External dependencies +base64 = { workspace = true } crossterm = { workspace = true } futures = { workspace = true } +parking_lot = { workspace = true } ratatui = { workspace = true } +tokio = { workspace = true } unicode-width = { workspace = true } +[target."cfg(windows)".dependencies] +clipboard-win = "5.4.0" + [target.'cfg(target_os = "macos")'.dependencies] crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] } diff --git a/yazi-plugin/src/clipboard.rs b/yazi-widgets/src/clipboard.rs similarity index 100% rename from yazi-plugin/src/clipboard.rs rename to yazi-widgets/src/clipboard.rs diff --git a/yazi-widgets/src/input/commands/paste.rs b/yazi-widgets/src/input/commands/paste.rs index 4e58a809..1889dea9 100644 --- a/yazi-widgets/src/input/commands/paste.rs +++ b/yazi-widgets/src/input/commands/paste.rs @@ -1,8 +1,7 @@ use yazi_macro::render; -use yazi_plugin::CLIPBOARD; use yazi_shared::event::CmdCow; -use crate::input::{Input, op::InputOp}; +use crate::{CLIPBOARD, input::{Input, op::InputOp}}; struct Opt { before: bool, diff --git a/yazi-widgets/src/input/input.rs b/yazi-widgets/src/input/input.rs index 697e4e87..8c636592 100644 --- a/yazi-widgets/src/input/input.rs +++ b/yazi-widgets/src/input/input.rs @@ -2,9 +2,9 @@ use std::{borrow::Cow, ops::Range}; use crossterm::cursor::SetCursorStyle; use yazi_config::YAZI; -use yazi_plugin::CLIPBOARD; use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp}; +use crate::CLIPBOARD; pub type InputCallback = Box; diff --git a/yazi-widgets/src/input/widget.rs b/yazi-widgets/src/input/widget.rs index fee55ac1..754ecebf 100644 --- a/yazi-widgets/src/input/widget.rs +++ b/yazi-widgets/src/input/widget.rs @@ -10,7 +10,7 @@ impl Widget for &Input { where Self: Sized, { - yazi_plugin::elements::Clear::default().render(area, buf); + yazi_binding::elements::Clear::default().render(area, buf); Line::styled(self.display(), THEME.input.value).render(area, buf); diff --git a/yazi-widgets/src/lib.rs b/yazi-widgets/src/lib.rs index dc1f4256..410d0cc2 100644 --- a/yazi-widgets/src/lib.rs +++ b/yazi-widgets/src/lib.rs @@ -1,3 +1,5 @@ yazi_macro::mod_pub!(input); -yazi_macro::mod_flat!(scrollable step); +yazi_macro::mod_flat!(clipboard scrollable step); + +pub fn init() { CLIPBOARD.with(<_>::default); }