From b38d825921ac20d9f6543c23ed3bc0a44a0bdf2d Mon Sep 17 00:00:00 2001 From: Liu Wei Date: Tue, 29 Aug 2017 17:32:08 +0100 Subject: Implement options to not start the config_monitor thread (#689) Provide a command line option as well as a configuration file option. The command line option takes precedence. --- src/cli.rs | 15 +++++++++++++++ src/config.rs | 11 +++++++++++ src/main.rs | 11 +++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index 789b1755..ea5610eb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,6 +22,7 @@ const DEFAULT_TITLE: &'static str = "Alacritty"; /// Options specified on the command line pub struct Options { + pub live_config_reload: Option, pub print_events: bool, pub ref_test: bool, pub dimensions: Option, @@ -35,6 +36,7 @@ pub struct Options { impl Default for Options { fn default() -> Options { Options { + live_config_reload: None, print_events: false, ref_test: false, dimensions: None, @@ -59,6 +61,11 @@ impl Options { .arg(Arg::with_name("ref-test") .long("ref-test") .help("Generates ref test")) + .arg(Arg::with_name("live-config-reload") + .long("live-config-reload") + .help("Live configuration reload") + .takes_value(true) + .use_delimiter(false)) .arg(Arg::with_name("print-events") .long("print-events")) .arg(Arg::with_name("dimensions") @@ -107,6 +114,14 @@ impl Options { options.print_events = true; } + if let Some(val) = matches.value_of("live-config-reload") { + match val { + "y" | "yes" => options.live_config_reload = Some(true), + "n" | "no" => options.live_config_reload = Some(false), + _ => options.live_config_reload = None, + } + } + if let Some(mut dimensions) = matches.values_of("dimensions") { let width = dimensions.next().map(|w| w.parse().map(|w| Column(w))); let height = dimensions.next().map(|h| h.parse().map(|h| Line(h))); diff --git a/src/config.rs b/src/config.rs index 450ab09e..b88723f5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -277,6 +277,10 @@ pub struct Config { /// Hide cursor when typing #[serde(default)] hide_cursor_when_typing: bool, + + /// Live config reload + #[serde(default)] + live_config_reload: bool, } fn default_padding() -> Delta { @@ -329,6 +333,7 @@ impl Default for Config { visual_bell: Default::default(), env: Default::default(), hide_cursor_when_typing: Default::default(), + live_config_reload: Default::default(), padding: default_padding(), } } @@ -1177,6 +1182,12 @@ impl Config { self.hide_cursor_when_typing } + /// Live config reload + #[inline] + pub fn live_config_reload(&self) -> bool { + self.live_config_reload + } + pub fn load_from>(path: P) -> Result { let path = path.into(); let raw = Config::read_file(path.as_path())?; diff --git a/src/main.rs b/src/main.rs index 472e4144..b8b82914 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,8 +148,15 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box> { // // The monitor watches the config file for changes and reloads it. Pending // config changes are processed in the main loop. - let config_monitor = config.path() - .map(|path| config::Monitor::new(path, display.notifier())); + let config_monitor = match (options.live_config_reload, config.live_config_reload()) { + // Start monitor if CLI flag says yes + (Some(true), _) | + // Or if no CLI flag was passed and the config says yes + (None, true) => config.path() + .map(|path| config::Monitor::new(path, display.notifier())), + // Otherwise, don't start the monitor + _ => None, + }; // Kick off the I/O thread let io_thread = event_loop.spawn(None); -- cgit