aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/application.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r--helix-term/src/application.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index bc5f3bd7..7733c2c6 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -56,15 +56,33 @@ pub struct Application {
}
impl Application {
- pub fn new(args: Args, config: Config) -> Result<Self, Error> {
+ pub fn new(args: Args) -> Result<Self, Error> {
use helix_view::editor::Action;
- let mut compositor = Compositor::new()?;
- let size = compositor.size();
- let conf_dir = helix_loader::config_dir();
+ let config_dir = helix_loader::config_dir();
+ if !config_dir.exists() {
+ std::fs::create_dir_all(&config_dir).ok();
+ }
- let theme_loader =
- std::sync::Arc::new(theme::Loader::new(&conf_dir, &helix_loader::runtime_dir()));
+ 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 <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 theme_loader = std::sync::Arc::new(theme::Loader::new(
+ &config_dir,
+ &helix_loader::runtime_dir(),
+ ));
let true_color = config.editor.true_color || crate::true_color();
let theme = config
@@ -98,9 +116,10 @@ impl Application {
});
let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));
+ let mut compositor = Compositor::new()?;
let config = Arc::new(ArcSwap::from_pointee(config));
let mut editor = Editor::new(
- size,
+ compositor.size(),
theme_loader.clone(),
syn_loader.clone(),
Box::new(Map::new(Arc::clone(&config), |config: &Config| {