Skip to content

Commit

Permalink
Improve output.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jul 15, 2024
1 parent 039aefd commit 0cc3d96
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,32 @@ def run

until remaining_downloads.empty?
begin
finished_downloads = {}

finished_states = [:fulfilled, :rejected]
remaining_downloads.each do |downloadable, promise|
break unless finished_states.include?(promise.state)

finished_downloads[downloadable] = remaining_downloads.delete(downloadable)
end

finished_downloads, remaining_downloads = remaining_downloads.partition { |_,promise| finished_states.include?(promise.state) }

finished_downloads.each do |downloadable, promise|
previous_pending_line_count -= 1
print "\033[K"
output_message.call(downloadable, promise)
end

previous_pending_line_count = 0
remaining_downloads.each do |downloadable, promise|
break if previous_pending_line_count >= (Tty.height - 1)
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min

print "\033[K"
previous_pending_line_count += output_message.call(downloadable, promise)
end

if previous_pending_line_count.positive?
$stdout.print "\033[#{previous_pending_line_count}A"
$stdout.flush
end

sleep 0.05
rescue Interrupt
print "\n" * previous_pending_line_count
raise
Expand Down

0 comments on commit 0cc3d96

Please sign in to comment.