From 78cfffb73bbc95534716cfa3341efbd6040006ca Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Thu, 5 Sep 2019 20:52:51 +0300 Subject: [PATCH] Add a flag to control setting the terimnal title (fix #194) --- config.example.toml | 2 ++ src/config.rs | 6 ++++++ src/main.rs | 1 + src/terminal.rs | 20 +++++++++++++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/config.example.toml b/config.example.toml index 9f12c742..7b6b6512 100644 --- a/config.example.toml +++ b/config.example.toml @@ -16,6 +16,8 @@ # Arguments to pass Git when pulling Repositories #git_arguments = "--rebase --autostash" +# Do not set the terminal title +#set_title = false # Commands to run before anything #[pre_commands] #"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak" diff --git a/src/config.rs b/src/config.rs index 982913bd..559d4dab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -90,6 +90,7 @@ pub struct ConfigFile { remote_topgrades: Option>, ssh_arguments: Option, git_arguments: Option, + set_title: Option, } impl ConfigFile { @@ -292,4 +293,9 @@ impl Config { pub fn edit_config(&self) -> bool { self.opt.edit_config } + + /// Whether to set the terminal title + pub fn set_title(&self) -> bool { + self.config_file.set_title.unwrap_or(true) + } } diff --git a/src/main.rs b/src/main.rs index 90c2bf73..a98061d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,6 +66,7 @@ fn run() -> Result<(), Error> { let base_dirs = directories::BaseDirs::new().ok_or(ErrorKind::NoBaseDirectories)?; let config = Config::load(&base_dirs)?; + terminal::set_title(config.set_title()); if config.edit_config() { Config::edit(&base_dirs)?; diff --git a/src/terminal.rs b/src/terminal.rs index 1495d92e..b912ff5b 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -31,6 +31,7 @@ struct Terminal { width: Option, prefix: String, term: Term, + set_title: bool, } impl Terminal { @@ -42,12 +43,19 @@ impl Terminal { prefix: env::var("TOPGRADE_PREFIX") .map(|prefix| format!("({}) ", prefix)) .unwrap_or_else(|_| String::new()), + set_title: true, } } + fn set_title(&mut self, set_title: bool) { + self.set_title = set_title + } + fn print_separator>(&mut self, message: P) { - self.term - .set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref())); + if self.set_title { + self.term + .set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref())); + } let now = Local::now(); let message = format!( "{}{:02}:{:02}:{:02} - {}", @@ -121,7 +129,9 @@ impl Terminal { return Ok(false); } - self.term.set_title("Topgrade - Awaiting user"); + if self.set_title { + self.term.set_title("Topgrade - Awaiting user"); + } self.term .write_fmt(format_args!( "\n{}", @@ -198,3 +208,7 @@ pub fn is_dumb() -> bool { pub fn get_char() -> char { TERMINAL.lock().unwrap().get_char().unwrap() } + +pub fn set_title(set_title: bool) { + TERMINAL.lock().unwrap().set_title(set_title); +}