diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-04-28 20:21:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-28 20:21:39 +0000 |
commit | 9e89aaa477369b20a06f4b9f636d7fd543c4c985 (patch) | |
tree | 81deb1b250541a3c8fe7b6f9274f5a87f265a314 /copypasta/src/lib.rs | |
parent | 37b66a7cd2e53fae93e3c2c8bc3ddbd9cbe140d2 (diff) | |
download | r-alacritty-9e89aaa477369b20a06f4b9f636d7fd543c4c985.tar.gz r-alacritty-9e89aaa477369b20a06f4b9f636d7fd543c4c985.tar.bz2 r-alacritty-9e89aaa477369b20a06f4b9f636d7fd543c4c985.zip |
Switch from copypasta to rust-clipboard
This switches our own `copypasta` crate with the more standardized
`clipboard` library, which allows us to get rid of the `xclip`
dependency on X11.
Additionally, this lays the foundation for native Wayland clipboard
support once the clipboard crate is updated (or a fork is created).
Fixes #5.
Diffstat (limited to 'copypasta/src/lib.rs')
-rw-r--r-- | copypasta/src/lib.rs | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/copypasta/src/lib.rs b/copypasta/src/lib.rs deleted file mode 100644 index d591a04f..00000000 --- a/copypasta/src/lib.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! A cross-platform clipboard library - -#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use, clippy::wrong_pub_self_convention)] - -// This has to be here due to macro_use -#[cfg(target_os = "macos")] -#[macro_use] -extern crate objc; - -#[cfg(windows)] -extern crate clipboard; - -/// An enumeration describing available clipboard buffers -pub enum Buffer { - Primary, - Selection, -} - -/// Types that can get the system clipboard contents -pub trait Load: Sized { - /// Errors encountered when working with a clipboard. Each implementation is - /// allowed to define its own error type, but it must conform to std error. - type Err: ::std::error::Error + Send + Sync + 'static; - - /// Create a clipboard - fn new() -> Result<Self, Self::Err>; - - /// Get the primary clipboard contents. - fn load_primary(&self) -> Result<String, Self::Err>; - - /// Get the clipboard selection contents. - /// - /// On most platforms, this doesn't mean anything. A default implementation - /// is provided which uses the primary clipboard. - #[inline] - fn load_selection(&self) -> Result<String, Self::Err> { - self.load_primary() - } - - fn load(&self, buffer: Buffer) -> Result<String, Self::Err> { - match buffer { - Buffer::Selection => self.load_selection(), - Buffer::Primary => self.load_primary(), - } - } -} - -/// Types that can set the system clipboard contents -/// -/// Note that some platforms require the clipboard context to stay active in -/// order to load the contents from other applications. -pub trait Store: Load { - /// Sets the primary clipboard contents - fn store_primary<S>(&mut self, contents: S) -> Result<(), Self::Err> - where - S: Into<String>; - - /// Sets the secondary clipboard contents - fn store_selection<S>(&mut self, contents: S) -> Result<(), Self::Err> - where - S: Into<String>; - - /// Store into the specified `buffer`. - fn store<S>(&mut self, contents: S, buffer: Buffer) -> Result<(), Self::Err> - where - S: Into<String>, - { - match buffer { - Buffer::Selection => self.store_selection(contents), - Buffer::Primary => self.store_primary(contents), - } - } -} - -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] -mod x11; -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] -pub use x11::{Clipboard, Error}; - -#[cfg(target_os = "macos")] -mod macos; -#[cfg(target_os = "macos")] -pub use macos::{Clipboard, Error}; - -#[cfg(windows)] -mod windows; -#[cfg(windows)] -pub use crate::windows::{Clipboard, Error}; |