forked from 7Ji/ampack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.rs
58 lines (50 loc) · 1.72 KB
/
progress.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
/*
ampack, to unpack and pack Aml burning images: progress module
Copyright (C) 2024-present Guoxin "7Ji" Pu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use crate::Result;
fn progress_style_with_templace<S: AsRef<str>>(template: S)
-> Result<ProgressStyle>
{
let template = template.as_ref();
match ProgressStyle::with_template(template) {
Ok(style) => Ok(style),
Err(e) => {
eprintln!(
"Failed to create progress bar style from template '{}': {}",
template, e
);
Err(e.into())
}
}
}
pub(crate) fn progress_bar_with_template<S>(length: u64, template: S)
-> Result<ProgressBar>
where
S: AsRef<str>,
{
let style = progress_style_with_templace(template)?;
let bar = ProgressBar::new(length);
bar.set_style(style);
Ok(bar)
}
pub(crate) fn progress_bar_with_template_multi<S>(
multi_progress: &MultiProgress, length: u64, template: S
)
-> Result<ProgressBar>
where
S: AsRef<str>,
{
Ok(multi_progress.add(progress_bar_with_template(length, template)?))
}