@@ -288,10 +288,12 @@ impl<'a> DownloadCfg<'a> {
288288 pub ( crate ) fn status_for (
289289 & self ,
290290 component_name : impl Into < Cow < ' static , str > > ,
291+ name_width : usize ,
291292 ) -> DownloadStatus {
292293 let progress = ProgressBar :: hidden ( ) ;
293294 progress. set_style (
294295 DownloadStatus :: progress_style (
296+ name_width,
295297 "downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
296298 )
297299 . progress_chars ( "## " ) ,
@@ -302,6 +304,7 @@ impl<'a> DownloadCfg<'a> {
302304 DownloadStatus {
303305 progress,
304306 retry_time : Mutex :: new ( None ) ,
307+ name_width,
305308 }
306309 }
307310
@@ -345,6 +348,8 @@ pub(crate) struct DownloadStatus {
345348 /// bar would reappear immediately, not allowing the user to correctly see the message,
346349 /// before the progress bar starts again.
347350 retry_time : Mutex < Option < Instant > > ,
351+ /// The dynamic maximum width of the component names for alignment
352+ name_width : usize ,
348353}
349354
350355impl DownloadStatus {
@@ -363,6 +368,7 @@ impl DownloadStatus {
363368 * retry_time = None ;
364369 self . progress . set_style (
365370 DownloadStatus :: progress_style (
371+ self . name_width ,
366372 "downloading [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
367373 )
368374 . progress_chars ( "## " ) ,
@@ -371,28 +377,33 @@ impl DownloadStatus {
371377
372378 pub ( crate ) fn finished ( & self ) {
373379 self . progress . set_style ( DownloadStatus :: progress_style (
380+ self . name_width ,
374381 "pending installation {total_bytes:>20}" ,
375382 ) ) ;
376383 self . progress . tick ( ) ; // A tick is needed for the new style to appear, as it is static.
377384 }
378385
379386 pub ( crate ) fn failed ( & self ) {
380387 self . progress . set_style ( DownloadStatus :: progress_style (
388+ self . name_width ,
381389 "download failed after {elapsed}" ,
382390 ) ) ;
383391 self . progress . finish ( ) ;
384392 }
385393
386394 pub ( crate ) fn retrying ( & self ) {
387395 * self . retry_time . lock ( ) . unwrap ( ) = Some ( Instant :: now ( ) ) ;
388- self . progress
389- . set_style ( DownloadStatus :: progress_style ( "retrying download..." ) ) ;
396+ self . progress . set_style ( DownloadStatus :: progress_style (
397+ self . name_width ,
398+ "retrying download..." ,
399+ ) ) ;
390400 }
391401
392402 pub ( crate ) fn unpack < T : Read > ( & self , inner : T ) -> ProgressBarIter < T > {
393403 self . progress . reset ( ) ;
394404 self . progress . set_style (
395405 DownloadStatus :: progress_style (
406+ self . name_width ,
396407 "unpacking [{bar:15}] {total_bytes:>11} ({bytes_per_sec}, ETA: {eta})" ,
397408 )
398409 . progress_chars ( "## " ) ,
@@ -402,21 +413,25 @@ impl DownloadStatus {
402413
403414 pub ( crate ) fn installing ( & self ) {
404415 self . progress . set_style (
405- DownloadStatus :: progress_style ( "installing {spinner:.green} {total_bytes:>28}" )
406- . tick_chars ( r"|/-\ " ) ,
416+ DownloadStatus :: progress_style (
417+ self . name_width ,
418+ "installing {spinner:.green} {total_bytes:>28}" ,
419+ )
420+ . tick_chars ( r"|/-\ " ) ,
407421 ) ;
408422 self . progress . enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
409423 }
410424
411425 pub ( crate ) fn installed ( & self ) {
412426 self . progress . set_style ( DownloadStatus :: progress_style (
427+ self . name_width ,
413428 "installed {total_bytes:>31}" ,
414429 ) ) ;
415430 self . progress . finish ( ) ;
416431 }
417432
418- fn progress_style ( suffix : & str ) -> ProgressStyle {
419- let template = format ! ( "{{msg:>13 .bold}} {suffix}" ) ;
433+ fn progress_style ( name_width : usize , suffix : & str ) -> ProgressStyle {
434+ let template = format ! ( "{{msg:>{name_width} .bold}} {suffix}" ) ;
420435 ProgressStyle :: with_template ( & template) . unwrap ( )
421436 }
422437}
0 commit comments