Add a flag to control setting the terimnal title (fix #194)
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
# Arguments to pass Git when pulling Repositories
|
# Arguments to pass Git when pulling Repositories
|
||||||
#git_arguments = "--rebase --autostash"
|
#git_arguments = "--rebase --autostash"
|
||||||
|
|
||||||
|
# Do not set the terminal title
|
||||||
|
#set_title = false
|
||||||
# Commands to run before anything
|
# Commands to run before anything
|
||||||
#[pre_commands]
|
#[pre_commands]
|
||||||
#"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak"
|
#"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak"
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ pub struct ConfigFile {
|
|||||||
remote_topgrades: Option<Vec<String>>,
|
remote_topgrades: Option<Vec<String>>,
|
||||||
ssh_arguments: Option<String>,
|
ssh_arguments: Option<String>,
|
||||||
git_arguments: Option<String>,
|
git_arguments: Option<String>,
|
||||||
|
set_title: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigFile {
|
impl ConfigFile {
|
||||||
@@ -292,4 +293,9 @@ impl Config {
|
|||||||
pub fn edit_config(&self) -> bool {
|
pub fn edit_config(&self) -> bool {
|
||||||
self.opt.edit_config
|
self.opt.edit_config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether to set the terminal title
|
||||||
|
pub fn set_title(&self) -> bool {
|
||||||
|
self.config_file.set_title.unwrap_or(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ fn run() -> Result<(), Error> {
|
|||||||
|
|
||||||
let base_dirs = directories::BaseDirs::new().ok_or(ErrorKind::NoBaseDirectories)?;
|
let base_dirs = directories::BaseDirs::new().ok_or(ErrorKind::NoBaseDirectories)?;
|
||||||
let config = Config::load(&base_dirs)?;
|
let config = Config::load(&base_dirs)?;
|
||||||
|
terminal::set_title(config.set_title());
|
||||||
|
|
||||||
if config.edit_config() {
|
if config.edit_config() {
|
||||||
Config::edit(&base_dirs)?;
|
Config::edit(&base_dirs)?;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ struct Terminal {
|
|||||||
width: Option<u16>,
|
width: Option<u16>,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
term: Term,
|
term: Term,
|
||||||
|
set_title: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Terminal {
|
impl Terminal {
|
||||||
@@ -42,12 +43,19 @@ impl Terminal {
|
|||||||
prefix: env::var("TOPGRADE_PREFIX")
|
prefix: env::var("TOPGRADE_PREFIX")
|
||||||
.map(|prefix| format!("({}) ", prefix))
|
.map(|prefix| format!("({}) ", prefix))
|
||||||
.unwrap_or_else(|_| String::new()),
|
.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) {
|
fn print_separator<P: AsRef<str>>(&mut self, message: P) {
|
||||||
self.term
|
if self.set_title {
|
||||||
.set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref()));
|
self.term
|
||||||
|
.set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref()));
|
||||||
|
}
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
let message = format!(
|
let message = format!(
|
||||||
"{}{:02}:{:02}:{:02} - {}",
|
"{}{:02}:{:02}:{:02} - {}",
|
||||||
@@ -121,7 +129,9 @@ impl Terminal {
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.term.set_title("Topgrade - Awaiting user");
|
if self.set_title {
|
||||||
|
self.term.set_title("Topgrade - Awaiting user");
|
||||||
|
}
|
||||||
self.term
|
self.term
|
||||||
.write_fmt(format_args!(
|
.write_fmt(format_args!(
|
||||||
"\n{}",
|
"\n{}",
|
||||||
@@ -198,3 +208,7 @@ pub fn is_dumb() -> bool {
|
|||||||
pub fn get_char() -> char {
|
pub fn get_char() -> char {
|
||||||
TERMINAL.lock().unwrap().get_char().unwrap()
|
TERMINAL.lock().unwrap().get_char().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_title(set_title: bool) {
|
||||||
|
TERMINAL.lock().unwrap().set_title(set_title);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user