diff options
-rw-r--r-- | src/clipboard_store.rs | 36 | ||||
-rw-r--r-- | src/main.rs | 20 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/clipboard_store.rs b/src/clipboard_store.rs new file mode 100644 index 0000000..61f53b3 --- /dev/null +++ b/src/clipboard_store.rs @@ -0,0 +1,36 @@ +extern crate clipboard; + +use std::error::Error; + +use clipboard::ClipboardContext; + +pub struct ClipboardStore { + context: ClipboardContext, + last: String, +} + +impl ClipboardStore { + pub fn new() -> Result<ClipboardStore, Box<Error>> { + let context = try!(ClipboardContext::new()); + + return Ok( + ClipboardStore { + context: context, + last: String::new(), + } + ) + } + + pub fn set_contents(&mut self, data: String) -> Result<(), Box<Error>> { + // Save last value + self.last = try!(self.context.get_contents()); + println!("last: {}", self.last); + + // Set new clipboard contents + // self.context.set_contents(data) + Ok(()) + } + + pub fn reset() { + } +} diff --git a/src/main.rs b/src/main.rs index 8e497c7..f499809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,10 @@ use std::io::{self, BufRead}; use std::process::{self, Command}; use std::time::Duration; +mod clipboard_store; + +use clipboard_store::ClipboardStore; + struct Point { x: usize, y: usize, @@ -78,6 +82,17 @@ fn parse_options(filename: &str) -> Vec<String> { options } +fn spawn_reset_clipboard() { + Command::new("passextract") + .arg("--reset-clipboard") + .spawn() + .expect("Failed to reset clipboard"); +} + +fn reset_clipboard() { + +} + fn main() { let args: Vec<String> = env::args().collect(); @@ -103,6 +118,7 @@ fn main() { let mut selection = Point { x: 0, y: 2 }; let mut clipboard_ctx = ClipboardContext::new().unwrap(); + let mut clipboard_store = ClipboardStore::new().expect("Failed to initialize clipboard storage"); loop { term.printline_with_cell(0, 0, "Passextract (Press q or Ctrl-C to quit)", knockout_cell); @@ -117,6 +133,9 @@ fn main() { if let Some(Event::Key(ch)) = evt { match ch { 'q' | '\x03' => { + // Reset clipboard + reset_clipboard(); + break; } 'j' => { @@ -138,6 +157,7 @@ fn main() { move_selection(&mut term, &mut selection, knockout_cell, options.len() + 1) } '\x0D' => { + clipboard_store.set_contents(strip_key(&options[selection.y - 2]).to_owned()); match clipboard_ctx.set_contents(strip_key(&options[selection.y - 2]).to_owned()) { Ok(_) => { term.printline_with_cell(selection.x, selection.y, "->", green_cell); |