Display warnings in color (fix #6)

This commit is contained in:
Roey Darwish Dror
2018-06-03 16:43:53 +03:00
parent 8de74a64d4
commit 504d79121d
2 changed files with 16 additions and 3 deletions

View File

@@ -141,9 +141,9 @@ fn run() -> Result<()> {
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
let sudo = which("sudo"); let sudo = which("sudo");
terminal.print_separator("System update");
match os_type::current_platform().os_type { match os_type::current_platform().os_type {
OSType::Arch => { OSType::Arch => {
terminal.print_separator("System update");
if let Ok(yay) = which("yay") { if let Ok(yay) = which("yay") {
Command::new(yay).spawn()?.wait()?; Command::new(yay).spawn()?.wait()?;
} else { } else {
@@ -153,6 +153,8 @@ fn run() -> Result<()> {
.arg("-Syu") .arg("-Syu")
.spawn()? .spawn()?
.wait()?; .wait()?;
} else {
terminal.print_warning("No sudo or yay detected. Skipping system upgrade");
} }
} }
} }
@@ -185,8 +187,8 @@ fn run() -> Result<()> {
} }
OSType::Unknown => { OSType::Unknown => {
println!( terminal.print_warning(
"Could not detect your Linux distribution. Do you have lsb-release installed?" "Could not detect your Linux distribution. Do you have lsb-release installed?",
); );
} }

View File

@@ -26,4 +26,15 @@ impl Terminal {
println!("―― {} ――", message); println!("―― {} ――", message);
} }
} }
pub fn print_warning<P: AsRef<str>>(&self, message: P) {
if let Some(_) = self.width {
println!(
"{}{}{}",
color::Fg(color::LightYellow),
message.as_ref(),
color::Fg(color::Reset)
);
}
}
} }