aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiu Wei <liuw@liuw.name>2017-08-29 17:32:08 +0100
committerJoe Wilm <jwilm@users.noreply.github.com>2017-08-29 09:32:08 -0700
commitb38d825921ac20d9f6543c23ed3bc0a44a0bdf2d (patch)
tree226a3e48f82392933ee218efc336b08aa71c43b8
parent6495ab34d2043440f138242cf58d39e687e6c02e (diff)
downloadalacritty-b38d825921ac20d9f6543c23ed3bc0a44a0bdf2d.tar.gz
alacritty-b38d825921ac20d9f6543c23ed3bc0a44a0bdf2d.zip
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.
-rw-r--r--alacritty.yml3
-rw-r--r--alacritty_macos.yml3
-rw-r--r--src/cli.rs15
-rw-r--r--src/config.rs11
-rw-r--r--src/main.rs11
5 files changed, 41 insertions, 2 deletions
diff --git a/alacritty.yml b/alacritty.yml
index c5e8ba0d..20529a78 100644
--- a/alacritty.yml
+++ b/alacritty.yml
@@ -278,6 +278,9 @@ selection:
hide_cursor_when_typing: false
+# Live config reload (changes require restart)
+live_config_reload: true
+
# Shell
#
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
diff --git a/alacritty_macos.yml b/alacritty_macos.yml
index 6659ea92..cbea7bec 100644
--- a/alacritty_macos.yml
+++ b/alacritty_macos.yml
@@ -273,6 +273,9 @@ selection:
hide_cursor_when_typing: false
+# Live config reload (changes require restart)
+live_config_reload: true
+
# Shell
#
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
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<bool>,
pub print_events: bool,
pub ref_test: bool,
pub dimensions: Option<Dimensions>,
@@ -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<P: Into<PathBuf>>(path: P) -> Result<Config> {
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<Error>> {
//
// 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);