@@ -282,9 +282,10 @@ def message_with_progress(downloadable, future, message, message_length_max)
282282 size , unit = disk_usage_readable_size_unit ( fetched_size , precision :)
283283 formatted_fetched_size = format ( size_formatting_string , size :, unit :)
284284
285+ total_size = downloadable . total_size
285286 formatted_total_size = if future . fulfilled?
286287 formatted_fetched_size
287- elsif ( total_size = downloadable . total_size )
288+ elsif total_size
288289 size , unit = disk_usage_readable_size_unit ( total_size , precision :)
289290 format ( size_formatting_string , size :, unit :)
290291 else
@@ -296,15 +297,11 @@ def message_with_progress(downloadable, future, message, message_length_max)
296297 phase = format ( "%-<phase>#{ max_phase_length } s" , phase : downloadable . phase . to_s . capitalize )
297298 progress = " #{ phase } #{ formatted_fetched_size } /#{ formatted_total_size } "
298299 bar_length = [ 4 , available_width - progress . length - message_length_max - 1 ] . max
299- if downloadable . phase == :downloading
300- percent = if ( total_size = downloadable . total_size )
301- ( fetched_size . to_f / [ 1 , total_size ] . max ) . clamp ( 0.0 , 1.0 )
302- else
303- 0.0
304- end
300+ if downloadable . phase == :downloading && total_size
301+ percent = ( fetched_size . to_f / [ 1 , total_size ] . max ) . clamp ( 0.0 , 1.0 )
305302 bar_used = ( percent * bar_length ) . round
306303 bar_completed = "#" * bar_used
307- bar_pending = "- " * ( bar_length - bar_used )
304+ bar_pending = " " * ( bar_length - bar_used )
308305 progress = " #{ bar_completed } #{ bar_pending } #{ progress } "
309306 end
310307 message_length = available_width - progress . length
0 commit comments