From 504d79121ddec7b3664bbf4b5f969bb180e0b2d9 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Sun, 3 Jun 2018 16:43:53 +0300 Subject: [PATCH] Display warnings in color (fix #6) --- src/main.rs | 8 +++++--- src/terminal.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1217d54b..cd23059a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,9 +141,9 @@ fn run() -> Result<()> { if cfg!(target_os = "linux") { let sudo = which("sudo"); + terminal.print_separator("System update"); match os_type::current_platform().os_type { OSType::Arch => { - terminal.print_separator("System update"); if let Ok(yay) = which("yay") { Command::new(yay).spawn()?.wait()?; } else { @@ -153,6 +153,8 @@ fn run() -> Result<()> { .arg("-Syu") .spawn()? .wait()?; + } else { + terminal.print_warning("No sudo or yay detected. Skipping system upgrade"); } } } @@ -185,8 +187,8 @@ fn run() -> Result<()> { } OSType::Unknown => { - println!( - "Could not detect your Linux distribution. Do you have lsb-release installed?" + terminal.print_warning( + "Could not detect your Linux distribution. Do you have lsb-release installed?", ); } diff --git a/src/terminal.rs b/src/terminal.rs index 1b883971..d4430dfb 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -26,4 +26,15 @@ impl Terminal { println!("―― {} ――", message); } } + + pub fn print_warning>(&self, message: P) { + if let Some(_) = self.width { + println!( + "{}{}{}", + color::Fg(color::LightYellow), + message.as_ref(), + color::Fg(color::Reset) + ); + } + } }