mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: api cleanup
This commit is contained in:
parent
184065085c
commit
4943694f68
21 changed files with 75 additions and 129 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -4744,6 +4744,7 @@ dependencies = [
|
||||||
"inventory",
|
"inventory",
|
||||||
"libc",
|
"libc",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
"parking_lot",
|
||||||
"paste",
|
"paste",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"ratatui-core",
|
"ratatui-core",
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ hashbrown = { workspace = true }
|
||||||
indexmap = { workspace = true }
|
indexmap = { workspace = true }
|
||||||
inventory = { workspace = true }
|
inventory = { workspace = true }
|
||||||
mlua = { workspace = true }
|
mlua = { workspace = true }
|
||||||
|
parking_lot = { workspace = true }
|
||||||
paste = { workspace = true }
|
paste = { workspace = true }
|
||||||
ratatui-core = { workspace = true }
|
ratatui-core = { workspace = true }
|
||||||
scopeguard = { workspace = true }
|
scopeguard = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,7 @@ impl Actor for Clipboard {
|
||||||
runtime_scope!(LUA, "root", {
|
runtime_scope!(LUA, "root", {
|
||||||
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;
|
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;
|
||||||
|
|
||||||
if form.event.is_paste_offer() {
|
root.call_method::<()>("clipboard", form.event)?;
|
||||||
root.call_method::<()>("paste_offer", form.event)?;
|
|
||||||
} else if form.event.is_read() {
|
|
||||||
root.call_method::<()>("paste_data", form.event)?;
|
|
||||||
} else {
|
|
||||||
root.call_method::<()>("write_result", form.event)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
yazi_macro::mod_flat!(
|
yazi_macro::mod_flat!(
|
||||||
accept_payload
|
accept_payload
|
||||||
bootstrap
|
bootstrap
|
||||||
|
clipboard
|
||||||
deprecate
|
deprecate
|
||||||
dnd
|
dnd
|
||||||
focus
|
focus
|
||||||
|
|
@ -16,5 +17,4 @@ yazi_macro::mod_flat!(
|
||||||
theme
|
theme
|
||||||
title
|
title
|
||||||
update_progress
|
update_progress
|
||||||
clipboard
|
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -70,16 +70,9 @@ impl Actor for Copy {
|
||||||
"uri_list" => {
|
"uri_list" => {
|
||||||
data.push(ClipboardData {
|
data.push(ClipboardData {
|
||||||
mime: b"text/uri-list".to_vec(),
|
mime: b"text/uri-list".to_vec(),
|
||||||
payload: s.clone(),
|
payload: s,
|
||||||
alias: b"text/plain".to_vec(),
|
alias: b"text/plain".to_vec(),
|
||||||
});
|
});
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
// Because Thunar (and likely others) won't reconize `text/uri-list`
|
|
||||||
data.push(ClipboardData {
|
|
||||||
mime: b"x-special/gnome-copied-files".to_vec(),
|
|
||||||
payload: [b"copy\n".to_vec(), s].concat(),
|
|
||||||
alias: vec![],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
data.push(ClipboardData { mime: b"text/plain".to_vec(), payload: s, alias: vec![] });
|
data.push(ClipboardData { mime: b"text/plain".to_vec(), payload: s, alias: vec![] });
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl Actor for Paste {
|
||||||
mgr.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(mgr.yanked.urls()));
|
mgr.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(mgr.yanked.urls()));
|
||||||
act!(mgr:unyank, cx)
|
act!(mgr:unyank, cx)
|
||||||
} else {
|
} else {
|
||||||
succ!(cx.core.tasks.file_copy(&mgr.yanked, dest, form.force, Some(form.follow)));
|
succ!(cx.core.tasks.file_copy(&mgr.yanked, dest, form.force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
yazi-cli/src/env/env.rs
vendored
1
yazi-cli/src/env/env.rs
vendored
|
|
@ -112,7 +112,6 @@ impl Env {
|
||||||
writeln!(s, " wl-copy/paste: {} / {}", Self::dep_version("wl-copy", "--version"), Self::dep_version("wl-paste", "--version"))?;
|
writeln!(s, " wl-copy/paste: {} / {}", Self::dep_version("wl-copy", "--version"), Self::dep_version("wl-paste", "--version"))?;
|
||||||
writeln!(s, " xclip : {}", Self::dep_version("xclip", "-version"))?;
|
writeln!(s, " xclip : {}", Self::dep_version("xclip", "-version"))?;
|
||||||
writeln!(s, " xsel : {}", Self::dep_version("xsel", "--version"))?;
|
writeln!(s, " xsel : {}", Self::dep_version("xsel", "--version"))?;
|
||||||
writeln!(s, " OSC 5522 : {:?}", yazi_emulator::EMULATOR.osc_5522)?;
|
|
||||||
|
|
||||||
writeln!(s, "\nRoutine")?;
|
writeln!(s, "\nRoutine")?;
|
||||||
writeln!(s, " `file -bL --mime-type`: {}", Self::file1_output())?;
|
writeln!(s, " `file -bL --mime-type`: {}", Self::file1_output())?;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_copy(&self, src: &Yanked, dest: &UrlBuf, force: bool, follow: Option<bool>) {
|
pub fn file_copy(&self, src: &Yanked, dest: &UrlBuf, force: bool) {
|
||||||
self.scheduler.behavior.reset();
|
self.scheduler.behavior.reset();
|
||||||
|
|
||||||
for u in src.urls() {
|
for u in src.urls() {
|
||||||
|
|
@ -33,7 +33,7 @@ impl Tasks {
|
||||||
if force && u == to {
|
if force && u == to {
|
||||||
debug!("file_copy: same file, skip {to:?}");
|
debug!("file_copy: same file, skip {to:?}");
|
||||||
} else {
|
} else {
|
||||||
self.scheduler.file_copy(FileInCopy::new(u.clone(), to, force, follow));
|
self.scheduler.file_copy(FileInCopy::new(u.clone(), to, force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,16 +69,13 @@ impl Emulator {
|
||||||
|
|
||||||
let csi_16t = Self::csi_16t(&resp).unwrap_or_default();
|
let csi_16t = Self::csi_16t(&resp).unwrap_or_default();
|
||||||
|
|
||||||
let osc_5522 =
|
|
||||||
["\x1b[?5522;1$y", "\x1b[?5522;2$y", "\x1b[?5522;3$y"].iter().any(|s| resp.contains(s));
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
kind,
|
kind,
|
||||||
version: Self::csi_gt_q(&resp).unwrap_or_default(),
|
version: Self::csi_gt_q(&resp).unwrap_or_default(),
|
||||||
light: Self::light_bg(&resp).unwrap_or_default(),
|
light: Self::light_bg(&resp).unwrap_or_default(),
|
||||||
csi_16t,
|
csi_16t,
|
||||||
force_16t: Self::force_16t(csi_16t),
|
force_16t: Self::force_16t(csi_16t),
|
||||||
osc_5522,
|
osc_5522: Self::osc_5522(&resp),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +191,10 @@ impl Emulator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn osc_5522(resp: &str) -> bool {
|
||||||
|
["\x1b[?5522;1$y", "\x1b[?5522;2$y", "\x1b[?5522;3$y"].iter().any(|s| resp.contains(s))
|
||||||
|
}
|
||||||
|
|
||||||
fn force_16t((w, h): (u16, u16)) -> bool {
|
fn force_16t((w, h): (u16, u16)) -> bool {
|
||||||
if w == 0 || h == 0 {
|
if w == 0 || h == 0 {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -104,14 +104,13 @@ impl<'a> Dispatcher<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_clipboard(&mut self, clip: ClipboardEvent) -> Result<()> {
|
fn dispatch_clipboard(&mut self, clip: ClipboardEvent) -> Result<()> {
|
||||||
if self.app.core.input.main.visible && clip.is_read() {
|
if self.app.core.input.main.visible {
|
||||||
if let Some(text) = clip.text() {
|
if let Some(text) = clip.text() {
|
||||||
self.dispatch_paste(text)?;
|
self.dispatch_paste(text)?;
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
let cx = &mut Ctx::active(&mut self.app.core, &mut self.app.term);
|
|
||||||
act!(app:clipboard, cx, clip).map(|_| ())
|
|
||||||
}
|
}
|
||||||
|
let cx = &mut Ctx::active(&mut self.app.core, &mut self.app.term);
|
||||||
|
act!(app:clipboard, cx, clip).map(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
yazi_macro::mod_flat!(deprecate dnd lua mouse plugin quit reflow title update_progress clipboard);
|
yazi_macro::mod_flat!(clipboard deprecate dnd lua mouse plugin quit reflow title update_progress);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub enum Spark<'a> {
|
||||||
// App
|
// App
|
||||||
AppAcceptPayload(yazi_dds::Payload<'a>),
|
AppAcceptPayload(yazi_dds::Payload<'a>),
|
||||||
AppBootstrap(crate::VoidForm),
|
AppBootstrap(crate::VoidForm),
|
||||||
|
AppClipboard(crate::app::ClipboardForm),
|
||||||
AppDeprecate(crate::app::DeprecateForm),
|
AppDeprecate(crate::app::DeprecateForm),
|
||||||
AppDnd(crate::app::DndForm),
|
AppDnd(crate::app::DndForm),
|
||||||
AppFocus(crate::VoidForm),
|
AppFocus(crate::VoidForm),
|
||||||
|
|
@ -25,7 +26,6 @@ pub enum Spark<'a> {
|
||||||
AppTheme(crate::VoidForm),
|
AppTheme(crate::VoidForm),
|
||||||
AppTitle(crate::app::TitleForm),
|
AppTitle(crate::app::TitleForm),
|
||||||
AppUpdateProgress(crate::app::UpdateProgressForm),
|
AppUpdateProgress(crate::app::UpdateProgressForm),
|
||||||
AppClipboard(crate::app::ClipboardForm),
|
|
||||||
|
|
||||||
// Mgr
|
// Mgr
|
||||||
Arrow(crate::ArrowForm),
|
Arrow(crate::ArrowForm),
|
||||||
|
|
@ -206,6 +206,7 @@ impl<'a> IntoLua for Spark<'a> {
|
||||||
// App
|
// App
|
||||||
Self::AppAcceptPayload(b) => b.into_lua(lua),
|
Self::AppAcceptPayload(b) => b.into_lua(lua),
|
||||||
Self::AppBootstrap(b) => b.into_lua(lua),
|
Self::AppBootstrap(b) => b.into_lua(lua),
|
||||||
|
Self::AppClipboard(b) => b.into_lua(lua),
|
||||||
Self::AppDeprecate(b) => b.into_lua(lua),
|
Self::AppDeprecate(b) => b.into_lua(lua),
|
||||||
Self::AppDnd(b) => b.into_lua(lua),
|
Self::AppDnd(b) => b.into_lua(lua),
|
||||||
Self::AppFocus(b) => b.into_lua(lua),
|
Self::AppFocus(b) => b.into_lua(lua),
|
||||||
|
|
@ -221,7 +222,6 @@ impl<'a> IntoLua for Spark<'a> {
|
||||||
Self::AppTheme(b) => b.into_lua(lua),
|
Self::AppTheme(b) => b.into_lua(lua),
|
||||||
Self::AppTitle(b) => b.into_lua(lua),
|
Self::AppTitle(b) => b.into_lua(lua),
|
||||||
Self::AppUpdateProgress(b) => b.into_lua(lua),
|
Self::AppUpdateProgress(b) => b.into_lua(lua),
|
||||||
Self::AppClipboard(b) => b.into_lua(lua),
|
|
||||||
|
|
||||||
// Mgr
|
// Mgr
|
||||||
Self::Arrow(b) => b.into_lua(lua),
|
Self::Arrow(b) => b.into_lua(lua),
|
||||||
|
|
@ -388,6 +388,7 @@ try_from_spark!(
|
||||||
|
|
||||||
// App
|
// App
|
||||||
try_from_spark!(crate::ArrowForm, mgr:arrow, mgr:tab_swap);
|
try_from_spark!(crate::ArrowForm, mgr:arrow, mgr:tab_swap);
|
||||||
|
try_from_spark!(crate::app::ClipboardForm, app:clipboard);
|
||||||
try_from_spark!(crate::app::DeprecateForm, app:deprecate);
|
try_from_spark!(crate::app::DeprecateForm, app:deprecate);
|
||||||
try_from_spark!(crate::app::DndForm, app:dnd);
|
try_from_spark!(crate::app::DndForm, app:dnd);
|
||||||
try_from_spark!(crate::app::LuaForm, app:lua);
|
try_from_spark!(crate::app::LuaForm, app:lua);
|
||||||
|
|
@ -397,7 +398,6 @@ try_from_spark!(crate::app::QuitForm, app:quit, mgr:quit);
|
||||||
try_from_spark!(crate::app::ReflowForm, app:reflow, app:resize, app:resume);
|
try_from_spark!(crate::app::ReflowForm, app:reflow, app:resize, app:resume);
|
||||||
try_from_spark!(crate::app::TitleForm, app:title);
|
try_from_spark!(crate::app::TitleForm, app:title);
|
||||||
try_from_spark!(crate::app::UpdateProgressForm, app:update_progress);
|
try_from_spark!(crate::app::UpdateProgressForm, app:update_progress);
|
||||||
try_from_spark!(crate::app::ClipboardForm, app:clipboard);
|
|
||||||
try_from_spark!(crate::cmp::CloseForm, cmp:close);
|
try_from_spark!(crate::cmp::CloseForm, cmp:close);
|
||||||
try_from_spark!(crate::cmp::ShowForm, cmp:show);
|
try_from_spark!(crate::cmp::ShowForm, cmp:show);
|
||||||
try_from_spark!(crate::cmp::TriggerForm, cmp:trigger);
|
try_from_spark!(crate::cmp::TriggerForm, cmp:trigger);
|
||||||
|
|
|
||||||
|
|
@ -100,30 +100,15 @@ function Root:drop(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clipboard events
|
function Root:clipboard(event)
|
||||||
function Root:paste_offer(event)
|
if event and event.type == "mimetypes" and event.pw then
|
||||||
if event and event.pw then
|
|
||||||
-- No harm in asking for unavailable types
|
-- No harm in asking for unavailable types
|
||||||
local mimetypes = "text/plain text/uri-list"
|
local mimetypes = "text/plain text/uri-list"
|
||||||
ya.dbg("Requesting ReadClipboard")
|
|
||||||
rt.tty:queue("ReadClipboard", { mimes = mimetypes, pw = event.pw, name = "Paste Event", primary = event.primary })
|
rt.tty:queue("ReadClipboard", { mimes = mimetypes, pw = event.pw, name = "Paste Event", primary = event.primary })
|
||||||
rt.tty:flush()
|
rt.tty:flush()
|
||||||
|
elseif event and event.type == "data" then
|
||||||
|
if event.data["text/uri-list"] ~= nil then
|
||||||
|
require("clipboard").copy_uri_list(event.data["text/uri-list"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Root:paste_data(event)
|
|
||||||
if event.data["text/uri-list"] ~= nil then
|
|
||||||
local list = event.data["text/uri-list"]
|
|
||||||
ya.dbg("Pasting URI list:", list)
|
|
||||||
require("clipboard").copy_uri_list(list)
|
|
||||||
end
|
|
||||||
-- TODO !!5522!! Suport non text formats
|
|
||||||
-- if event.data["image/png"] ~= nil then
|
|
||||||
-- local type = "image/png"
|
|
||||||
-- local data = event.data["image/png"]
|
|
||||||
-- ya.dbg("Pasting image/png:")
|
|
||||||
-- require("clipboard").paste_image(type, data)
|
|
||||||
-- end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Root:write_result(event) end
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ pub(super) fn term() -> Composer<ComposerGet, ComposerSet> {
|
||||||
match key {
|
match key {
|
||||||
b"light" => EMULATOR.light.into_lua(lua),
|
b"light" => EMULATOR.light.into_lua(lua),
|
||||||
b"cell_size" => cell_size(lua)?.into_lua(lua),
|
b"cell_size" => cell_size(lua)?.into_lua(lua),
|
||||||
b"osc5522_clipboard" => EMULATOR.osc_5522.into_lua(lua),
|
|
||||||
_ => Ok(Value::Nil),
|
_ => Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,9 +157,9 @@ impl TaskIn for FileInCopy {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileInCopy {
|
impl FileInCopy {
|
||||||
pub fn new(from: UrlBuf, to: UrlBuf, force: bool, follow: Option<bool>) -> Self {
|
pub fn new(from: UrlBuf, to: UrlBuf, force: bool) -> Self {
|
||||||
Self {
|
Self {
|
||||||
follow: follow.unwrap_or(!from.auth().covariant(to.auth())),
|
follow: !from.auth().covariant(to.auth()),
|
||||||
id: Id::ZERO,
|
id: Id::ZERO,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
|
@ -189,7 +189,7 @@ impl FromLua for FileInCopy {
|
||||||
return Err("constructing FileInCopy from non-table value".into_lua_err());
|
return Err("constructing FileInCopy from non-table value".into_lua_err());
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self::new(t.raw_get("from")?, t.raw_get("to")?, t.raw_get("force")?, None))
|
Ok(Self::new(t.raw_get("from")?, t.raw_get("to")?, t.raw_get("force")?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// --- Cut
|
// --- Cut
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
use std::str::SplitWhitespace;
|
|
||||||
|
|
||||||
use strum::{FromRepr, IntoStaticStr};
|
use strum::{FromRepr, IntoStaticStr};
|
||||||
|
|
||||||
use crate::parser::{Osc5522Status, StateOsc5522};
|
use crate::{event::mime::MimeList, parser::{Osc5522Status, StateOsc5522}};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum ClipboardEvent {
|
pub enum ClipboardEvent {
|
||||||
|
|
@ -15,7 +13,7 @@ pub enum ClipboardEvent {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct ClipboardPaste {
|
pub struct ClipboardPaste {
|
||||||
pub mimes: ClipboardMimeList,
|
pub mimes: MimeList,
|
||||||
pub primary: bool,
|
pub primary: bool,
|
||||||
pub pw: Vec<u8>,
|
pub pw: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +26,7 @@ pub struct ClipboardData {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct ClipboardRead {
|
pub struct ClipboardRead {
|
||||||
pub mimes: ClipboardMimeList,
|
pub mimes: MimeList,
|
||||||
pub primary: bool,
|
pub primary: bool,
|
||||||
pub data: Vec<ClipboardData>,
|
pub data: Vec<ClipboardData>,
|
||||||
}
|
}
|
||||||
|
|
@ -41,15 +39,15 @@ pub struct ClipboardError {
|
||||||
impl ClipboardEvent {
|
impl ClipboardEvent {
|
||||||
pub fn r#type(&self) -> &'static str {
|
pub fn r#type(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::ReadMimetypes(_) => "read_mimetypes",
|
Self::ReadMimetypes(_) => "mimetypes",
|
||||||
Self::ReadData(_) => "read_data",
|
Self::ReadData(_) => "data",
|
||||||
Self::ReadError(_) => "read_error",
|
Self::ReadError(_) => "error",
|
||||||
Self::WriteSuccess => "write_success",
|
Self::WriteSuccess => "success",
|
||||||
Self::WriteError(_) => "write_error",
|
Self::WriteError(_) => "error",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mimes(&self) -> Option<&ClipboardMimeList> {
|
pub fn mimes(&self) -> Option<&MimeList> {
|
||||||
match self {
|
match self {
|
||||||
Self::ReadMimetypes(e) => Some(&e.mimes),
|
Self::ReadMimetypes(e) => Some(&e.mimes),
|
||||||
Self::ReadData(e) => Some(&e.mimes),
|
Self::ReadData(e) => Some(&e.mimes),
|
||||||
|
|
@ -80,16 +78,9 @@ impl ClipboardEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_paste_offer(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
Self::ReadMimetypes(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_read(&self) -> bool {
|
pub fn is_read(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::ReadError(_) | Self::ReadData(_) => true,
|
Self::ReadMimetypes(_) | Self::ReadError(_) | Self::ReadData(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +91,7 @@ impl ClipboardEvent {
|
||||||
if mime.first()? == b"." =>
|
if mime.first()? == b"." =>
|
||||||
{
|
{
|
||||||
ClipboardEvent::ReadMimetypes(ClipboardPaste {
|
ClipboardEvent::ReadMimetypes(ClipboardPaste {
|
||||||
mimes: ClipboardMimeList::new(s.payload.first()?.to_owned())?,
|
mimes: MimeList::new(s.payload.first()?.to_owned())?,
|
||||||
primary: s.primary,
|
primary: s.primary,
|
||||||
pw: s.pw,
|
pw: s.pw,
|
||||||
})
|
})
|
||||||
|
|
@ -114,7 +105,7 @@ impl ClipboardEvent {
|
||||||
mimes.push(b' ');
|
mimes.push(b' ');
|
||||||
}
|
}
|
||||||
ClipboardEvent::ReadData(ClipboardRead {
|
ClipboardEvent::ReadData(ClipboardRead {
|
||||||
mimes: ClipboardMimeList::new(mimes)?,
|
mimes: MimeList::new(mimes)?,
|
||||||
primary: s.primary,
|
primary: s.primary,
|
||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
|
|
@ -140,16 +131,6 @@ pub enum ClipboardType {
|
||||||
Write = 2,
|
Write = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- MIME list
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct ClipboardMimeList(String);
|
|
||||||
|
|
||||||
impl ClipboardMimeList {
|
|
||||||
pub fn new(b: Vec<u8>) -> Option<Self> { Some(Self(String::from_utf8(b).ok()?)) }
|
|
||||||
|
|
||||||
pub fn iter(&self) -> SplitWhitespace<'_> { self.0.split_whitespace() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Error payload parsing
|
// --- Error payload parsing
|
||||||
fn parse_error(status: Option<Osc5522Status>) -> Option<String> {
|
fn parse_error(status: Option<Osc5522Status>) -> Option<String> {
|
||||||
match status {
|
match status {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
use std::str::SplitWhitespace;
|
|
||||||
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use strum::{FromRepr, IntoStaticStr};
|
use strum::{FromRepr, IntoStaticStr};
|
||||||
use yazi_shim::BASE64_SANE;
|
use yazi_shim::BASE64_SANE;
|
||||||
|
|
||||||
use crate::parser::StateOsc72;
|
use crate::{event::mime::MimeList, parser::StateOsc72};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum DndEvent {
|
pub enum DndEvent {
|
||||||
|
|
@ -63,7 +61,7 @@ pub struct DndDropEnter {
|
||||||
pub x: u32,
|
pub x: u32,
|
||||||
pub y: u32,
|
pub y: u32,
|
||||||
pub op: DndOp,
|
pub op: DndOp,
|
||||||
pub mimes: DndMimeList,
|
pub mimes: MimeList,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
@ -71,7 +69,7 @@ pub struct DndDropReady {
|
||||||
pub x: u32,
|
pub x: u32,
|
||||||
pub y: u32,
|
pub y: u32,
|
||||||
pub op: DndOp,
|
pub op: DndOp,
|
||||||
pub mimes: DndMimeList,
|
pub mimes: MimeList,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
@ -144,7 +142,7 @@ impl DndEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mimes(&self) -> Option<&DndMimeList> {
|
pub fn mimes(&self) -> Option<&MimeList> {
|
||||||
match self {
|
match self {
|
||||||
Self::DropEnter(e) => Some(&e.mimes),
|
Self::DropEnter(e) => Some(&e.mimes),
|
||||||
Self::DropReady(e) => Some(&e.mimes),
|
Self::DropReady(e) => Some(&e.mimes),
|
||||||
|
|
@ -185,13 +183,13 @@ impl DndEvent {
|
||||||
x: s.x?.try_into().ok()?,
|
x: s.x?.try_into().ok()?,
|
||||||
y: s.y?.try_into().ok()?,
|
y: s.y?.try_into().ok()?,
|
||||||
op: DndOp::from_repr(s.op?)?,
|
op: DndOp::from_repr(s.op?)?,
|
||||||
mimes: DndMimeList::new(s.payload)?,
|
mimes: MimeList::new(s.payload)?,
|
||||||
}),
|
}),
|
||||||
b'M' => Self::DropReady(DndDropReady {
|
b'M' => Self::DropReady(DndDropReady {
|
||||||
x: s.x?.try_into().ok()?,
|
x: s.x?.try_into().ok()?,
|
||||||
y: s.y?.try_into().ok()?,
|
y: s.y?.try_into().ok()?,
|
||||||
op: DndOp::from_repr(s.op?)?,
|
op: DndOp::from_repr(s.op?)?,
|
||||||
mimes: DndMimeList::new(s.payload)?,
|
mimes: MimeList::new(s.payload)?,
|
||||||
}),
|
}),
|
||||||
b'r' => Self::DropArrive(DndDropArrive {
|
b'r' => Self::DropArrive(DndDropArrive {
|
||||||
idx: s.x?.try_into().ok()?,
|
idx: s.x?.try_into().ok()?,
|
||||||
|
|
@ -217,14 +215,6 @@ pub enum DndOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- MIME list
|
// --- MIME list
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct DndMimeList(String);
|
|
||||||
|
|
||||||
impl DndMimeList {
|
|
||||||
pub fn new(b: Vec<u8>) -> Option<Self> { Some(Self(String::from_utf8(b).ok()?)) }
|
|
||||||
|
|
||||||
pub fn iter(&self) -> SplitWhitespace<'_> { self.0.split_whitespace() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Error payload parsing
|
// --- Error payload parsing
|
||||||
fn parse_error(payload: Vec<u8>) -> Option<(String, String)> {
|
fn parse_error(payload: Vec<u8>) -> Option<(String, String)> {
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,12 @@ impl UserData for ClipboardEvent {
|
||||||
|
|
||||||
fields.add_cached_field_mut("data", |lua, me| match me {
|
fields.add_cached_field_mut("data", |lua, me| match me {
|
||||||
Self::ReadData(ClipboardRead { data, .. }) => lua
|
Self::ReadData(ClipboardRead { data, .. }) => lua
|
||||||
.create_table_from(data.iter().map(|d| {
|
.create_table_from(
|
||||||
(
|
data
|
||||||
lua.create_string(&d.mime).ok(),
|
.iter()
|
||||||
// TODO !!5522!! is this the best way
|
.map(|d| Ok((lua.create_string(&d.mime)?, lua.create_external_string(&*d.data)?)))
|
||||||
lua.create_external_string(&*d.data).ok(),
|
.collect::<Result<Vec<_>, mlua::Error>>()?,
|
||||||
)
|
)?
|
||||||
}))?
|
|
||||||
.into_lua(lua),
|
.into_lua(lua),
|
||||||
_ => Ok(Value::Nil),
|
_ => Ok(Value::Nil),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
10
yazi-term/src/event/mime.rs
Normal file
10
yazi-term/src/event/mime.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
use std::str::SplitWhitespace;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct MimeList(String);
|
||||||
|
|
||||||
|
impl MimeList {
|
||||||
|
pub fn new(b: Vec<u8>) -> Option<Self> { Some(Self(String::from_utf8(b).ok()?)) }
|
||||||
|
|
||||||
|
pub fn iter(&self) -> SplitWhitespace<'_> { self.0.split_whitespace() }
|
||||||
|
}
|
||||||
|
|
@ -1 +1 @@
|
||||||
yazi_macro::mod_flat!(clipboard dnd event keyboard lua modifiers mouse);
|
yazi_macro::mod_flat!(clipboard dnd event keyboard lua mime modifiers mouse);
|
||||||
|
|
|
||||||
|
|
@ -52,20 +52,17 @@ pub struct ReadClipboard<'a> {
|
||||||
|
|
||||||
impl Display for ReadClipboard<'_> {
|
impl Display for ReadClipboard<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let b64_mime = BASE64_PAD.encode(self.mime).into_bytes();
|
let b64_mime = BASE64_PAD.encode(self.mime);
|
||||||
let mime_str = unsafe { String::from_utf8_unchecked(b64_mime) };
|
|
||||||
let mut metadata = String::new();
|
let mut metadata = String::new();
|
||||||
if self.pw.len() > 0 {
|
if self.pw.len() > 0 {
|
||||||
let b64_pw = BASE64_PAD.encode(self.pw).into_bytes();
|
let b64_pw = BASE64_PAD.encode(self.pw);
|
||||||
let pw_str = unsafe { String::from_utf8_unchecked(b64_pw) };
|
let b64_name = BASE64_PAD.encode(self.name);
|
||||||
let b64_name = BASE64_PAD.encode(self.name).into_bytes();
|
metadata.push_str(&format!(":pw={}:name={}", b64_pw, b64_name));
|
||||||
let name_str = unsafe { String::from_utf8_unchecked(b64_name) };
|
|
||||||
metadata.push_str(&format!(":pw={}:name={}", pw_str, name_str));
|
|
||||||
}
|
}
|
||||||
if self.primary {
|
if self.primary {
|
||||||
metadata.push_str(":loc=primary");
|
metadata.push_str(":loc=primary");
|
||||||
}
|
}
|
||||||
write!(f, "\x1b]5522;type=read{};{}\x1b\\", metadata, mime_str)
|
write!(f, "\x1b]5522;type=read{};{}\x1b\\", metadata, b64_mime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,20 +88,17 @@ impl Display for WriteClipboard<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "\x1b]5522;type=write\x1b\\")?;
|
write!(f, "\x1b]5522;type=write\x1b\\")?;
|
||||||
for item in &self.data {
|
for item in &self.data {
|
||||||
let b64_mime = BASE64_PAD.encode(item.mime).into_bytes();
|
let b64_mime = BASE64_PAD.encode(item.mime);
|
||||||
let mime_str = unsafe { String::from_utf8_unchecked(b64_mime) };
|
|
||||||
let data = item.payload;
|
let data = item.payload;
|
||||||
|
|
||||||
for (_, chunk) in data.chunks(4096).enumerate() {
|
for (_, chunk) in data.chunks(4096).enumerate() {
|
||||||
let b64_chunk = BASE64_PAD.encode(chunk).into_bytes();
|
let b64_chunk = BASE64_PAD.encode(chunk);
|
||||||
let s = unsafe { String::from_utf8_unchecked(b64_chunk) };
|
write!(f, "\x1b]5522;type=wdata:mime={};{}\x1b\\", b64_mime, b64_chunk)?;
|
||||||
write!(f, "\x1b]5522;type=wdata:mime={};{s}\x1b\\", mime_str)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.alias.len() > 0 {
|
if item.alias.len() > 0 {
|
||||||
let b64_alias = BASE64_PAD.encode(item.alias).into_bytes();
|
let b64_alias = BASE64_PAD.encode(item.alias);
|
||||||
let s = unsafe { String::from_utf8_unchecked(b64_alias) };
|
write!(f, "\x1b]5522;type=walias:mime={};{}\x1b\\", b64_mime, b64_alias)?;
|
||||||
write!(f, "\x1b]5522;type=walias:mime={};{s}\x1b\\", mime_str)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write!(f, "\x1b]5522;type=wdata\x1b\\")
|
write!(f, "\x1b]5522;type=wdata\x1b\\")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue