forked from rustwasm/wasm-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rustwasm#66 from mgattozzi/lazy-static
feat(pbar): Add global progress bar to write to
- Loading branch information
Showing
9 changed files
with
94 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ serde = "1.0" | |
serde_derive = "1.0" | ||
serde_json = "1.0" | ||
toml = "0.4" | ||
lazy_static = "1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,63 @@ | ||
use indicatif::{ProgressBar, ProgressStyle}; | ||
|
||
pub fn new(msg: String) -> 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 | ||
use console::style; | ||
use emoji; | ||
use failure::Error; | ||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | ||
|
||
pub struct ProgressOutput { | ||
bar: MultiProgress, | ||
} | ||
|
||
impl ProgressOutput { | ||
pub fn new() -> Self { | ||
Self { | ||
bar: MultiProgress::new(), | ||
} | ||
} | ||
|
||
pub fn message(&self, message: &str) -> ProgressBar { | ||
self.bar.add(Self::progressbar(message)) | ||
} | ||
|
||
pub fn one_off_message(&self, message: &str) { | ||
let bar = self.bar.add(Self::progressbar(message)); | ||
bar.finish(); | ||
} | ||
|
||
pub fn warn(&self, message: &str) { | ||
let warn = format!( | ||
"{} {}: {}", | ||
style("[WARN]").bold().dim(), | ||
emoji::WARN, | ||
message | ||
); | ||
let bar = self.bar.add(Self::progressbar(&warn)); | ||
bar.finish(); | ||
} | ||
|
||
pub fn error(&self, message: &str) { | ||
let err = format!( | ||
"{} {}: {}", | ||
emoji::ERROR, | ||
style("[Error]").bold().dim(), | ||
message | ||
); | ||
let bar = self.bar.add(Self::progressbar(&err)); | ||
bar.finish(); | ||
} | ||
|
||
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 | ||
} | ||
|
||
pub fn done(&self) -> Result<(), Error> { | ||
self.bar.join_and_clear().map_err(|e| Error::from(e)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
use console::style; | ||
use failure::Error; | ||
use indicatif::MultiProgress; | ||
use std::fs; | ||
|
||
use PBAR; | ||
use emoji; | ||
use progressbar; | ||
|
||
pub fn copy_from_crate(path: &str) -> Result<(), Error> { | ||
let m = MultiProgress::new(); | ||
let step = format!( | ||
"{} {}Copying over your README...", | ||
style("[5/7]").bold().dim(), | ||
emoji::DANCERS | ||
); | ||
let pb = m.add(progressbar::new(step)); | ||
let pb = PBAR.message(&step); | ||
let crate_readme_path = format!("{}/README.md", path); | ||
let new_readme_path = format!("{}/pkg/README.md", path); | ||
if let Err(_) = fs::copy(&crate_readme_path, &new_readme_path) { | ||
let warn = format!( | ||
"{} {}: origin crate has no README", | ||
emoji::WARN, | ||
style("[WARN]").bold().dim() | ||
); | ||
let warn_pb = m.add(progressbar::new(warn)); | ||
warn_pb.finish(); | ||
PBAR.warn("origin crate has no README"); | ||
}; | ||
pb.finish(); | ||
m.join_and_clear()?; | ||
Ok(()) | ||
} |