diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-02-07 22:36:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-07 22:36:45 +0000 |
commit | 35efb4619c4b7a77b3c30de763856bc4441e236e (patch) | |
tree | 99aa70b58f97bd57c2a654e3177eae0ea0b572fa /src/config | |
parent | e561ae373393e919cf3dbbf123a98e0aad215dbc (diff) | |
download | alacritty-35efb4619c4b7a77b3c30de763856bc4441e236e.tar.gz alacritty-35efb4619c4b7a77b3c30de763856bc4441e236e.zip |
Dynamically resize terminal for errors/warnings
The warning and error messages now don't overwrite other terminal
content anymore but instead resize the terminal to make sure that text
can always be read.
Instead of just showing that there is a new error and pointing to the log,
errors will now be displayed fully in multiple lines of text, assuming that
there is enough space left in the terminal.
Explicit mouse click handling has also been added to the message bar,
which made it possible to add a simple `close` button in the form of
`[X]`.
Alacritty's log file location is now stored in the `$ALACRITTY_LOG`
environment variable which the shell inherits automatically.
Previously there were some issues with the log file only being deleted
when certain methods for closing Alacritty were used (like typing
`exit`). This has been reworked and now Ctrl+D, exit and signals should
all work properly.
Before the config is reloaded, all current messages are now dropped.
This should help with multiple terminals all getting clogged up at the
same time when the config is broken.
When one message is removed, all other duplicate messages are
automatically removed too.
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/mod.rs | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index c487ceb7..4ff0cb78 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -5,7 +5,7 @@ //! the config file will also hold user and platform specific keybindings. use std::borrow::Cow; use std::{env, fmt}; -use std::fs::{self, File}; +use std::fs::File; use std::io::{self, Read, Write}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -13,7 +13,6 @@ use std::sync::mpsc; use std::time::Duration; use std::collections::HashMap; -use crate::Rgb; use font::Size; use serde_yaml; use serde::{self, de, Deserialize}; @@ -26,9 +25,11 @@ use crate::cli::Options; use crate::input::{Action, Binding, MouseBinding, KeyBinding}; use crate::index::{Line, Column}; use crate::ansi::{CursorStyle, NamedColor, Color}; +use crate::term::color::Rgb; mod bindings; +pub const SOURCE_FILE_PATH: &str = file!(); const MAX_SCROLLBACK_LINES: u32 = 100_000; static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/alacritty.yml")); @@ -1691,7 +1692,7 @@ impl Config { path = path.join("alacritty/alacritty.yml"); - fs::create_dir_all(path.parent().unwrap())?; + std::fs::create_dir_all(path.parent().unwrap())?; File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; @@ -1868,16 +1869,6 @@ impl Config { self.persistent_logging } - pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> { - let path = path.into(); - let raw = Config::read_file(path.as_path())?; - let mut config: Config = serde_yaml::from_str(&raw)?; - config.config_path = Some(path); - config.print_deprecation_warnings(); - - Ok(config) - } - /// Overrides the `dynamic_title` configuration based on `--title`. pub fn update_dynamic_title(mut self, options: &Options) -> Self { if options.title.is_some() { @@ -1886,15 +1877,35 @@ impl Config { self } - fn read_file<P: AsRef<Path>>(path: P) -> Result<String> { - let mut f = fs::File::open(path)?; + pub fn load_from(path: PathBuf) -> Config { + let mut config = Config::reload_from(&path).unwrap_or_else(|_| Config::default()); + config.config_path = Some(path); + config + } + + pub fn reload_from(path: &PathBuf) -> Result<Config> { + match Config::read_config(path) { + Ok(config) => Ok(config), + Err(err) => { + error!("Unable to load config {:?}: {}", path, err); + Err(err) + } + } + } + + fn read_config(path: &PathBuf) -> Result<Config> { let mut contents = String::new(); - f.read_to_string(&mut contents)?; + File::open(path)?.read_to_string(&mut contents)?; + + // Prevent parsing error with empty string if contents.is_empty() { - return Err(Error::Empty); + return Ok(Config::default()); } - Ok(contents) + let mut config: Config = serde_yaml::from_str(&contents)?; + config.print_deprecation_warnings(); + + Ok(config) } fn print_deprecation_warnings(&mut self) { @@ -2201,7 +2212,7 @@ impl SecondaryFontDescription { pub struct Monitor { _thread: ::std::thread::JoinHandle<()>, - rx: mpsc::Receiver<Config>, + rx: mpsc::Receiver<PathBuf>, } pub trait OnConfigReload { @@ -2216,7 +2227,7 @@ impl OnConfigReload for crate::display::Notifier { impl Monitor { /// Get pending config changes - pub fn pending_config(&self) -> Option<Config> { + pub fn pending(&self) -> Option<PathBuf> { let mut config = None; while let Ok(new) = self.rx.try_recv() { config = Some(new); @@ -2224,6 +2235,7 @@ impl Monitor { config } + pub fn new<H, P>(path: P, mut handler: H) -> Monitor where H: OnConfigReload + Send + 'static, P: Into<PathBuf> @@ -2260,22 +2272,7 @@ impl Monitor { continue; } - let config = match Config::load_from(&path) { - Ok(config) => { - config - }, - Err(err) => { - if let Error::Empty = err { - info!("Config file {:?} is empty; loading default", path); - Config::default() - } else { - error!("Ignoring invalid config: {}", err); - continue; - } - } - }; - - let _ = config_tx.send(config); + let _ = config_tx.send(path); handler.on_config_reload(); } _ => {} |