main.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #![feature(duration_millis_float)]
  2. use std::{env, fs::File};
  3. use application::Application;
  4. use clap::Parser;
  5. use config::{appconfig::DeserializeAppOption, cmd::CmdConfig};
  6. use utils::log_util::Log;
  7. mod application;
  8. mod buffer;
  9. mod config;
  10. mod errors;
  11. mod modules;
  12. mod plugin;
  13. mod util;
  14. mod utils;
  15. mod view;
  16. mod workspace;
  17. #[macro_use]
  18. extern crate log;
  19. extern crate simplelog;
  20. use crate::errors::*;
  21. pub static mut APPLICATION: Option<Application> = None;
  22. pub fn get_application() -> &'static mut Application {
  23. unsafe { APPLICATION.as_mut().unwrap() }
  24. }
  25. fn main() -> Result<()> {
  26. let args: Vec<String> = env::args().collect();
  27. let config = CmdConfig::parse();
  28. Log::init(config.level)?;
  29. let setting;
  30. let file = File::open("config.yaml");
  31. if file.is_err() {
  32. setting = DeserializeAppOption::default();
  33. } else {
  34. setting = serde_yaml::from_reader::<File, DeserializeAppOption>(file?).unwrap_or_default();
  35. }
  36. let application = Application::new(config.file, setting.to_app_setting(), &args)?;
  37. unsafe {
  38. APPLICATION = Some(application);
  39. }
  40. get_application().run()
  41. }