@@ -1,6 +1,7 @@
1−use anyhow::{Context, Result};
1+use anyhow::{Context, Error, Result};
22use helix_term::application::Application;
33use helix_term::args::Args;
4+use helix_term::config::Config;
45use std::path::PathBuf;
56
67fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
@@ -110,8 +111,28 @@ FLAGS:
110111
111112 setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
112113
114+ let config_dir = helix_loader::config_dir();
115+ if !config_dir.exists() {
116+ std::fs::create_dir_all(&config_dir).ok();
117+ }
118+
119+ let config = match std::fs::read_to_string(config_dir.join("config.toml")) {
120+ Ok(config) => toml::from_str(&config)
121+ .map(helix_term::keymap::merge_keys)
122+ .unwrap_or_else(|err| {
123+ eprintln!("Bad config: {}", err);
124+ eprintln!("Press <ENTER> to continue with default config");
125+ use std::io::Read;
126+ // This waits for an enter press.
127+ let _ = std::io::stdin().read(&mut []);
128+ Config::default()
129+ }),
130+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(),
131+ Err(err) => return Err(Error::new(err)),
132+ };
133+
113134 // TODO: use the thread local executor to spawn the application task separately from the work pool
114− let mut app = Application::new(args).context("unable to create new application")?;
135+ let mut app = Application::new(args, config).context("unable to create new application")?;
115136
116137 let exit_code = app.run().await?;
117138