This commit is contained in:
sxyazi 2024-04-09 01:01:30 +08:00
parent 63b20ba2cb
commit bfdbe4ffa0
No known key found for this signature in database
5 changed files with 12 additions and 29 deletions

View file

@ -3,7 +3,7 @@ use yazi_shared::event::Cmd;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};
pub struct Opt { pub struct Opt {
force: bool, force: bool,
follow: bool, follow: bool,
} }

View file

@ -2,9 +2,7 @@ use anyhow::Result;
use mlua::{ExternalResult, IntoLua, Lua, Value}; use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::Serialize; use serde::Serialize;
use super::{ use super::{BodyBulk, BodyCd, BodyCustom, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyYank};
BodyBulk, BodyCd, BodyCustom, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyYank,
};
use crate::Payload; use crate::Payload;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]

View file

@ -9,7 +9,7 @@ use super::Body;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct BodyMove<'a> { pub struct BodyMove<'a> {
pub from: Cow<'a, Url>, pub from: Cow<'a, Url>,
pub to: Cow<'a, Url>, pub to: Cow<'a, Url>,
} }
impl<'a> BodyMove<'a> { impl<'a> BodyMove<'a> {
@ -27,9 +27,7 @@ impl BodyMove<'static> {
} }
impl<'a> From<BodyMove<'a>> for Body<'a> { impl<'a> From<BodyMove<'a>> for Body<'a> {
fn from(value: BodyMove<'a>) -> Self { fn from(value: BodyMove<'a>) -> Self { Self::Move(value) }
Self::Move(value)
}
} }
impl IntoLua<'_> for BodyMove<'static> { impl IntoLua<'_> for BodyMove<'static> {

View file

@ -9,18 +9,14 @@ use crate::{body::Body, ID};
#[derive(Debug)] #[derive(Debug)]
pub struct Payload<'a> { pub struct Payload<'a> {
pub receiver: u64, pub receiver: u64,
pub sender: u64, pub sender: u64,
pub body: Body<'a>, pub body: Body<'a>,
} }
impl<'a> Payload<'a> { impl<'a> Payload<'a> {
pub(super) fn new(body: Body<'a>) -> Self { pub(super) fn new(body: Body<'a>) -> Self { Self { receiver: 0, sender: *ID, body } }
Self { receiver: 0, sender: *ID, body }
}
pub(super) fn flush(&self) { pub(super) fn flush(&self) { writeln!(std::io::stdout(), "{self}").ok(); }
writeln!(std::io::stdout(), "{self}").ok();
}
pub(super) fn try_flush(&self) { pub(super) fn try_flush(&self) {
let b = if self.receiver == 0 { let b = if self.receiver == 0 {
@ -75,9 +71,7 @@ impl FromStr for Payload<'_> {
} }
impl<'a> From<Body<'a>> for Payload<'a> { impl<'a> From<Body<'a>> for Payload<'a> {
fn from(value: Body<'a>) -> Self { fn from(value: Body<'a>) -> Self { Self::new(value) }
Self::new(value)
}
} }
impl Display for Payload<'_> { impl Display for Payload<'_> {

View file

@ -5,10 +5,7 @@ use parking_lot::RwLock;
use yazi_boot::BOOT; use yazi_boot::BOOT;
use yazi_shared::{fs::Url, RoCell}; use yazi_shared::{fs::Url, RoCell};
use crate::{ use crate::{body::{Body, BodyCd, BodyHi, BodyHover, BodyMove, BodyRename, BodyYank}, Client, ID, PEERS};
body::{Body, BodyCd, BodyHi, BodyHover, BodyMove, BodyRename, BodyYank},
Client, ID, PEERS,
};
pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> = pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> =
RoCell::new(); RoCell::new();
@ -62,17 +59,13 @@ impl Pubsub {
sub!(REMOTE)(plugin, kind, f) && Self::pub_from_hi() sub!(REMOTE)(plugin, kind, f) && Self::pub_from_hi()
} }
pub fn unsub(plugin: &str, kind: &str) -> bool { pub fn unsub(plugin: &str, kind: &str) -> bool { unsub!(LOCAL)(plugin, kind) }
unsub!(LOCAL)(plugin, kind)
}
pub fn unsub_remote(plugin: &str, kind: &str) -> bool { pub fn unsub_remote(plugin: &str, kind: &str) -> bool {
unsub!(REMOTE)(plugin, kind) && Self::pub_from_hi() unsub!(REMOTE)(plugin, kind) && Self::pub_from_hi()
} }
pub fn pub_(body: Body<'static>) { pub fn pub_(body: Body<'static>) { body.with_receiver(*ID).emit(); }
body.with_receiver(*ID).emit();
}
pub fn pub_to(receiver: u64, body: Body<'static>) { pub fn pub_to(receiver: u64, body: Body<'static>) {
if receiver == *ID { if receiver == *ID {