mod app; mod bitmap; mod brush; mod command; mod consts; mod dither; mod error; mod lisp; mod message; mod symmetry; mod undo; mod utils; use app::AppState; use error::{AppError, SdlTTFError}; use std::{ env, fs::OpenOptions, io::{Cursor, Read}, path::PathBuf, }; use log::{error, info}; use obi::Image; pub fn error_sink() -> Result<(), AppError> { env_logger::init(); let sdl_context = sdl2::init().map_err(AppError::Sdl)?; info!("Initialized SDL context"); let ttf_context = sdl2::ttf::init().map_err(|e| AppError::SdlTTF(SdlTTFError::Init(e)))?; info!("Initialized SDL_ttf context"); let args: Vec<_> = env::args().collect(); if args.len() < 2 { AppState::init(160, 160, &sdl_context, &ttf_context, None, None)?.run(); return Ok(()); } else { let path = PathBuf::from(args.get(1).unwrap()); let mut image = OpenOptions::new() .read(true) .write(false) .create(false) .open(&path) .map_err(AppError::File)?; let mut buf = Vec::new(); image.read_to_end(&mut buf).map_err(AppError::File)?; let decoded = Image::decode(&mut (Cursor::new(buf))).unwrap(); // TODO: obi error let (width, height) = (decoded.width(), decoded.height()); AppState::init( width, height, &sdl_context, &ttf_context, Some(decoded.data), Some(&path), )? .run(); return Ok(()); } } pub fn main() { match error_sink() { Err(e) => error!("{}", e), _ => (), } }