forked from rgreinho/trauma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
with-style.rs
59 lines (55 loc) · 1.88 KB
/
with-style.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Changes the style of the downloader.
//!
//! Run with:
//!
//! ```not_rust
//! cargo run -q --example with-style
//! ```
use console::style;
use std::path::PathBuf;
use trauma::{
download::Download,
downloader::{DownloaderBuilder, ProgressBarOpts, StyleOptions},
Error,
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let debian_net_install =
"https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/debian-11.3.0-arm64-netinst.iso";
let downloads = vec![Download::try_from(debian_net_install).unwrap()];
let style_opts = StyleOptions::new(
// The main bar uses a predifined template and progression characters set.
ProgressBarOpts::new(
Some(ProgressBarOpts::TEMPLATE_BAR_WITH_POSITION.into()),
Some(ProgressBarOpts::CHARS_FINE.into()),
true,
false,
),
// The child bar defines a custom template and a custom progression
// character set using unicode block characters.
// Other examples or symbols can easily be found online, for instance at:
// - https://changaco.oy.lc/unicode-progress-bars/
// - https://emojistock.com/circle-symbols/
ProgressBarOpts::new(
Some(
format!(
"{{bar:40.cyan/blue}} {{percent:>2.magenta}}{} ● {{eta_precise:.blue}}",
style("%").magenta(),
)
.into(),
),
Some("●◕◑◔○".into()),
true,
false,
),
);
// Predefined styles can also be used.
// let mut style_opts = StyleOptions::default();
// style_opts.set_child(ProgressBarOpts::with_pip_style());
let downloader = DownloaderBuilder::new()
.directory(PathBuf::from("output"))
.style_options(style_opts)
.build();
downloader.download(&downloads).await;
Ok(())
}