From f55252ec8537e68d0c98a1fac35728a2b596d328 Mon Sep 17 00:00:00 2001 From: Nathan Lilienthal Date: Mon, 18 Jun 2018 01:26:54 -0400 Subject: Override dynamic_title when --title is specified --- src/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index ed69ec5d..539edb61 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,7 @@ use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode}; use glutin::ModifiersState; +use cli::Options; use input::{Action, Binding, MouseBinding, KeyBinding}; use index::{Line, Column}; use ansi::CursorStyle; @@ -1383,6 +1384,14 @@ impl Config { 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() { + self.dynamic_title = false; + } + self + } + fn read_file>(path: P) -> Result { let mut f = fs::File::open(path)?; let mut contents = String::new(); @@ -1713,6 +1722,7 @@ impl Monitor { #[cfg(test)] mod tests { + use cli::Options; use super::Config; #[cfg(target_os="macos")] @@ -1733,6 +1743,26 @@ mod tests { // Sanity check that key bindings are being parsed assert!(!config.key_bindings.is_empty()); } + + #[test] + fn dynamic_title_ignoring_options_by_default() { + let config: Config = ::serde_yaml::from_str(ALACRITTY_YML) + .expect("deserialize config"); + let old_dynamic_title = config.dynamic_title; + let options = Options::default(); + let config = config.update_dynamic_title(&options); + assert_eq!(old_dynamic_title, config.dynamic_title); + } + + #[test] + fn dynamic_title_overridden_by_options() { + let config: Config = ::serde_yaml::from_str(ALACRITTY_YML) + .expect("deserialize config"); + let mut options = Options::default(); + options.title = Some("foo".to_owned()); + let config = config.update_dynamic_title(&options); + assert!(!config.dynamic_title); + } } #[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] -- cgit