| 1 | use anyhow::Result; |
| 2 | |
| 3 | #[macro_use] |
| 4 | extern crate log; |
| 5 | extern crate simplelog; |
| 6 | |
| 7 | mod action; |
| 8 | mod app; |
| 9 | mod cli; |
| 10 | mod config; |
| 11 | mod events; |
| 12 | mod logger; |
| 13 | mod network_manager; |
| 14 | mod timer; |
| 15 | mod tui; |
| 16 | mod ui; |
| 17 | |
| 18 | use app::App; |
| 19 | use log::logger; |
| 20 | use tui::Tui; |
| 21 | |
| 22 | use crate::{cli::Cli, config::Config}; |
| 23 | |
| 24 | #[tokio::main] |
| 25 | async fn main() -> Result<()> { |
| 26 | let cli = Cli::new(); |
| 27 | if cli.args.config { |
| 28 | let _ = Config::create(&Config::default()); |
| 29 | } else { |
| 30 | // Initialize |
| 31 | logger::init()?; |
| 32 | let config = Config::load().unwrap_or_default(); |
| 33 | let mut app = App::new(config).await?; |
| 34 | let mut tui = Tui::new()?; |
| 35 | |
| 36 | // Start TUI |
| 37 | if let Err(e) = tui.run(&mut app).await { |
| 38 | tui.cleanup()?; |
| 39 | |
| 40 | error!("Fatal error: {:#}", e); |
| 41 | logger().flush(); |
| 42 | return Err(e); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Ok(()) |
| 47 | } |
