Add a flag to control setting the terimnal title (fix #194)

This commit is contained in:
Roey Darwish Dror
2019-09-05 20:52:51 +03:00
parent b80f31db37
commit 78cfffb73b
4 changed files with 26 additions and 3 deletions

View File

@@ -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"

View File

@@ -90,6 +90,7 @@ pub struct ConfigFile {
remote_topgrades: Option<Vec<String>>,
ssh_arguments: Option<String>,
git_arguments: Option<String>,
set_title: Option<bool>,
}
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)
}
}

View File

@@ -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)?;

View File

@@ -31,6 +31,7 @@ struct Terminal {
width: Option<u16>,
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<P: AsRef<str>>(&mut self, message: P) {
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);
}
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);
}