aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2016-08-06 04:42:17 -0400
committerTeddy Wing2016-08-06 04:42:17 -0400
commit78681400909e395372a5e6fe743fbdc7b1c39752 (patch)
tree3e3798014fc537aa99ce882ef270eae0e3acd337 /src/main.rs
parenta090a72139ae0d1466859758b57408b4de49c14a (diff)
downloadPassextract-78681400909e395372a5e6fe743fbdc7b1c39752.tar.bz2
Parse options from STDIN
Read STDIN and get all lines that start with "e: ", "u: ", and "p: ". If none are found, exit. These lines get added to the `options` vector which then gets displayed in the TUI. Since the contents of the vector are different from our hard-coded one, use a borrow on the clipboard write call.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index ee06d29..ce0f4fe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,6 +6,8 @@ use clipboard::ClipboardContext;
use rustty::{Terminal, Event, Cell, Color, Attr};
use rustty::ui::Painter;
+use std::io::{self, BufRead};
+use std::process;
use std::time::Duration;
struct Point {
@@ -19,6 +21,22 @@ fn strip_key(line: &str) -> &str {
}
fn main() {
+ let mut options = Vec::new();
+ let stdin = io::stdin();
+ for line in stdin.lock().lines() {
+ let line = line.expect("Error reading from STDIN");
+
+ if line.starts_with("e: ") ||
+ line.starts_with("u: ") ||
+ line.starts_with("p: ") {
+ options.push(line);
+ }
+ }
+
+ if options.is_empty() {
+ process::exit(1);
+ }
+
let mut term = Terminal::new().unwrap();
term.swap_buffers().unwrap();
@@ -36,12 +54,6 @@ fn main() {
term.printline_with_cell(selection.x, selection.y, "->", knockout_cell);
term.printline(5, 2, "test");
- let options = vec![
- "e: booya@kacha.ch",
- "u: booyakacha",
- "p: secret"
- ];
-
for (i, s) in options.iter().enumerate() {
term.printline(5, i + 3, s)
}
@@ -75,7 +87,7 @@ fn main() {
}
}
'\x0D' => {
- match clipboard_ctx.set_contents(strip_key(options[selection.y - 3]).to_owned()) {
+ match clipboard_ctx.set_contents(strip_key(&options[selection.y - 3]).to_owned()) {
Ok(_) => {
term.printline_with_cell(selection.x, selection.y, "->", green_cell);
},