aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock26
-rw-r--r--crates/ra_cli/Cargo.toml1
-rw-r--r--crates/ra_cli/src/analysis_stats.rs17
-rw-r--r--crates/ra_cli/src/main.rs1
-rw-r--r--crates/ra_cli/src/progress_bar.rs130
5 files changed, 138 insertions, 37 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1c6161504..f751be2e3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -226,7 +226,6 @@ dependencies = [
226 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 226 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
227 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 227 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
228 "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 228 "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
229 "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
230 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 229 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
231] 230]
232 231
@@ -473,17 +472,6 @@ dependencies = [
473] 472]
474 473
475[[package]] 474[[package]]
476name = "indicatif"
477version = "0.13.0"
478source = "registry+https://github.com/rust-lang/crates.io-index"
479dependencies = [
480 "console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
481 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
482 "number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
483 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
484]
485
486[[package]]
487name = "inotify" 475name = "inotify"
488version = "0.6.1" 476version = "0.6.1"
489source = "registry+https://github.com/rust-lang/crates.io-index" 477source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -760,11 +748,6 @@ dependencies = [
760] 748]
761 749
762[[package]] 750[[package]]
763name = "number_prefix"
764version = "0.3.0"
765source = "registry+https://github.com/rust-lang/crates.io-index"
766
767[[package]]
768name = "once_cell" 751name = "once_cell"
769version = "1.2.0" 752version = "1.2.0"
770source = "registry+https://github.com/rust-lang/crates.io-index" 753source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -945,7 +928,6 @@ name = "ra_cli"
945version = "0.1.0" 928version = "0.1.0"
946dependencies = [ 929dependencies = [
947 "flexi_logger 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)", 930 "flexi_logger 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
948 "indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
949 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 931 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
950 "ra_batch 0.1.0", 932 "ra_batch 0.1.0",
951 "ra_db 0.1.0", 933 "ra_db 0.1.0",
@@ -1719,11 +1701,6 @@ version = "1.6.0"
1719source = "registry+https://github.com/rust-lang/crates.io-index" 1701source = "registry+https://github.com/rust-lang/crates.io-index"
1720 1702
1721[[package]] 1703[[package]]
1722name = "unicode-width"
1723version = "0.1.6"
1724source = "registry+https://github.com/rust-lang/crates.io-index"
1725
1726[[package]]
1727name = "unicode-xid" 1704name = "unicode-xid"
1728version = "0.2.0" 1705version = "0.2.0"
1729source = "registry+https://github.com/rust-lang/crates.io-index" 1706source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1899,7 +1876,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1899"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" 1876"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120"
1900"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" 1877"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
1901"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" 1878"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
1902"checksum indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8572bccfb0665e70b7faf44ee28841b8e0823450cd4ad562a76b5a3c4bf48487"
1903"checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" 1879"checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718"
1904"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" 1880"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
1905"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349" 1881"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349"
@@ -1932,7 +1908,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1932"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" 1908"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
1933"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" 1909"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4"
1934"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" 1910"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
1935"checksum number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a"
1936"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" 1911"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
1937"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" 1912"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
1938"checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" 1913"checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc"
@@ -2008,7 +1983,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2008"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 1983"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
2009"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" 1984"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf"
2010"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" 1985"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
2011"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
2012"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" 1986"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
2013"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" 1987"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
2014"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" 1988"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index c9d3bdb77..3bb475997 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -8,7 +8,6 @@ publish = false
8[dependencies] 8[dependencies]
9pico-args = "0.3.0" 9pico-args = "0.3.0"
10flexi_logger = "0.14.0" 10flexi_logger = "0.14.0"
11indicatif = "0.13.0"
12 11
13ra_syntax = { path = "../ra_syntax" } 12ra_syntax = { path = "../ra_syntax" }
14ra_ide_api = { path = "../ra_ide_api" } 13ra_ide_api = { path = "../ra_ide_api" }
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index c4eb28245..8bf3863bb 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::{Result, Verbosity}; 9use crate::{progress_bar::ProgressBar, Result, Verbosity};
10 10
11pub fn run( 11pub fn run(
12 verbosity: Verbosity, 12 verbosity: Verbosity,
@@ -75,17 +75,14 @@ pub fn run(
75 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 75 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
76 76
77 let inference_time = Instant::now(); 77 let inference_time = Instant::now();
78 let bar = match verbosity { 78 let mut bar = match verbosity {
79 Verbosity::Verbose | Verbosity::Normal => indicatif::ProgressBar::with_draw_target( 79 Verbosity::Verbose | Verbosity::Normal => ProgressBar::new(funcs.len() as u64),
80 funcs.len() as u64, 80 Verbosity::Quiet => ProgressBar::hidden(),
81 indicatif::ProgressDrawTarget::stderr_nohz(),
82 ),
83 Verbosity::Quiet => indicatif::ProgressBar::hidden(),
84 }; 81 };
85 82
86 bar.set_style( 83 // bar.set_style(
87 indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"), 84 // indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"),
88 ); 85 // );
89 bar.tick(); 86 bar.tick();
90 let mut num_exprs = 0; 87 let mut num_exprs = 0;
91 let mut num_exprs_unknown = 0; 88 let mut num_exprs_unknown = 0;
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index a31fd5d6a..c23d92ec2 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -3,6 +3,7 @@
3mod analysis_stats; 3mod analysis_stats;
4mod analysis_bench; 4mod analysis_bench;
5mod help; 5mod help;
6mod progress_bar;
6 7
7use std::{error::Error, fmt::Write, io::Read}; 8use std::{error::Error, fmt::Write, io::Read};
8 9
diff --git a/crates/ra_cli/src/progress_bar.rs b/crates/ra_cli/src/progress_bar.rs
new file mode 100644
index 000000000..95bfcf4d0
--- /dev/null
+++ b/crates/ra_cli/src/progress_bar.rs
@@ -0,0 +1,130 @@
1//! A simple progress bar
2//!
3//! A single thread non-optimized progress bar
4use std::io::Write;
5
6/// A Simple ASCII Progress Bar
7pub struct ProgressBar {
8 curr: f32,
9 text: String,
10 anim: usize,
11 hidden: bool,
12
13 len: u64,
14 pos: u64,
15 msg: String,
16}
17
18impl ProgressBar {
19 const ANIMATION: &'static str = r#"|/-\"#;
20 const BLOCK_COUNT: usize = 20;
21
22 pub fn new(len: u64) -> ProgressBar {
23 ProgressBar {
24 curr: 0.0,
25 text: String::new(),
26 anim: 0,
27 hidden: false,
28 len,
29 pos: 0,
30 msg: String::new(),
31 }
32 }
33
34 pub fn hidden() -> ProgressBar {
35 ProgressBar {
36 curr: 0.0,
37 text: String::new(),
38 anim: 0,
39 hidden: true,
40 len: 0,
41 pos: 0,
42 msg: String::new(),
43 }
44 }
45
46 pub fn set_message(&mut self, msg: &str) {
47 self.msg = msg.to_string();
48 self.tick();
49 }
50
51 pub fn println<I: Into<String>>(&mut self, msg: I) {
52 self.clear();
53 println!("{}", msg.into());
54 self.tick();
55 }
56
57 pub fn inc(&mut self, delta: u64) {
58 self.pos += delta;
59 if self.len == 0 {
60 self.set_value(0.0)
61 } else {
62 self.set_value((self.pos as f32) / (self.len as f32))
63 }
64 self.tick();
65 }
66
67 pub fn finish_and_clear(&mut self) {
68 self.clear();
69 }
70
71 pub fn tick(&mut self) {
72 if self.hidden {
73 return;
74 }
75
76 let progress_block: usize = (self.curr * Self::BLOCK_COUNT as f32) as usize;
77 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();
88 self.update_text(&text);
89 }
90
91 fn update_text(&mut self, text: &str) {
92 // Get length of common portion
93 let mut common_prefix_length = 0;
94 let common_length = usize::min(self.text.len(), text.len());
95
96 while common_prefix_length < common_length
97 && text.chars().nth(common_prefix_length).unwrap()
98 == self.text.chars().nth(common_prefix_length).unwrap()
99 {
100 common_prefix_length += 1;
101 }
102
103 // Backtrack to the first differing character
104 let mut output = String::new();
105 output += &'\x08'.to_string().repeat(self.text.len() - common_prefix_length);
106 // Output new suffix
107 output += &text[common_prefix_length..text.len()];
108
109 // If the new text is shorter than the old one: delete overlapping characters
110 if let Some(overlap_count) = self.text.len().checked_sub(text.len()) {
111 if overlap_count > 0 {
112 output += &" ".repeat(overlap_count);
113 output += &"\x08".repeat(overlap_count);
114 }
115 }
116
117 let _ = std::io::stdout().write(output.as_bytes());
118 let _ = std::io::stdout().flush();
119 self.text = text.to_string();
120 }
121
122 fn set_value(&mut self, value: f32) {
123 self.curr = f32::max(0.0, f32::min(1.0, value));
124 }
125
126 fn clear(&mut self) {
127 print!("{}", "\x08".repeat(self.text.len()));
128 self.text = String::new();
129 }
130}