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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#[ allow( clippy ::std_instead_of_alloc, clippy ::std_instead_of_core ) ]
mod private
{
/// The `ProgressBar` structure is used to display progress indicators in the terminal.
/// It wraps the functionality of the `indicatif` library.
///
/// This structure is only available when the `progress_bar` feature is enabled.
#[ cfg( feature = "progress_bar" ) ]
pub struct ProgressBar< 'a >
{
/// A reference to the `MultiProgress` object from the `indicatif` library, which
/// allows managing multiple progress bars simultaneously. This object is necessary
/// for coordinating the display of multiple progress bars.
pub( crate ) multi_progress: &'a indicatif ::MultiProgress,
/// The `ProgressBar` object from the `indicatif` library, which represents
/// an individual progress indicator. It is used to update the progress state
/// and display it in the terminal.
pub( crate ) progress_bar: indicatif ::ProgressBar,
}
#[ cfg( feature = "progress_bar" ) ]
impl std ::fmt ::Debug for ProgressBar< '_ > // fix clippy
{
fn fmt( &self, f: &mut std ::fmt ::Formatter< '_ > ) -> std ::fmt ::Result
{
f.debug_struct( "ProgressBar" )
.finish()
}
}
/// The `MultiProgress` structure is used to manage and display multiple progress
/// indicators simultaneously in the terminal. It utilizes the `indicatif` library.
///
/// This structure is only available when the `progress_bar` feature is enabled.
#[ cfg( feature = "progress_bar" ) ]
pub struct MultiProgress
{
multi_progress: indicatif ::MultiProgress,
progress_style: indicatif ::ProgressStyle,
}
#[ cfg( feature = "progress_bar" ) ]
impl MultiProgress
{
/// Creates a new `ProgressBar` instance tied to the `MultiProgress` manager.
/// This function initializes a new progress bar with a specified length and applies
/// the defined style to it.
///
/// # Parameters
///
/// - `variants_len` : The total length or count that the progress bar will track.
///
/// # Returns
///
/// A `ProgressBar` instance that can be used to update and display progress.
#[ must_use ]
pub fn progress_bar( &self, variants_len: u64 ) -> ProgressBar< '_ >
{
let progress_bar =
{
let pb = self.multi_progress.add( indicatif ::ProgressBar ::new( variants_len ) );
pb.set_style( self.progress_style.clone() );
pb.inc( 0 );
pb
};
ProgressBar
{
multi_progress: &self.multi_progress,
progress_bar,
}
}
}
#[ cfg( feature = "progress_bar" ) ]
impl std ::fmt ::Debug for MultiProgress
{
fn fmt( &self, f: &mut std ::fmt ::Formatter< '_ > ) -> std ::fmt ::Result
{
f.debug_struct( "MultiprogressProgress" )
.finish()
}
}
#[ cfg( feature = "progress_bar" ) ]
impl Default for MultiProgress
{
fn default() -> Self
{
Self
{
multi_progress: indicatif ::MultiProgress ::new(),
progress_style: indicatif ::ProgressStyle ::with_template
(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)
.unwrap()
.progress_chars( "##-" ),
}
}
}
}
crate ::mod_interface!
{
#[ cfg( feature = "progress_bar" ) ]
own use ProgressBar;
#[ cfg( feature = "progress_bar" ) ]
own use MultiProgress;
}