diff options
author | Joe Wilm <joe@jwilm.com> | 2016-10-08 18:42:33 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-10-08 18:42:33 -0700 |
commit | 9d491f9f676536634040fea8294dc672f3466e26 (patch) | |
tree | 81d4ddc867c570a9004c3d878647feb69e0e2d91 /copypasta/src/lib.rs | |
parent | 7e69a070aaf92eff3bea1878bd77821b5ae60ede (diff) | |
download | r-alacritty-9d491f9f676536634040fea8294dc672f3466e26.tar.gz r-alacritty-9d491f9f676536634040fea8294dc672f3466e26.tar.bz2 r-alacritty-9d491f9f676536634040fea8294dc672f3466e26.zip |
Start implementing copypasta, a clipboard library
Currently it only supports x11 via the xclip program, and that only
supports reading the clipboard contents.
Diffstat (limited to 'copypasta/src/lib.rs')
-rw-r--r-- | copypasta/src/lib.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/copypasta/src/lib.rs b/copypasta/src/lib.rs new file mode 100644 index 00000000..722142aa --- /dev/null +++ b/copypasta/src/lib.rs @@ -0,0 +1,46 @@ +//! A cross-platform clipboard library + +/// 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() + } +} + +/// 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(&mut self, contents: String) -> Result<(), Self::Err>; + + /// Sets the secondary clipboard contents + fn store_selection(&mut self, contents: String) -> Result<(), Self::Err>; +} + +#[cfg(target_os = "linux")] +mod x11; +#[cfg(target_os = "linux")] +pub use x11::{Clipboard, Error}; + +#[cfg(target_os = "macos")] +mod macos; +#[cfg(target_os = "macos")] +pub use macos::{Clipboard, Error}; + |