Skip to content

Commit

Permalink
Failing gracefully when the cursor can't be hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
89netraM committed Oct 4, 2020
1 parent 2c06ad0 commit b9661e4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit b9661e4

Please sign in to comment.