From bee05dd32a685b58015514492525673b1b568b0d Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 25 Mar 2022 05:05:20 -0400 Subject: Add refresh-config and open-config command (#1803) * Add refresh-config and open-config command * clippy * Use dynamic dispatch for editor config * Refactor Result::Ok to Ok * Remove unused import * cargo fmt * Modify config error handling * cargo xtask docgen * impl display for ConfigLoadError * cargo fmt * Put keymaps behind dyn access, refactor config.load() * Update command names * Update helix-term/src/application.rs Co-authored-by: Blaž Hrastnik * Switch to unbounded_channel * Remove --edit-config command * Update configuration docs * Revert "Put keymaps behind dyn access", too hard This reverts commit 06bad8cf492b9331d0a2d1e9242f3ad4e2c1cf79. * Add refresh for keys * Refactor default_keymaps, fix config default, add test * swap -> store, remove unneeded clone * cargo fmt * Rename default_keymaps to default Co-authored-by: Blaž Hrastnik --- helix-term/src/main.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'helix-term/src/main.rs') diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index e554a21b..0385d92c 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -1,8 +1,7 @@ use anyhow::{Context, Error, Result}; use helix_term::application::Application; use helix_term::args::Args; -use helix_term::config::Config; -use helix_term::keymap::merge_keys; +use helix_term::config::{Config, ConfigLoadError}; use std::path::PathBuf; fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> { @@ -60,7 +59,6 @@ ARGS: FLAGS: -h, --help Prints help information - --edit-config Opens the helix config file --tutor Loads the tutorial --health [LANG] Checks for potential errors in editor setup If given, checks for config errors in language LANG @@ -118,19 +116,24 @@ FLAGS: std::fs::create_dir_all(&conf_dir).ok(); } - let config = match std::fs::read_to_string(helix_loader::config_file()) { - Ok(config) => toml::from_str(&config) - .map(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 config = match Config::load_default() { + Ok(config) => config, + Err(err) => { + match err { + ConfigLoadError::BadConfig(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() + } + ConfigLoadError::Error(err) if err.kind() == std::io::ErrorKind::NotFound => { + Config::default() + } + ConfigLoadError::Error(err) => return Err(Error::new(err)), + } + } }; setup_logging(logpath, args.verbosity).context("failed to initialize logging")?; -- cgit v1.2.3-70-g09d2