From b9661e4c9af8f519cabb92c5c114ef4ff75d70d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20=C3=85sberg?= Date: Sun, 4 Oct 2020 12:20:34 +0200 Subject: [PATCH] Failing gracefully when the cursor can't be hidden --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55f3d4d..683fd3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,7 @@ fn main() { let delay = get_arg_as_t(&matches, "DELAY"); let mut stdout = stdout(); - stdout.execute(cursor::Hide).expect("Could not hide cursor."); + let did_hide = stdout.execute(cursor::Hide).is_ok(); let initial_peek_fn = |map: &Map| println!("{}", map); let peek_fn = |map: &Map, pos: &Position, dir: &Direction| { let chars = map.get_chars(pos, dir); @@ -161,7 +161,10 @@ fn main() { } else { Map::generate_dfs(rows, columns, start_pos, initial_peek_fn, peek_fn) }; - stdout.execute(cursor::Show).expect("Could not show cursor."); + + if did_hide { + stdout.execute(cursor::Show).expect("Could not show cursor."); + } if let Some(path) = map.solve(Position(0, 0), Position(map.rows - 1, map.columns - 1)) { println!(