From 0623a72599f5ffe7adfd0ebe5445ad5eaa26ff91 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Sun, 24 Apr 2022 16:01:45 -0400 Subject: [PATCH] move config parsing back into main --- helix-term/src/application.rs | 21 +-------------------- helix-term/src/main.rs | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0c8de2ab..e8fbb7cc 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -56,29 +56,10 @@ pub struct Application { } impl Application { - pub fn new(args: Args) -> Result { + pub fn new(args: Args, config: Config) -> Result { use helix_view::editor::Action; let config_dir = helix_loader::config_dir(); - if !config_dir.exists() { - std::fs::create_dir_all(&config_dir).ok(); - } - - let config = match std::fs::read_to_string(config_dir.join("config.toml")) { - Ok(config) => toml::from_str(&config) - .map(crate::keymap::merge_keys) - .unwrap_or_else(|err| { - eprintln!("Bad config: {}", err); - eprintln!("Press to continue with default config"); - use std::io::Read; - // This waits for an enter press. - let _ = std::io::stdin().read(&mut []); - Config::default() - }), - Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(), - Err(err) => return Err(Error::new(err)), - }; - let theme_loader = std::sync::Arc::new(theme::Loader::new( &config_dir, &helix_loader::runtime_dir(), diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 58a90131..cd0b364b 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -1,6 +1,7 @@ -use anyhow::{Context, Result}; +use anyhow::{Context, Error, Result}; use helix_term::application::Application; use helix_term::args::Args; +use helix_term::config::Config; use std::path::PathBuf; fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> { @@ -110,8 +111,28 @@ FLAGS: setup_logging(logpath, args.verbosity).context("failed to initialize logging")?; + let config_dir = helix_loader::config_dir(); + if !config_dir.exists() { + std::fs::create_dir_all(&config_dir).ok(); + } + + let config = match std::fs::read_to_string(config_dir.join("config.toml")) { + Ok(config) => toml::from_str(&config) + .map(helix_term::keymap::merge_keys) + .unwrap_or_else(|err| { + eprintln!("Bad config: {}", err); + eprintln!("Press to continue with default config"); + use std::io::Read; + // This waits for an enter press. + let _ = std::io::stdin().read(&mut []); + Config::default() + }), + Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(), + Err(err) => return Err(Error::new(err)), + }; + // TODO: use the thread local executor to spawn the application task separately from the work pool - let mut app = Application::new(args).context("unable to create new application")?; + let mut app = Application::new(args, config).context("unable to create new application")?; let exit_code = app.run().await?;