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_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk};
|
||||||
use ra_syntax::AstNode;
|
use ra_syntax::AstNode;
|
||||||
|
|
||||||
use crate::{progress_bar::ProgressBar, Result, Verbosity};
|
use crate::{progress_report::ProgressReport, Result, Verbosity};
|
||||||
|
|
||||||
pub fn run(
|
pub fn run(
|
||||||
verbosity: Verbosity,
|
verbosity: Verbosity,
|
||||||
@ -76,8 +76,8 @@ pub fn run(
|
|||||||
|
|
||||||
let inference_time = Instant::now();
|
let inference_time = Instant::now();
|
||||||
let mut bar = match verbosity {
|
let mut bar = match verbosity {
|
||||||
Verbosity::Verbose | Verbosity::Normal => ProgressBar::new(funcs.len() as u64),
|
Verbosity::Verbose | Verbosity::Normal => ProgressReport::new(funcs.len() as u64),
|
||||||
Verbosity::Quiet => ProgressBar::hidden(),
|
Verbosity::Quiet => ProgressReport::hidden(),
|
||||||
};
|
};
|
||||||
|
|
||||||
bar.tick();
|
bar.tick();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
mod analysis_stats;
|
mod analysis_stats;
|
||||||
mod analysis_bench;
|
mod analysis_bench;
|
||||||
mod help;
|
mod help;
|
||||||
mod progress_bar;
|
mod progress_report;
|
||||||
|
|
||||||
use std::{error::Error, fmt::Write, io::Read};
|
use std::{error::Error, fmt::Write, io::Read};
|
||||||
|
|
||||||
|
@ -4,10 +4,9 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
/// A Simple ASCII Progress Bar
|
/// A Simple ASCII Progress Bar
|
||||||
pub struct ProgressBar {
|
pub struct ProgressReport {
|
||||||
curr: f32,
|
curr: f32,
|
||||||
text: String,
|
text: String,
|
||||||
anim: usize,
|
|
||||||
hidden: bool,
|
hidden: bool,
|
||||||
|
|
||||||
len: u64,
|
len: u64,
|
||||||
@ -15,15 +14,11 @@ pub struct ProgressBar {
|
|||||||
msg: String,
|
msg: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl ProgressReport {
|
||||||
const ANIMATION: &'static str = r#"|/-\"#;
|
pub fn new(len: u64) -> ProgressReport {
|
||||||
const BLOCK_COUNT: usize = 20;
|
ProgressReport {
|
||||||
|
|
||||||
pub fn new(len: u64) -> ProgressBar {
|
|
||||||
ProgressBar {
|
|
||||||
curr: 0.0,
|
curr: 0.0,
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
anim: 0,
|
|
||||||
hidden: false,
|
hidden: false,
|
||||||
len,
|
len,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
@ -31,11 +26,10 @@ pub fn new(len: u64) -> ProgressBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hidden() -> ProgressBar {
|
pub fn hidden() -> ProgressReport {
|
||||||
ProgressBar {
|
ProgressReport {
|
||||||
curr: 0.0,
|
curr: 0.0,
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
anim: 0,
|
|
||||||
hidden: true,
|
hidden: true,
|
||||||
len: 0,
|
len: 0,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
@ -72,19 +66,8 @@ pub fn tick(&mut self) {
|
|||||||
if self.hidden {
|
if self.hidden {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let progress_block: usize = (self.curr * Self::BLOCK_COUNT as f32) as usize;
|
|
||||||
let percent = (self.curr * 100.0) as u32;
|
let percent = (self.curr * 100.0) as u32;
|
||||||
let text = format!(
|
let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg);
|
||||||
"[{}{}] {: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();
|
|
||||||
self.update_text(&text);
|
self.update_text(&text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +107,7 @@ fn set_value(&mut self, value: f32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
print!("{}", "\x08".repeat(self.text.len()));
|
print!("{}{}", " ".repeat(self.text.len()), "\x08".repeat(self.text.len()));
|
||||||
self.text = String::new();
|
self.text = String::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user