From 63f78f82fbc4d6141e5b2b183c9920623da93a21 Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Tue, 30 Apr 2024 17:16:38 +0300 Subject: [PATCH] refactor: move CLIPBOARD from yazi-core -> yazi-plugin This needs to be done because we want to make it possible to use the clipboard in lua plugins. Before this change, the clipboard was only available in the yazi-core crate, which depends on yazi-plugin. The lua plugins are configured in the yazi-plugin crate, but it can't use anything from yazi-core, because it would create a circular dependency. --- Cargo.lock | 4 +++- yazi-core/Cargo.toml | 3 --- yazi-core/src/input/commands/paste.rs | 3 ++- yazi-core/src/input/input.rs | 2 +- yazi-core/src/lib.rs | 4 ---- yazi-core/src/tab/commands/copy.rs | 3 ++- yazi-plugin/Cargo.toml | 5 +++++ {yazi-core => yazi-plugin}/src/clipboard.rs | 0 yazi-plugin/src/lib.rs | 3 +++ 9 files changed, 16 insertions(+), 11 deletions(-) rename {yazi-core => yazi-plugin}/src/clipboard.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f06f724e..5a6d67f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2764,7 +2764,6 @@ dependencies = [ "anyhow", "base64 0.22.0", "bitflags 2.5.0", - "clipboard-win", "crossterm", "futures", "libc", @@ -2843,6 +2842,9 @@ version = "0.2.5" dependencies = [ "ansi-to-tui", "anyhow", + "base64 0.22.0", + "clipboard-win", + "crossterm", "futures", "md-5", "mlua", diff --git a/yazi-core/Cargo.toml b/yazi-core/Cargo.toml index d7dc8b00..ed3f7ff0 100644 --- a/yazi-core/Cargo.toml +++ b/yazi-core/Cargo.toml @@ -40,6 +40,3 @@ tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_lev [target."cfg(unix)".dependencies] libc = "0.2.153" - -[target."cfg(windows)".dependencies] -clipboard-win = "5.3.1" diff --git a/yazi-core/src/input/commands/paste.rs b/yazi-core/src/input/commands/paste.rs index 4cd88758..2c313ea4 100644 --- a/yazi-core/src/input/commands/paste.rs +++ b/yazi-core/src/input/commands/paste.rs @@ -1,6 +1,7 @@ +use yazi_plugin::CLIPBOARD; use yazi_shared::{event::Cmd, render}; -use crate::{input::{op::InputOp, Input}, CLIPBOARD}; +use crate::input::{op::InputOp, Input}; pub struct Opt { before: bool, diff --git a/yazi-core/src/input/input.rs b/yazi-core/src/input/input.rs index 99e9d27d..243f24dc 100644 --- a/yazi-core/src/input/input.rs +++ b/yazi-core/src/input/input.rs @@ -3,10 +3,10 @@ use std::ops::Range; use tokio::sync::mpsc::UnboundedSender; use unicode_width::UnicodeWidthStr; use yazi_config::{popup::Position, INPUT}; +use yazi_plugin::CLIPBOARD; use yazi_shared::{render, InputError}; use super::{mode::InputMode, op::InputOp, InputSnap, InputSnaps}; -use crate::CLIPBOARD; #[derive(Default)] pub struct Input { diff --git a/yazi-core/src/lib.rs b/yazi-core/src/lib.rs index 43ab4f08..9850ca81 100644 --- a/yazi-core/src/lib.rs +++ b/yazi-core/src/lib.rs @@ -6,7 +6,6 @@ clippy::unit_arg )] -mod clipboard; pub mod completion; pub mod folder; pub mod help; @@ -19,12 +18,9 @@ pub mod tab; pub mod tasks; pub mod which; -pub use clipboard::*; pub use step::*; pub fn init() { - CLIPBOARD.with(Default::default); - manager::WATCHED.with(Default::default); manager::LINKED.with(Default::default); } diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index 22344720..6c8e0bb4 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -1,8 +1,9 @@ use std::ffi::{OsStr, OsString}; +use yazi_plugin::CLIPBOARD; use yazi_shared::event::Cmd; -use crate::{tab::Tab, CLIPBOARD}; +use crate::tab::Tab; pub struct Opt { type_: String, diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index 55033878..4c89ac79 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -23,6 +23,8 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" } # External dependencies ansi-to-tui = "3.1.0" anyhow = "1.0.82" +base64 = "0.22.0" +crossterm = "0.27.0" futures = "0.3.30" md-5 = "0.10.6" mlua = { version = "0.9.7", features = [ "lua54", "serialize", "macros", "async" ] } @@ -43,3 +45,6 @@ tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_lev [target."cfg(unix)".dependencies] uzers = "0.11.3" + +[target."cfg(windows)".dependencies] +clipboard-win = "5.3.1" diff --git a/yazi-core/src/clipboard.rs b/yazi-plugin/src/clipboard.rs similarity index 100% rename from yazi-core/src/clipboard.rs rename to yazi-plugin/src/clipboard.rs diff --git a/yazi-plugin/src/lib.rs b/yazi-plugin/src/lib.rs index 069f6649..0d0bc923 100644 --- a/yazi-plugin/src/lib.rs +++ b/yazi-plugin/src/lib.rs @@ -2,6 +2,7 @@ pub mod bindings; mod cast; +pub mod clipboard; mod config; pub mod elements; pub mod external; @@ -17,6 +18,7 @@ pub mod url; pub mod utils; pub use cast::*; +pub use clipboard::*; pub use config::*; pub use lua::*; pub use opt::*; @@ -25,4 +27,5 @@ pub use runtime::*; pub fn init() { crate::loader::init(); crate::init_lua(); + CLIPBOARD.with(Default::default); }