diff --git a/Cargo.lock b/Cargo.lock index 23f52ca60..2d0c8a44e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,17 +466,6 @@ dependencies = [ "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "indicatif" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "console 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "is_executable" version = "0.1.2" @@ -909,18 +898,6 @@ dependencies = [ "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex" version = "1.1.0" @@ -933,14 +910,6 @@ dependencies = [ "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex-syntax" version = "0.6.4" @@ -1338,7 +1307,6 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1492,7 +1460,6 @@ dependencies = [ "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" -"checksum indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a29b2fa6f00010c268bface64c18bb0310aaa70d46a195d5382d288c477fb016" "checksum is_executable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" @@ -1544,9 +1511,7 @@ dependencies = [ "checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" "checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" diff --git a/Cargo.toml b/Cargo.toml index a03158857..2055028b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,6 @@ env_logger = { version = "0.5.13", default-features = false } failure = "0.1.2" human-panic = "1.0.1" glob = "0.2" -indicatif = "0.9.0" -lazy_static = "1.1.0" log = "0.4.6" openssl = { version = '0.10.11', optional = true } parking_lot = "0.6" @@ -39,6 +37,7 @@ walkdir = "2" [dev-dependencies] assert_cmd = "0.10.2" +lazy_static = "1.1.0" predicates = "1.0.0" tempfile = "3" diff --git a/src/command/build.rs b/src/command/build.rs index e68303012..681c75f98 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -7,7 +7,6 @@ use cache; use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use failure::Error; -use indicatif::HumanDuration; use license; use lockfile::Lockfile; use log::info; @@ -204,7 +203,7 @@ impl Build { step_counter.inc(); } - let duration = HumanDuration(started.elapsed()); + let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); info!( "Your wasm pkg is ready to publish at {}.", diff --git a/src/command/test.rs b/src/command/test.rs index f07d4a9fa..1e8808863 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -9,7 +9,6 @@ use command::utils::set_crate_path; use console::style; use emoji; use failure::Error; -use indicatif::HumanDuration; use lockfile::Lockfile; use log::info; use manifest; @@ -172,7 +171,7 @@ impl Test { process_step(&mut self, &step_counter)?; step_counter.inc(); } - let duration = HumanDuration(started.elapsed()); + let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); Ok(()) diff --git a/src/command/utils.rs b/src/command/utils.rs index f17111508..b9ce0a606 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -5,6 +5,7 @@ use failure; use progressbar::Step; use std::fs; use std::path::{Path, PathBuf}; +use std::time::Duration; use walkdir::WalkDir; use PBAR; @@ -39,3 +40,14 @@ pub fn find_pkg_directory(path: &Path) -> Option { fn is_pkg_directory(path: &Path) -> bool { path.exists() && path.is_dir() && path.ends_with("pkg") } + +/// Render a `Duration` to a form suitable for display on a console +pub fn elapsed(duration: Duration) -> String { + let secs = duration.as_secs(); + + if secs >= 60 { + format!("{}m {:02}s", secs / 60, secs % 60) + } else { + format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000) + } +} diff --git a/src/lib.rs b/src/lib.rs index 97b136feb..e8b7ceb68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,12 +8,9 @@ extern crate strsim; #[macro_use] extern crate failure; extern crate glob; -extern crate indicatif; -extern crate which; -#[macro_use] -extern crate lazy_static; extern crate parking_lot; extern crate serde; +extern crate which; #[macro_use] extern crate serde_derive; extern crate serde_ignored; @@ -43,10 +40,8 @@ pub mod test; use progressbar::ProgressOutput; -lazy_static! { - /// The global progress bar and user-facing message output. - pub static ref PBAR: ProgressOutput = { ProgressOutput::new() }; -} +/// The global progress bar and user-facing message output. +pub static PBAR: ProgressOutput = ProgressOutput; /// 📦 ✨ pack and publish your wasm! #[derive(Debug, StructOpt)] diff --git a/src/progressbar.rs b/src/progressbar.rs index f0c0e6a5c..c720cbae7 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -2,25 +2,12 @@ use console::style; use emoji; -use indicatif::{ProgressBar, ProgressStyle}; -use parking_lot::RwLock; use std::fmt; /// Synchronized progress bar and status message printing. -pub struct ProgressOutput { - spinner: RwLock, - messages: RwLock, -} +pub struct ProgressOutput; impl ProgressOutput { - /// Construct a new `ProgressOutput`. - pub fn new() -> Self { - Self { - spinner: RwLock::new(ProgressBar::new_spinner()), - messages: RwLock::new(String::from("")), - } - } - /// Inform the user that the given `step` is being executed, with details in /// `message`. pub fn step(&self, step: &Step, message: &str) { @@ -28,35 +15,13 @@ impl ProgressOutput { self.message(&msg) } - fn finish(&self) { - let spinner = self.spinner.read(); - spinner.finish(); - - let mut message = self.messages.write(); - print!("{}", *message); - message.clear(); - } - /// Print the given message. pub fn message(&self, message: &str) { - self.finish(); - - let mut spinner = self.spinner.write(); - *spinner = Self::progressbar(message); - - if !atty::is(atty::Stream::Stderr) { - // `indicatif` won't print any output if `stderr` is not a tty, so - // to ensure that our output is still emitted, we print it manually - // here. - eprintln!("{}", message) - } + println!(" {}", message); } fn add_message(&self, msg: &str) { - let mut message = self.messages.write(); - message.push_str(" "); - message.push_str(msg); - message.push('\n'); + println!("{}", msg); } /// Add an informational message. @@ -91,23 +56,6 @@ impl ProgressOutput { ); self.add_message(&err); } - - fn progressbar(msg: &str) -> ProgressBar { - let pb = ProgressBar::new_spinner(); - pb.enable_steady_tick(200); - pb.set_style( - ProgressStyle::default_spinner() - .tick_chars("/|\\- ") - .template("{spinner:.dim.bold} {wide_msg}"), - ); - pb.set_message(&msg); - pb - } - - /// After having built up a series of messages, print all of them out. - pub fn done(&self) { - self.finish(); - } } /// For processes that can be broken down into N fractional steps, with messages @@ -136,9 +84,3 @@ impl fmt::Display for Step { write!(f, "[{}/{}]", self.current, self.total) } } - -impl Drop for ProgressOutput { - fn drop(&mut self) { - self.done(); - } -}