diff options
author | Teddy Wing | 2016-08-06 02:20:43 -0400 |
---|---|---|
committer | Teddy Wing | 2016-08-06 02:20:43 -0400 |
commit | a090a72139ae0d1466859758b57408b4de49c14a (patch) | |
tree | ffe94a305dbb8c68c97d7144b7fc1ef5a142133a /src | |
parent | bcddc44e2f034c1b7ef0dfb2037184b96080a1ae (diff) | |
download | Passextract-a090a72139ae0d1466859758b57408b4de49c14a.tar.bz2 |
Handle `Result` on clipboard `set_contents`
Change the colour of the selection arrow to red if there's an error and
green if the clipboard was written to successfully.
The colour only lasts for 100 milliseconds because that's the refresh
rate of the loop. This seems to be a nice way to briefly offer a visual
notification and automatically return the interface to normal right
afterward.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index f0a452a..ee06d29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,8 @@ fn main() { term.swap_buffers().unwrap(); let knockout_cell = Cell::with_style(Color::White, Color::Black, Attr::Default); + let red_cell = Cell::with_style(Color::White, Color::Red, Attr::Default); + let green_cell = Cell::with_style(Color::White, Color::Green, Attr::Default); let mut selection = Point { x: 0, y: 2 }; @@ -73,7 +75,14 @@ fn main() { } } '\x0D' => { - clipboard_ctx.set_contents(strip_key(options[selection.y - 3]).to_owned()).unwrap() + match clipboard_ctx.set_contents(strip_key(options[selection.y - 3]).to_owned()) { + Ok(_) => { + term.printline_with_cell(selection.x, selection.y, "->", green_cell); + }, + Err(_) => { + term.printline_with_cell(selection.x, selection.y, "->", red_cell); + } + } } c @ _ => { } |