From a090a72139ae0d1466859758b57408b4de49c14a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 6 Aug 2016 02:20:43 -0400 Subject: 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. --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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 @ _ => { } -- cgit v1.2.3