Skip to content

Commit 5460b76

Browse files
committed
add progress bar to downloads
1 parent e0d83ce commit 5460b76

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Library/Homebrew/download_queue.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,21 @@ def message_with_progress(downloadable, future, message)
294294

295295
max_phase_length = 11
296296
phase = format("%-<phase>#{max_phase_length}s", phase: downloadable.phase.to_s.capitalize)
297-
progress = " [#{phase} #{formatted_fetched_size}/#{formatted_total_size}]"
297+
progress_bar = if future.fulfilled?
298+
""
299+
else
300+
percent = if (total_size = downloadable.total_size)
301+
fetched_size.to_f / [1, total_size].max
302+
else
303+
0.0
304+
end
305+
bar_length = [4, available_width / 5].max
306+
bar_used = (percent * bar_length).round
307+
bar_completed = "━" * bar_used
308+
bar_pending = "┈" * (bar_length - bar_used)
309+
"#{bar_completed}#{bar_pending} "
310+
end
311+
progress = " #{progress_bar}#{phase} #{formatted_fetched_size}/#{formatted_total_size}"
298312
message_length = available_width - progress.length
299313
return message[0, available_width].to_s unless message_length.positive?
300314

0 commit comments

Comments
 (0)