mod app; mod bitmap; mod brush; mod cli; mod command; mod consts; mod dither; mod error; mod lisp; mod message; mod symmetry; mod undo; mod utils; use { app::AppState, cli::Config, error::{AppError, SdlTTFError}, }; use log::{error, info}; pub fn error_sink() -> Result<(), AppError> { let init = || { let sdl_context = sdl2::init().map_err(AppError::Sdl)?; info!("Initialized SDL context"); let ttf_context = sdl2::ttf::init() .map_err(SdlTTFError::Init) .map_err(AppError::SdlTTF)?; info!("Initialized SDL_ttf context"); Ok((sdl_context, ttf_context)) }; match cli::parse_args().map_err(AppError::Cli)? { Config::Help => { println!("{}", cli::HELP_TEXT); } Config::NewProject { file_name, dimensions: (width, height), } => { let (sdl_context, ttf_context) = init()?; AppState::init(width, height, &sdl_context, &ttf_context, None, file_name)?.run(); } Config::ExistingProject { file_name } => { let (sdl_context, ttf_context) = init()?; let image = utils::load_file(&file_name).map_err(AppError::File)?; AppState::init( image.width(), image.height(), &sdl_context, &ttf_context, Some(image.data), Some(file_name), )? .run(); } } return Ok(()); } pub fn main() { env_logger::init(); match error_sink() { Err(e) => error!("{}", e), _ => (), } }