| 1 |
use std::io::{BufRead, BufReader}; |
| 2 |
use std::process; |
| 3 |
use std::time::{Duration, Instant}; |
| 4 |
|
| 5 |
use indicatif::{HumanDuration, ProgressBar, ProgressStyle}; |
| 6 |
|
| 7 |
pub fn main() { |
| 8 |
let started = Instant::now(); |
| 9 |
|
| 10 |
println!("Compiling package in release mode..."); |
| 11 |
|
| 12 |
let pb = ProgressBar::new_spinner(); |
| 13 |
pb.enable_steady_tick(Duration::from_millis(200)); |
| 14 |
pb.set_style( |
| 15 |
ProgressStyle::with_template("{spinner:.dim.bold} cargo: {wide_msg}") |
| 16 |
.unwrap() |
| 17 |
.tick_chars("/|\\- "), |
| 18 |
); |
| 19 |
|
| 20 |
let mut p = process::Command::new("cargo") |
| 21 |
.arg("build") |
| 22 |
.arg("--release") |
| 23 |
.stderr(process::Stdio::piped()) |
| 24 |
.spawn() |
| 25 |
.unwrap(); |
| 26 |
|
| 27 |
for line in BufReader::new(p.stderr.take().unwrap()).lines() { |
| 28 |
let line = line.unwrap(); |
| 29 |
let stripped_line = line.trim(); |
| 30 |
if !stripped_line.is_empty() { |
| 31 |
pb.set_message(stripped_line.to_owned()); |
| 32 |
} |
| 33 |
pb.tick(); |
| 34 |
} |
| 35 |
|
| 36 |
p.wait().unwrap(); |
| 37 |
|
| 38 |
pb.finish_and_clear(); |
| 39 |
|
| 40 |
println!("Done in {}", HumanDuration(started.elapsed())); |
| 41 |
} |