From c0e3daacaf6850811df5bc57fa43e0f249d5cfa4 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sun, 18 Apr 2021 15:37:41 +0200 Subject: [PATCH 1/3] feat(list): added progress info Added a progress info at the bottom of the list for command: rustlings list closes #705 --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 569aa4a..7364723 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,13 +138,19 @@ fn main() { println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status"); } let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase(); + let mut exercises_done: u16 = 0; exercises.iter().for_each(|e| { let fname = format!("{}", e.path.display()); let filter_cond = filters .split(',') .filter(|f| !f.trim().is_empty()) .any(|f| e.name.contains(&f) || fname.contains(&f)); - let status = if e.looks_done() { "Done" } else { "Pending" }; + let status = if e.looks_done() { + exercises_done = exercises_done + 1; + "Done" + } else { + "Pending" + }; let solve_cond = { (e.looks_done() && list_m.is_present("solved")) || (!e.looks_done() && list_m.is_present("unsolved")) @@ -173,6 +179,13 @@ fn main() { } } }); + let percentage_progress = exercises_done as f32 / exercises.len() as f32; + println!( + "Progress: You completed {} / {} exercises ({:.2} %).", + exercises_done, + exercises.len(), + percentage_progress + ); std::process::exit(0); } @@ -314,7 +327,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { .chain( exercises .iter() - .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)) + .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)), ); clear_screen(); match verify(pending_exercises, verbose) { From bd48544e25bb58f86fee1b1a5004e961996a3388 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sun, 18 Apr 2021 15:40:47 +0200 Subject: [PATCH 2/3] style: formatted files with rustfmt --- src/exercise.rs | 5 ++--- src/ui.rs | 16 ++++------------ src/verify.rs | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 3d2e38d..e9d1c1c 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -1,6 +1,6 @@ -use std::env; use regex::Regex; use serde::Deserialize; +use std::env; use std::fmt::{self, Display, Formatter}; use std::fs::{self, remove_file, File}; use std::io::Read; @@ -132,8 +132,7 @@ path = "{}.rs""#, } else { "Failed to write 📎 Clippy 📎 Cargo.toml file." }; - fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml) - .expect(cargo_toml_error_msg); + fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml).expect(cargo_toml_error_msg); // To support the ability to run the clipy exercises, build // an executable, in addition to running clippy. With a // compilation failure, this would silently fail. But we expect diff --git a/src/ui.rs b/src/ui.rs index cb07337..1ee4631 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,14 +1,10 @@ macro_rules! warn { ($fmt:literal, $ex:expr) => {{ - use std::env; use console::{style, Emoji}; + use std::env; let formatstr = format!($fmt, $ex); if env::var("NO_EMOJI").is_ok() { - println!( - "{} {}", - style("!").red(), - style(formatstr).red() - ); + println!("{} {}", style("!").red(), style(formatstr).red()); } else { println!( "{} {}", @@ -21,15 +17,11 @@ macro_rules! warn { macro_rules! success { ($fmt:literal, $ex:expr) => {{ - use std::env; use console::{style, Emoji}; + use std::env; let formatstr = format!($fmt, $ex); if env::var("NO_EMOJI").is_ok() { - println!( - "{} {}", - style("✓").green(), - style(formatstr).green() - ); + println!("{} {}", style("✓").green(), style(formatstr).green()); } else { println!( "{} {}", diff --git a/src/verify.rs b/src/verify.rs index 7a0e9cc..b98598a 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,7 +1,7 @@ -use std::env; use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; use indicatif::ProgressBar; +use std::env; // Verify that the provided container of Exercise objects // can be compiled and run without any failures. From 1c6f7e4b7b9b3bd36f4da2bb2b69c549cc8bd913 Mon Sep 17 00:00:00 2001 From: Patrick Hintermayer Date: Mon, 19 Apr 2021 09:39:05 +0200 Subject: [PATCH 3/3] feat(list): updated progress percentage --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7364723..3b7a194 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,7 +179,7 @@ fn main() { } } }); - let percentage_progress = exercises_done as f32 / exercises.len() as f32; + let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0; println!( "Progress: You completed {} / {} exercises ({:.2} %).", exercises_done,