From af2c477a04dd7980327b6b0c506c912361216827 Mon Sep 17 00:00:00 2001 From: lukasprobst Date: Thu, 15 Apr 2021 23:37:36 +0200 Subject: [PATCH] Add the dependency 'colored' and color relevant messages --- Cargo.toml | 1 + src/main.rs | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e26e4af..e0cc546 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,4 @@ rpassword = "5.0.0" rprompt = "1.0.5" ignore = "0.4.14" anyhow = "1.0.28" +colored = "2.0.0" diff --git a/src/main.rs b/src/main.rs index 571e6c9..f777c90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use colored::Colorize; use anyhow::{Context, Result, anyhow}; use futures::future::{self, Either}; use futures_channel::mpsc::UnboundedSender; @@ -45,7 +46,7 @@ async fn main() { opt.output.push(".iliasignore"); let (ignore, error) = Gitignore::new(&opt.output); if let Some(err) = error { - println!("Warning: .iliasignore error: {}", err); + println!("Warning: {} {}", ".iliasignore error:".bright_yellow(), err.to_string().bright_yellow()); } opt.output.pop(); // loac .iliaslogin file @@ -60,7 +61,7 @@ async fn main() { let pass = pass.unwrap().trim(); (user.to_owned(), pass.to_owned()) } else { - println!("Warning: .iliaslogin incomplete"); + println!("Warning: {}", ".iliaslogin incomplete".bright_yellow()); ask_user_pass() } } else { @@ -70,15 +71,15 @@ async fn main() { let ilias = match ILIAS::login(opt, user, pass, ignore).await { Ok(ilias) => ilias, - Err(e) => { - print!("{:?}", e); + Err(e) =>{ + println!("Error: {}", format!("{:?}", e).bright_red()); std::process::exit(77); } }; if ilias.opt.content_tree { // need this to get the content tree if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").send().await { - println!("Warning: could not enable content tree: {:?}", e); + println!("Warning: {} {}", "could not enable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); } } let ilias = Arc::new(ilias); @@ -106,7 +107,7 @@ async fn main() { if ilias.opt.content_tree { // restore fast page loading times if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").send().await { - println!("Warning: could not disable content tree: {:?}", e); + println!("Warning: {} {}", "could not disable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); } } } @@ -143,14 +144,14 @@ fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Fut } let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { - println!("Syncing {}: {:?}", path_text, e); + println!("Syncing {}: {:?}", path_text, format!("{:?}", e).bright_red()); } *TASKS_RUNNING.lock() -= 1; }} async fn handle_gracefully(fut: impl Future>) { if let Err(e) = fut.await { - println!("Error: {:?}", e); + println!("Error: {}", format!("{:?}", e).bright_red()); } } @@ -221,7 +222,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future()? { - log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy()); + log!(0, "Warning: {} {}", relative_path.to_string_lossy().bright_yellow(), "was updated, consider moving the outdated file".bright_yellow()); } } } else { @@ -397,7 +398,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future>(); if cells.len() != 6 { - log!(0, "Warning: unusual table row ({} cells) in {}", cells.len(), url); + log!(0, "Warning: {}{} {} {}", "unusual table row (".bright_yellow(), cells.len().to_string().bright_yellow(), "cells) in".bright_yellow(), url.to_string().bright_yellow()); continue; } let link = cells[1].select(&a).next().context("thread link not found")?; @@ -476,7 +477,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future Result {