diff --git a/Cargo.toml b/Cargo.toml index 46f23df..e0f6dfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,11 @@ tuirs-termion = ["tuirs", "dep:termion", "tui/termion"] tuirs-no-backend = ["tuirs"] # Other optional features search = ["dep:regex"] -clipboard = ["dep:copypasta"] +clipboard = ["dep:arboard"] [dependencies] arbitrary = { version = "1", features = ["derive"], optional = true } -copypasta = { version = "0.10.0", optional = true } +arboard = { version = "3.2.1", default-features = false, features = ["wayland-data-control"], optional = true } crossterm = { package = "crossterm", version = "0.27", optional = true } crossterm-025 = { package = "crossterm", version = "0.25", optional = true } ratatui = { version = ">=0.23.0, <1", default-features = false, optional = true } diff --git a/src/clipboard.rs b/src/clipboard.rs index 5a19980..135eea9 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -1,5 +1,5 @@ #[cfg(feature = "clipboard")] -use copypasta::{ClipboardContext, ClipboardProvider as _}; +use arboard::Clipboard as Arboard; use std::borrow::Cow; #[cfg(feature = "clipboard")] use std::cell::RefCell; @@ -23,13 +23,13 @@ pub enum Clipboard { Piece(String), Chunk(Vec), #[cfg(feature = "clipboard")] - Os(RefCell), // Use `RefCell` not to make `Clipboard::contents` mut method + Os(RefCell), // Use `RefCell` not to make `Clipboard::contents` mut method } impl Default for Clipboard { fn default() -> Self { #[cfg(feature = "clipboard")] - if let Ok(ctx) = ClipboardContext::new() { + if let Ok(ctx) = Arboard::new() { return Self::Os(RefCell::new(ctx)); } Self::Piece(String::new()) @@ -50,7 +50,7 @@ impl Clipboard { #[cfg(feature = "clipboard")] if let Self::Os(ctx) = self { if let Ok(mut ctx) = ctx.try_borrow_mut() { - let _ = ctx.set_contents(s); + let _ = ctx.set_text(s); return; } } @@ -66,7 +66,7 @@ impl Clipboard { #[cfg(feature = "clipboard")] if let Self::Os(ctx) = self { if let Ok(mut ctx) = ctx.try_borrow_mut() { - let _ = ctx.set_contents(c.join("\n")); + let _ = ctx.set_text(c.join("\n")); return; } } @@ -82,7 +82,7 @@ impl Clipboard { #[cfg(feature = "clipboard")] Self::Os(ctx) => { if let Ok(mut ctx) = ctx.try_borrow_mut() { - if let Ok(contents) = ctx.get_contents() { + if let Ok(contents) = ctx.get_text() { let mut lines = contents .split('\n') .map(|s| s.strip_suffix('\r').unwrap_or(s).to_string()) @@ -119,7 +119,7 @@ impl Clone for Clipboard { Self::Chunk(c) => Self::Chunk(c.clone()), #[cfg(feature = "clipboard")] Self::Os(_) => { - if let Ok(ctx) = ClipboardContext::new() { + if let Ok(ctx) = Arboard::new() { Self::Os(RefCell::new(ctx)) } else { Self::Piece(String::new()) @@ -157,10 +157,8 @@ mod tests { #[test] fn default_value() { let _guard = guard(); - ClipboardContext::new() - .unwrap() - .set_contents("Hello, world".into()) - .unwrap(); + let mut arboard = Arboard::new().unwrap(); + arboard.set_text("Hello, world").unwrap(); let c = Clipboard::default(); assert_eq!(String::from(c.contents()), "Hello, world"); }