feat(cli): adding colors in list command

This commit is contained in:
dusartvict 2022-01-23 16:58:37 +01:00
parent 5002c54ffb
commit eccdc5bdf8
3 changed files with 21 additions and 1 deletions

12
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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.