diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 122aa05523..9b1802a5fc 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -6,7 +6,7 @@ use ra_db::SourceDatabaseExt; use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk}; use ra_syntax::AstNode; -use crate::{progress_bar::ProgressBar, Result, Verbosity}; +use crate::{progress_report::ProgressReport, Result, Verbosity}; pub fn run( verbosity: Verbosity, @@ -76,8 +76,8 @@ pub fn run( let inference_time = Instant::now(); let mut bar = match verbosity { - Verbosity::Verbose | Verbosity::Normal => ProgressBar::new(funcs.len() as u64), - Verbosity::Quiet => ProgressBar::hidden(), + Verbosity::Verbose | Verbosity::Normal => ProgressReport::new(funcs.len() as u64), + Verbosity::Quiet => ProgressReport::hidden(), }; bar.tick(); diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index c23d92ec2e..08f3531477 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -3,7 +3,7 @@ mod analysis_stats; mod analysis_bench; mod help; -mod progress_bar; +mod progress_report; use std::{error::Error, fmt::Write, io::Read}; diff --git a/crates/ra_cli/src/progress_bar.rs b/crates/ra_cli/src/progress_report.rs similarity index 77% rename from crates/ra_cli/src/progress_bar.rs rename to crates/ra_cli/src/progress_report.rs index 95bfcf4d0a..6ce0d4cab7 100644 --- a/crates/ra_cli/src/progress_bar.rs +++ b/crates/ra_cli/src/progress_report.rs @@ -4,10 +4,9 @@ use std::io::Write; /// A Simple ASCII Progress Bar -pub struct ProgressBar { +pub struct ProgressReport { curr: f32, text: String, - anim: usize, hidden: bool, len: u64, @@ -15,15 +14,11 @@ pub struct ProgressBar { msg: String, } -impl ProgressBar { - const ANIMATION: &'static str = r#"|/-\"#; - const BLOCK_COUNT: usize = 20; - - pub fn new(len: u64) -> ProgressBar { - ProgressBar { +impl ProgressReport { + pub fn new(len: u64) -> ProgressReport { + ProgressReport { curr: 0.0, text: String::new(), - anim: 0, hidden: false, len, pos: 0, @@ -31,11 +26,10 @@ impl ProgressBar { } } - pub fn hidden() -> ProgressBar { - ProgressBar { + pub fn hidden() -> ProgressReport { + ProgressReport { curr: 0.0, text: String::new(), - anim: 0, hidden: true, len: 0, pos: 0, @@ -72,19 +66,8 @@ impl ProgressBar { if self.hidden { return; } - - let progress_block: usize = (self.curr * Self::BLOCK_COUNT as f32) as usize; let percent = (self.curr * 100.0) as u32; - let text = format!( - "[{}{}] {:3>}% {} {}", - "#".repeat(progress_block), - "-".repeat(Self::BLOCK_COUNT - progress_block), - percent, - Self::ANIMATION.chars().nth(self.anim).unwrap(), - self.msg, - ); - - self.anim = (self.anim + 1) % Self::ANIMATION.len(); + let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg); self.update_text(&text); } @@ -124,7 +107,7 @@ impl ProgressBar { } fn clear(&mut self) { - print!("{}", "\x08".repeat(self.text.len())); + print!("{}{}", " ".repeat(self.text.len()), "\x08".repeat(self.text.len())); self.text = String::new(); } }