Skip to content

Commit 27943be

Browse files
committed
Remove progress bar and add a true counter
1 parent 97f6f14 commit 27943be

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

crates/ra_cli/src/analysis_stats.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ra_db::SourceDatabaseExt;
66
use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk};
77
use ra_syntax::AstNode;
88

9-
use crate::{progress_bar::ProgressBar, Result, Verbosity};
9+
use crate::{progress_report::ProgressReport, Result, Verbosity};
1010

1111
pub fn run(
1212
verbosity: Verbosity,
@@ -76,8 +76,8 @@ pub fn run(
7676

7777
let inference_time = Instant::now();
7878
let mut bar = match verbosity {
79-
Verbosity::Verbose | Verbosity::Normal => ProgressBar::new(funcs.len() as u64),
80-
Verbosity::Quiet => ProgressBar::hidden(),
79+
Verbosity::Verbose | Verbosity::Normal => ProgressReport::new(funcs.len() as u64),
80+
Verbosity::Quiet => ProgressReport::hidden(),
8181
};
8282

8383
bar.tick();

crates/ra_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
mod analysis_stats;
44
mod analysis_bench;
55
mod help;
6-
mod progress_bar;
6+
mod progress_report;
77

88
use std::{error::Error, fmt::Write, io::Read};
99

crates/ra_cli/src/progress_bar.rs renamed to crates/ra_cli/src/progress_report.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,32 @@
44
use std::io::Write;
55

66
/// A Simple ASCII Progress Bar
7-
pub struct ProgressBar {
7+
pub struct ProgressReport {
88
curr: f32,
99
text: String,
10-
anim: usize,
1110
hidden: bool,
1211

1312
len: u64,
1413
pos: u64,
1514
msg: String,
1615
}
1716

18-
impl ProgressBar {
19-
const ANIMATION: &'static str = r#"|/-\"#;
20-
const BLOCK_COUNT: usize = 20;
21-
22-
pub fn new(len: u64) -> ProgressBar {
23-
ProgressBar {
17+
impl ProgressReport {
18+
pub fn new(len: u64) -> ProgressReport {
19+
ProgressReport {
2420
curr: 0.0,
2521
text: String::new(),
26-
anim: 0,
2722
hidden: false,
2823
len,
2924
pos: 0,
3025
msg: String::new(),
3126
}
3227
}
3328

34-
pub fn hidden() -> ProgressBar {
35-
ProgressBar {
29+
pub fn hidden() -> ProgressReport {
30+
ProgressReport {
3631
curr: 0.0,
3732
text: String::new(),
38-
anim: 0,
3933
hidden: true,
4034
len: 0,
4135
pos: 0,
@@ -72,19 +66,8 @@ impl ProgressBar {
7266
if self.hidden {
7367
return;
7468
}
75-
76-
let progress_block: usize = (self.curr * Self::BLOCK_COUNT as f32) as usize;
7769
let percent = (self.curr * 100.0) as u32;
78-
let text = format!(
79-
"[{}{}] {:3>}% {} {}",
80-
"#".repeat(progress_block),
81-
"-".repeat(Self::BLOCK_COUNT - progress_block),
82-
percent,
83-
Self::ANIMATION.chars().nth(self.anim).unwrap(),
84-
self.msg,
85-
);
86-
87-
self.anim = (self.anim + 1) % Self::ANIMATION.len();
70+
let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg);
8871
self.update_text(&text);
8972
}
9073

@@ -124,7 +107,7 @@ impl ProgressBar {
124107
}
125108

126109
fn clear(&mut self) {
127-
print!("{}", "\x08".repeat(self.text.len()));
110+
print!("{}{}", " ".repeat(self.text.len()), "\x08".repeat(self.text.len()));
128111
self.text = String::new();
129112
}
130113
}

0 commit comments

Comments
 (0)