diff options
author | Joe | 2022-03-25 09:05:20 +0000 |
---|---|---|
committer | GitHub | 2022-03-25 09:05:20 +0000 |
commit | bee05dd32a685b58015514492525673b1b568b0d (patch) | |
tree | 4d141ece2ff029b881013f7ef4e89bfb9b064919 /helix-term/src/main.rs | |
parent | 309f2c2c8e64f8be2123a0232c5f9761496b6514 (diff) |
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 <blaz@mxxn.io>
* 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 <blaz@mxxn.io>
Diffstat (limited to 'helix-term/src/main.rs')
-rw-r--r-- | helix-term/src/main.rs | 35 |
1 files changed, 19 insertions, 16 deletions
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 <ENTER> 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 <ENTER> 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")?; |