From 257f43f02adcacca84ea053e28bc871e711319ba Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Thu, 3 Mar 2022 12:08:08 -0700 Subject: [PATCH] Better error handling --- src/io.rs | 16 +++++----------- src/main.rs | 8 +++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/io.rs b/src/io.rs index dbc0d3e..5128a3c 100644 --- a/src/io.rs +++ b/src/io.rs @@ -10,7 +10,7 @@ use thiserror::Error; /// Initializes the terminal to accept user input, and creates a new /// Window. -pub fn init_window() -> Window { +pub fn init_window() -> Result { // Create a new window over the terminal. let window = initscr(); @@ -22,16 +22,10 @@ pub fn init_window() -> Window { // upper-left corner of the screen when they type a character. noecho(); - // // Set up a color palette. TODO - // init_colors().unwrap(); - let c = init_colors(); - if let Err(e) = c { - endwin(); - println!("{}", e); - panic!(); - } + // Set up a color palette. + init_colors()?; - window + Ok(window) } /// Cleans everything up and exits the game. @@ -55,7 +49,7 @@ pub enum Color { } #[derive(Error, Debug)] -enum ColorError { +pub enum ColorError { #[error("colors not supported")] NoColors, diff --git a/src/main.rs b/src/main.rs index acc8efa..c882191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,13 @@ fn main() { .with(MobSystem, "mobs", &[]) .build(); - let mut window = init_window(); + let mut window = match init_window() { + Ok(window) => window, + Err(err) => { + println!("Error initializing window: {}", err); + return; + }, + }; loop { dispatcher.dispatch(&world);