@@ -259,19 +259,21 @@ def message_with_progress(downloadable, future, message)
259259 tty_width = Tty . width
260260 return message unless tty_width . positive?
261261
262+ available_width = tty_width - 2
262263 fetched_size = downloadable . fetched_size
263- return message if fetched_size . blank?
264+ return message [ 0 , available_width ] . to_s if fetched_size . blank?
264265
266+ precision = 1
265267 size_length = 5
266268 unit_length = 2
267- size_formatting_string = "%<size>#{ size_length } .1f %<unit>#{ unit_length } s"
268- size , unit = disk_usage_readable_size_unit ( fetched_size )
269+ size_formatting_string = "%<size>#{ size_length } .#{ precision } f %<unit>#{ unit_length } s"
270+ size , unit = disk_usage_readable_size_unit ( fetched_size , precision : )
269271 formatted_fetched_size = format ( size_formatting_string , size :, unit :)
270272
271273 formatted_total_size = if future . fulfilled?
272274 formatted_fetched_size
273275 elsif ( total_size = downloadable . total_size )
274- size , unit = disk_usage_readable_size_unit ( total_size )
276+ size , unit = disk_usage_readable_size_unit ( total_size , precision : )
275277 format ( size_formatting_string , size :, unit :)
276278 else
277279 # fill in the missing spaces for the size if we don't have it yet.
@@ -280,11 +282,11 @@ def message_with_progress(downloadable, future, message)
280282
281283 max_phase_length = 11
282284 phase = format ( "%-<phase>#{ max_phase_length } s" , phase : downloadable . phase . to_s . capitalize )
283- progress = "#{ formatted_fetched_size } /#{ formatted_total_size } "
284- additional_padding_length = max_phase_length + size_length + unit_length - 1
285- message_length = tty_width - progress . length - additional_padding_length
285+ progress = " [ #{ phase } #{ formatted_fetched_size } /#{ formatted_total_size } ] "
286+ message_length = available_width - progress . length
287+ return message [ 0 , available_width ] . to_s unless message_length . positive?
286288
287- "#{ message [ 0 , message_length ] . to_s . ljust ( message_length ) } [ #{ phase } #{ progress } ] "
289+ "#{ message [ 0 , message_length ] . to_s . ljust ( message_length ) } #{ progress } "
288290 end
289291
290292 class Spinner
0 commit comments