@@ -285,16 +285,18 @@ impl<'a> DownloadCfg<'a> {
285285 Ok ( Some ( ( file, partial_hash) ) )
286286 }
287287
288- pub ( crate ) fn status_for ( & self , component : impl Into < Cow < ' static , str > > ) -> DownloadStatus {
288+ pub ( crate ) fn status_for (
289+ & self ,
290+ component_name : impl Into < Cow < ' static , str > > ,
291+ ) -> DownloadStatus {
289292 let progress = ProgressBar :: hidden ( ) ;
290293 progress. set_style (
291- ProgressStyle :: with_template (
292- "{msg:>13.bold} downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
294+ DownloadStatus :: progress_style (
295+ "downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
293296 )
294- . unwrap ( )
295297 . progress_chars ( "## " ) ,
296298 ) ;
297- progress. set_message ( component ) ;
299+ progress. set_message ( component_name ) ;
298300 self . tracker . multi_progress_bars . add ( progress. clone ( ) ) ;
299301
300302 DownloadStatus {
@@ -360,65 +362,63 @@ impl DownloadStatus {
360362
361363 * retry_time = None ;
362364 self . progress . set_style (
363- ProgressStyle :: with_template (
364- "{msg:>13.bold} downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
365+ DownloadStatus :: progress_style (
366+ "downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
365367 )
366- . unwrap ( )
367368 . progress_chars ( "## " ) ,
368369 ) ;
369370 }
370371
371372 pub ( crate ) fn finished ( & self ) {
372- self . progress . set_style (
373- ProgressStyle :: with_template ( "{msg:>13.bold} pending installation {total_bytes:>20}" )
374- . unwrap ( ) ,
375- ) ;
373+ self . progress . set_style ( DownloadStatus :: progress_style (
374+ "pending installation {total_bytes:>20}" ,
375+ ) ) ;
376376 self . progress . tick ( ) ; // A tick is needed for the new style to appear, as it is static.
377377 }
378378
379379 pub ( crate ) fn failed ( & self ) {
380- self . progress . set_style (
381- ProgressStyle :: with_template ( "{msg:>13.bold} download failed after {elapsed}") . unwrap ( ) ,
382- ) ;
380+ self . progress . set_style ( DownloadStatus :: progress_style (
381+ " download failed after {elapsed}",
382+ ) ) ;
383383 self . progress . finish ( ) ;
384384 }
385385
386386 pub ( crate ) fn retrying ( & self ) {
387387 * self . retry_time . lock ( ) . unwrap ( ) = Some ( Instant :: now ( ) ) ;
388- self . progress . set_style (
389- ProgressStyle :: with_template ( "{msg:>13.bold} retrying download..." ) . unwrap ( ) ,
390- ) ;
388+ self . progress
389+ . set_style ( DownloadStatus :: progress_style ( "retrying download..." ) ) ;
391390 }
392391
393392 pub ( crate ) fn unpack < T : Read > ( & self , inner : T ) -> ProgressBarIter < T > {
394393 self . progress . reset ( ) ;
395394 self . progress . set_style (
396- ProgressStyle :: with_template (
397- "{msg:>13.bold} unpacking [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
395+ DownloadStatus :: progress_style (
396+ "unpacking [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
398397 )
399- . unwrap ( )
400398 . progress_chars ( "## " ) ,
401399 ) ;
402400 self . progress . wrap_read ( inner)
403401 }
404402
405403 pub ( crate ) fn installing ( & self ) {
406404 self . progress . set_style (
407- ProgressStyle :: with_template (
408- "{msg:>13.bold} installing {spinner:.green} {total_bytes:>28}" ,
409- )
410- . unwrap ( )
411- . tick_chars ( r"|/-\ " ) ,
405+ DownloadStatus :: progress_style ( "installing {spinner:.green} {total_bytes:>28}" )
406+ . tick_chars ( r"|/-\ " ) ,
412407 ) ;
413408 self . progress . enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
414409 }
415410
416411 pub ( crate ) fn installed ( & self ) {
417- self . progress . set_style (
418- ProgressStyle :: with_template ( "{msg:>13.bold} installed {total_bytes:>31}") . unwrap ( ) ,
419- ) ;
412+ self . progress . set_style ( DownloadStatus :: progress_style (
413+ " installed {total_bytes:>31}",
414+ ) ) ;
420415 self . progress . finish ( ) ;
421416 }
417+
418+ fn progress_style ( suffix : & str ) -> ProgressStyle {
419+ let template = format ! ( "{{msg:>13.bold}} {suffix}" ) ;
420+ ProgressStyle :: with_template ( & template) . unwrap ( )
421+ }
422422}
423423
424424fn file_hash ( path : & Path ) -> Result < String > {
0 commit comments