diff options
author | Josh Leverette <josh.leverette@utiliflex.com> | 2017-01-06 15:02:13 -0500 |
---|---|---|
committer | Josh Leverette <josh.leverette@utiliflex.com> | 2017-01-06 15:02:13 -0500 |
commit | 4fad82bc267141532460d6fc15b1ee6c1acd9589 (patch) | |
tree | 74edf44a07b6533cc72dbd8ea38ba4ea799a6294 /src | |
parent | 2dd5f0f45d403fee11215eb515eff41168198e13 (diff) | |
parent | 8d3f5f4e179b6fe55617dc72fe60fa1bdfd9b014 (diff) | |
download | alacritty-4fad82bc267141532460d6fc15b1ee6c1acd9589.tar.gz alacritty-4fad82bc267141532460d6fc15b1ee6c1acd9589.zip |
Merge branch 'master' of github.com:coder543/alacritty
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 14 | ||||
-rw-r--r-- | src/event.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 8 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 5daa4455..36f0c363 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,11 +6,12 @@ use std::env; use std::fmt; use std::fs; -use std::io::{self, Read}; +use std::io::{self, Read, Write}; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::mpsc; use std::ops::{Index, IndexMut}; +use std::fs::File; use ::Rgb; use font::Size; @@ -199,7 +200,10 @@ pub struct Config { config_path: Option<PathBuf>, } +#[cfg(not(target_os="macos"))] static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty.yml"); +#[cfg(target_os="macos")] +static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty_macos.yml"); fn default_config() -> Config { serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG) @@ -821,6 +825,14 @@ impl Config { Config::load_from(path) } + pub fn write_defaults() -> io::Result<PathBuf> { + let path = ::xdg::BaseDirectories::new() + .map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err))) + .and_then(|p| p.place_config_file("alacritty.yml"))?; + File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; + Ok(path) + } + /// Get list of colors /// /// The ordering returned here is expected by the terminal. Colors are simply indexed in this diff --git a/src/event.rs b/src/event.rs index 88f28952..66abbaa2 100644 --- a/src/event.rs +++ b/src/event.rs @@ -129,8 +129,8 @@ impl<N: Notify> Processor<N> { .expect("write size.json"); } - // FIXME - panic!("window closed"); + // FIXME should do a more graceful shutdown + ::std::process::exit(0); }, glutin::Event::Resized(w, h) => { resize_tx.send((w, h)).expect("send new size"); diff --git a/src/main.rs b/src/main.rs index 3328ab59..d53daf0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,8 +38,12 @@ fn main() { match err { // Use default config when not found config::Error::NotFound => { - err_println!("Config file not found; using defaults"); - Config::default() + match Config::write_defaults() { + Ok(path) => err_println!("Config file not found; write defaults config to {:?}", path), + Err(err) => err_println!("Write defaults config failure: {}", err) + } + + Config::load().unwrap() }, // If there's a problem with the config file, print an error |