Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Use the upstream's set console title
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Aug 26, 2019
1 parent 21513f9 commit f6d761d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 64 deletions.
69 changes: 33 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ shellexpand = "1.0.0"
structopt = "0.2.16"
log = "0.4.6"
walkdir = "2.2.7"
console = "0.7.5"
console = "0.8.0"
self_update_crate = { version = "0.6.0", optional = true, package = "self_update" }
lazy_static = "1.3.0"
rust-ini = "0.13.0"
Expand All @@ -37,9 +37,6 @@ glob = "0.3.0"
[target.'cfg(unix)'.dependencies]
nix = "0.15.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["wincon"] }

[profile.release]
lto = true

Expand Down
27 changes: 3 additions & 24 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ use console::{style, Term};
use lazy_static::lazy_static;
use std::cmp::{max, min};
use std::env;
#[cfg(windows)]
use std::ffi::OsStr;
use std::fmt::Display;
use std::io::{self, Write};
#[cfg(windows)]
use std::iter::once;
#[cfg(windows)]
use std::os::windows::ffi::OsStrExt;
use std::process::Command;
use std::sync::Mutex;
#[cfg(windows)]
use which_crate::which;
#[cfg(windows)]
use winapi::um::wincon::SetConsoleTitleW;

lazy_static! {
static ref TERMINAL: Mutex<Terminal> = Mutex::new(Terminal::new());
Expand Down Expand Up @@ -55,7 +46,8 @@ impl Terminal {
}

fn print_separator<P: AsRef<str>>(&mut self, message: P) {
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 message = format!(
"{}{:02}:{:02}:{:02} - {}",
Expand Down Expand Up @@ -129,7 +121,7 @@ impl Terminal {
return Ok(false);
}

set_title("Topgrade - Awaiting user");
self.term.set_title("Topgrade - Awaiting user");
self.term
.write_fmt(format_args!(
"\n{}",
Expand Down Expand Up @@ -206,16 +198,3 @@ pub fn is_dumb() -> bool {
pub fn get_char() -> char {
TERMINAL.lock().unwrap().get_char().unwrap()
}

#[cfg(unix)]
pub fn set_title<T: Display>(title: T) {
print!("\x1b]0;{}\x07", title);
}

#[cfg(windows)]
pub fn set_title<T: Display>(title: T) {
let buffer: Vec<u16> = OsStr::new(&format!("{}", title)).encode_wide().chain(once(0)).collect();
unsafe {
SetConsoleTitleW(buffer.as_ptr());
}
}

0 comments on commit f6d761d

Please sign in to comment.