diff --git a/Cargo.lock b/Cargo.lock index e536d1b7..cda872fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi 0.3.9", +] + [[package]] name = "console" version = "0.7.7" @@ -545,6 +556,7 @@ version = "4.6.0" dependencies = [ "argh", "assert_cmd", + "colored", "console 0.7.7", "glob", "indicatif", diff --git a/Cargo.toml b/Cargo.toml index 30032695..6dbf5f12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ notify = "4.0.15" toml = "0.4.10" regex = "1.1.6" serde = {version = "1.0.10", features = ["derive"]} +colored = "2.0" [[bin]] name = "rustlings" diff --git a/src/main.rs b/src/main.rs index 32e7bba2..4b5c7b16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use crate::exercise::{Exercise, ExerciseList}; use crate::run::run; use crate::verify::verify; use argh::FromArgs; +use colored::Colorize; use console::Emoji; use notify::DebouncedEvent; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; @@ -163,6 +164,7 @@ fn main() { } else { "Pending" }; + let line_color = if status == "Done" { "green" } else { "red" }; let solve_cond = { (e.looks_done() && subargs.solved) || (!e.looks_done() && subargs.unsolved) @@ -174,7 +176,12 @@ fn main() { } else if subargs.names { format!("{}\n", e.name) } else { - format!("{:<17}\t{:<46}\t{:<7}\n", e.name, fname, status) + format!( + "{:<17}\t{:<46}\t{:<7}\n", + e.name.color(line_color), + fname.color(line_color), + status.color(line_color) + ) }; // Somehow using println! leads to the binary panicking // when its output is piped.