summaryrefslogtreecommitdiffstats
path: root/copypasta
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-02-01 22:13:08 -0800
committerJoe Wilm <jwilm@users.noreply.github.com>2017-02-02 09:25:08 -0800
commitd0283141b538610ccd0252916c6f842fe5146187 (patch)
tree7b2141112da600a4d987d102a5e59cd1433ff1ce /copypasta
parent40d7c0c4344022636f27fac89c4253140b8019fc (diff)
Decouple input processing from Term
Should make input processing much more easily tested.
Diffstat (limited to 'copypasta')
-rw-r--r--copypasta/src/lib.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/copypasta/src/lib.rs b/copypasta/src/lib.rs
index 828c23bd..74e556a9 100644
--- a/copypasta/src/lib.rs
+++ b/copypasta/src/lib.rs
@@ -4,6 +4,12 @@
#[cfg(target_os = "macos")]
#[macro_use] extern crate objc;
+/// 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
@@ -24,6 +30,13 @@ pub trait Load : Sized {
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
@@ -38,6 +51,16 @@ pub trait Store : Load {
/// 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"))]