@@ -8,7 +8,7 @@ use std::time::Duration;
88/// Abstract progress sender/handler used for both CLI and GUI mode.
99pub trait ProgressHandler : Send + Sync {
1010 /// Start the progress with a certain message and style.
11- fn start ( & mut self , msg : String , style : ProgressStyle ) -> Result < ( ) > ;
11+ fn start ( & mut self , msg : String , style : ProgressKind ) -> Result < ( ) > ;
1212 /// Update the progress to a value, or tick once if the value is `None`.
1313 fn update ( & self , value : Option < u64 > ) -> Result < ( ) > ;
1414 /// Finish progress with a certain message.
@@ -17,7 +17,7 @@ pub trait ProgressHandler: Send + Sync {
1717 // Optional overall (master) progress control
1818
1919 /// Start the master progress bar with a certain progress.
20- fn start_master ( & mut self , msg : String , style : ProgressStyle ) -> Result < ( ) > {
20+ fn start_master ( & mut self , msg : String , style : ProgressKind ) -> Result < ( ) > {
2121 Ok ( ( ) )
2222 }
2323 /// Update the master progress bar, or tick once if the value is `None`.
@@ -31,7 +31,7 @@ pub trait ProgressHandler: Send + Sync {
3131}
3232
3333#[ derive( Debug , Clone , Copy ) ]
34- pub enum ProgressStyle {
34+ pub enum ProgressKind {
3535 /// Display the progress base on number of bytes.
3636 Bytes ( u64 ) ,
3737 /// Display the progress base on position & length parameters.
@@ -46,7 +46,7 @@ pub enum ProgressStyle {
4646 Hidden ,
4747}
4848
49- impl ProgressStyle {
49+ impl ProgressKind {
5050 fn cli_pattern ( & self ) -> & str {
5151 match self {
5252 Self :: Bytes ( _) => "{msg}\n {spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})" ,
@@ -70,7 +70,7 @@ impl ProgressStyle {
7070pub struct HiddenProgress ;
7171
7272impl ProgressHandler for HiddenProgress {
73- fn start ( & mut self , _msg : String , _style : ProgressStyle ) -> Result < ( ) > {
73+ fn start ( & mut self , _msg : String , _style : ProgressKind ) -> Result < ( ) > {
7474 Ok ( ( ) )
7575 }
7676 fn finish ( & self , _msg : String ) -> Result < ( ) > {
@@ -85,50 +85,52 @@ impl ProgressHandler for HiddenProgress {
8585#[ derive( Debug , Clone ) ]
8686pub struct CliProgress {
8787 bar : CliProgressBar ,
88- style : ProgressStyle ,
88+ style : ProgressKind ,
8989}
9090
9191impl Default for CliProgress {
9292 fn default ( ) -> Self {
9393 Self {
9494 bar : CliProgressBar :: hidden ( ) ,
95- style : ProgressStyle :: Hidden ,
95+ style : ProgressKind :: Hidden ,
9696 }
9797 }
9898}
9999
100100impl ProgressHandler for CliProgress {
101- fn start ( & mut self , msg : String , style : ProgressStyle ) -> Result < ( ) > {
101+ fn start ( & mut self , msg : String , style : ProgressKind ) -> Result < ( ) > {
102102 // log the starting of the progress
103103 info ! ( "{msg}" ) ;
104104
105105 let bar = match style {
106- ProgressStyle :: Bytes ( len) | ProgressStyle :: Len ( len) => CliProgressBar :: new ( len) ,
107- ProgressStyle :: Spinner { auto_tick_duration } => {
106+ ProgressKind :: Bytes ( len) | ProgressKind :: Len ( len) => CliProgressBar :: new ( len) ,
107+ ProgressKind :: Spinner { auto_tick_duration } => {
108108 let bar = CliProgressBar :: new_spinner ( ) ;
109109 if let Some ( interval) = auto_tick_duration {
110110 bar. enable_steady_tick ( interval) ;
111111 }
112112 bar
113113 }
114- ProgressStyle :: Hidden => CliProgressBar :: hidden ( ) ,
114+ ProgressKind :: Hidden => CliProgressBar :: hidden ( ) ,
115115 } ;
116116
117- self . bar = bar. with_style (
118- CliProgressStyle :: with_template ( style. cli_pattern ( ) )
119- . with_context ( || {
120- format ! ( "Internal error: Invalid style pattern defined for {style:?}" )
121- } ) ?
122- . with_key (
123- "eta" ,
124- |state : & ProgressState , w : & mut dyn std:: fmt:: Write | {
125- write ! ( w, "{:.1}s" , state. eta( ) . as_secs_f64( ) )
126- . expect ( "unable to display progress bar" )
127- } ,
128- )
129- . progress_chars ( "#>-" ) ,
130- ) . with_message ( msg)
131- . with_position ( 0 ) ;
117+ self . bar = bar
118+ . with_style (
119+ CliProgressStyle :: with_template ( style. cli_pattern ( ) )
120+ . with_context ( || {
121+ format ! ( "Internal error: Invalid style pattern defined for {style:?}" )
122+ } ) ?
123+ . with_key (
124+ "eta" ,
125+ |state : & ProgressState , w : & mut dyn std:: fmt:: Write | {
126+ write ! ( w, "{:.1}s" , state. eta( ) . as_secs_f64( ) )
127+ . expect ( "unable to display progress bar" )
128+ } ,
129+ )
130+ . progress_chars ( "#>-" ) ,
131+ )
132+ . with_message ( msg)
133+ . with_position ( 0 ) ;
132134 self . style = style;
133135
134136 Ok ( ( ) )
0 commit comments