From 5b6924569709784282e4bf3a3454f5c85efc47f8 Mon Sep 17 00:00:00 2001 From: Teascade Date: Mon, 16 Apr 2018 21:25:46 +0300 Subject: [PATCH] Add ansi_term for colorful displays! --- Cargo.lock | 1 + Cargo.toml | 1 + src/logger.rs | 12 +++++++----- src/main.rs | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85ee2f0..aa82390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,6 +192,7 @@ dependencies = [ name = "teascade-generator" version = "0.1.0" dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 550ba70..5bc88d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ structopt = "*" serde = "*" serde_derive = "*" regex = "*" +ansi_term = "*" \ No newline at end of file diff --git a/src/logger.rs b/src/logger.rs index 74a3661..acb9f4c 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,3 +1,5 @@ +use ansi_term::Color::{Blue, Cyan, Red, Yellow}; + pub struct Logger { log_level: LogLevel, } @@ -11,11 +13,11 @@ impl Logger { if self.log_level.clone() as i32 >= log_level.clone() as i32 { match log_level { LogLevel::QUIET => (), - LogLevel::SEVERE => eprintln!("[SEVERE]: {}", message.into()), - LogLevel::INFO => println!("[INFO]: {}", message.into()), - LogLevel::WARNING => eprintln!("[WARNING]: {}", message.into()), - LogLevel::DETAIL => println!("[DETAIL]: {}", message.into()), - LogLevel::DETAILER => println!("[DETAILER]: {}", message.into()), + LogLevel::SEVERE => eprintln!("{}: {}", Red.paint("[SEVERE]"), message.into()), + LogLevel::INFO => println!("{}: {}", Cyan.paint("[INFO]"), message.into()), + LogLevel::WARNING => println!("{}: {}", Yellow.paint("[WARNING]"), message.into()), + LogLevel::DETAIL => println!("{}: {}", Blue.paint("[DETAIL]"), message.into()), + LogLevel::DETAILER => println!("{}: {}", Blue.paint("[DETAILER]"), message.into()), } } } diff --git a/src/main.rs b/src/main.rs index 4a44bfd..697ea5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +extern crate ansi_term; extern crate pulldown_cmark; extern crate regex; #[macro_use]