aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs6
-rw-r--r--crates/ra_cli/src/main.rs2
-rw-r--r--crates/ra_cli/src/progress_report.rs (renamed from crates/ra_cli/src/progress_bar.rs)33
3 files changed, 12 insertions, 29 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 122aa0552..9b1802a5f 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;
6use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk}; 6use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk};
7use ra_syntax::AstNode; 7use ra_syntax::AstNode;
8 8
9use crate::{progress_bar::ProgressBar, Result, Verbosity}; 9use crate::{progress_report::ProgressReport, Result, Verbosity};
10 10
11pub fn run( 11pub fn run(
12 verbosity: Verbosity, 12 verbosity: Verbosity,
@@ -76,8 +76,8 @@ pub fn run(
76 76
77 let inference_time = Instant::now(); 77 let inference_time = Instant::now();
78 let mut bar = match verbosity { 78 let mut bar = match verbosity {
79 Verbosity::Verbose | Verbosity::Normal => ProgressBar::new(funcs.len() as u64), 79 Verbosity::Verbose | Verbosity::Normal => ProgressReport::new(funcs.len() as u64),
80 Verbosity::Quiet => ProgressBar::hidden(), 80 Verbosity::Quiet => ProgressReport::hidden(),
81 }; 81 };
82 82
83 bar.tick(); 83 bar.tick();
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index c23d92ec2..08f353147 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -3,7 +3,7 @@
3mod analysis_stats; 3mod analysis_stats;
4mod analysis_bench; 4mod analysis_bench;
5mod help; 5mod help;
6mod progress_bar; 6mod progress_report;
7 7
8use std::{error::Error, fmt::Write, io::Read}; 8use std::{error::Error, fmt::Write, io::Read};
9 9
diff --git a/crates/ra_cli/src/progress_bar.rs b/crates/ra_cli/src/progress_report.rs
index 95bfcf4d0..6ce0d4cab 100644
--- a/crates/ra_cli/src/progress_bar.rs
+++ b/crates/ra_cli/src/progress_report.rs
@@ -4,10 +4,9 @@
4use std::io::Write; 4use std::io::Write;
5 5
6/// A Simple ASCII Progress Bar 6/// A Simple ASCII Progress Bar
7pub struct ProgressBar { 7pub struct ProgressReport {
8 curr: f32, 8 curr: f32,
9 text: String, 9 text: String,
10 anim: usize,
11 hidden: bool, 10 hidden: bool,
12 11
13 len: u64, 12 len: u64,
@@ -15,15 +14,11 @@ pub struct ProgressBar {
15 msg: String, 14 msg: String,
16} 15}
17 16
18impl ProgressBar { 17impl ProgressReport {
19 const ANIMATION: &'static str = r#"|/-\"#; 18 pub fn new(len: u64) -> ProgressReport {
20 const BLOCK_COUNT: usize = 20; 19 ProgressReport {
21
22 pub fn new(len: u64) -> ProgressBar {
23 ProgressBar {
24 curr: 0.0, 20 curr: 0.0,
25 text: String::new(), 21 text: String::new(),
26 anim: 0,
27 hidden: false, 22 hidden: false,
28 len, 23 len,
29 pos: 0, 24 pos: 0,
@@ -31,11 +26,10 @@ impl ProgressBar {
31 } 26 }
32 } 27 }
33 28
34 pub fn hidden() -> ProgressBar { 29 pub fn hidden() -> ProgressReport {
35 ProgressBar { 30 ProgressReport {
36 curr: 0.0, 31 curr: 0.0,
37 text: String::new(), 32 text: String::new(),
38 anim: 0,
39 hidden: true, 33 hidden: true,
40 len: 0, 34 len: 0,
41 pos: 0, 35 pos: 0,
@@ -72,19 +66,8 @@ impl ProgressBar {
72 if self.hidden { 66 if self.hidden {
73 return; 67 return;
74 } 68 }
75
76 let progress_block: usize = (self.curr * Self::BLOCK_COUNT as f32) as usize;
77 let percent = (self.curr * 100.0) as u32; 69 let percent = (self.curr * 100.0) as u32;
78 let text = format!( 70 let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg);
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();
88 self.update_text(&text); 71 self.update_text(&text);
89 } 72 }
90 73
@@ -124,7 +107,7 @@ impl ProgressBar {
124 } 107 }
125 108
126 fn clear(&mut self) { 109 fn clear(&mut self) {
127 print!("{}", "\x08".repeat(self.text.len())); 110 print!("{}{}", " ".repeat(self.text.len()), "\x08".repeat(self.text.len()));
128 self.text = String::new(); 111 self.text = String::new();
129 } 112 }
130} 113}