Remove progress bar and add a true counter
This commit is contained in:
parent
97f6f141ee
commit
27943bead6
@ -6,7 +6,7 @@
|
||||
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();
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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 @@ pub fn new(len: u64) -> 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 @@ pub fn tick(&mut self) {
|
||||
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 @@ fn set_value(&mut self, value: f32) {
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
print!("{}", "\x08".repeat(self.text.len()));
|
||||
print!("{}{}", " ".repeat(self.text.len()), "\x08".repeat(self.text.len()));
|
||||
self.text = String::new();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user