1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#![allow(
clippy::upper_case_acronyms,
clippy::vec_init_then_push,
clippy::unsound_collection_transmute,
clippy::new_without_default
)]
mod app;
mod bitmap;
mod brush;
mod cache;
mod cli;
mod command;
mod consts;
mod dither;
mod error;
mod grid;
mod guide;
mod keybind;
mod lisp;
mod message;
mod symmetry;
mod undo;
mod utils;
mod widget;
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();
}
}
Ok(())
}
pub fn main() {
env_logger::init();
if let Err(e) = error_sink() {
error!("{}", e);
}
}
|