diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 564e193..4478a81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,14 +21,54 @@ If not, see <https://www.gnu.org/licenses/>. */ +extern crate ctrlc; +extern crate sdl2; +extern crate toml; + mod luma; -use crate::luma::application::Application; +use crate::luma::VERSION; +use crate::luma::app::App; use crate::luma::configuration::Configuration; +use std::env::{args, var}; +use std::process::exit; + fn main() { - let configuration = Configuration::new(); + eprintln!(); + eprintln!("\u{1B}[1mluma\u{1B}[0m {:X}.{:X}", VERSION.0, VERSION.1); + eprintln!("Copyright 2021-2023 \u{1B}[1mGabriel Bj\u{F8}rnager Jensen\u{1B}[0m."); + eprintln!(); + + let path = if let Some(path) = args().nth(0x1) { path } + else { default_configuration_path() }; + + let configuration = match Configuration::load(&path) { + Ok( configuration) => configuration, + Err(message) => panic!("unable to load configuration: {message}"), + }; + + let app = match App::init(configuration) { + Ok( app) => app, + Err(message) => panic!("unable to initialise application: {message}"), + }; + + let result = app.run(); + + if let Err(ref message) = result { eprintln!("\u{1B}[1m\u{1B}[91merror\u{1B}[0m: {message}") }; + + exit(match result { + Ok( ..) => 0x0, + Err(..) => 0x1, + }); +} + +fn default_configuration_path() -> String { + let home = match var("HOME") { + Ok( path) => path, + Err(..) => "/".to_string(), + }; - let mut application = Application::initialise(&configuration); - application.run(); + let path = home + "/.luma.toml"; + return path; } |