From d6ebb04ff5b51633c9e4e3dc71a37dd06eb28650 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 16 Jul 2024 00:01:40 -0400 Subject: [PATCH] Improve output. --- Library/Homebrew/cmd/fetch.rb | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index d35680936b..069abe2230 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -82,12 +82,16 @@ module Homebrew class Spinner FRAMES = [ - "◜", - "◠", - "◝", - "◞", - "◡", - "◟", + "⠋", + "⠙", + "⠚", + "⠞", + "⠖", + "⠦", + "⠴", + "⠲", + "⠳", + "⠓", ].freeze sig { void } @@ -221,22 +225,20 @@ module Homebrew end if concurrency == 1 - downloads.each_value do |promise| + downloads.each do |downloadable, promise| promise.wait! rescue ChecksumMismatchError => e opoo "#{downloadable.download_type.capitalize} reports different checksum: #{e.expected}" Homebrew.failed = true if downloadable.is_a?(Resource::Patch) end else - spinner = Spinner.new - remaining_downloads = downloads.dup - previous_pending_line_count = 0 begin - print Tty.hide_cursor + $stdout.print Tty.hide_cursor + $stdout.flush output_message = lambda do |downloadable, promise| status = case promise.state @@ -245,13 +247,14 @@ module Homebrew when :rejected "#{Tty.red}✘#{Tty.reset}" when :pending - spinner + "#{Tty.blue}#{spinner}#{Tty.reset}" else raise promise.state end message = "#{downloadable.download_type.capitalize} #{downloadable.name}" - puts "#{status} #{message}" + $stdout.puts "#{status} #{message}" + $stdout.flush if promise.rejected? && (e = promise.reason).is_a?(ChecksumMismatchError) opoo "#{downloadable.download_type.capitalize} reports different checksum: #{e.expected}" @@ -273,6 +276,7 @@ module Homebrew finished_downloads.each do |downloadable, promise| previous_pending_line_count -= 1 print "\033[K" + $stdout.flush output_message.call(downloadable, promise) end @@ -281,6 +285,7 @@ module Homebrew break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min print "\033[K" + $stdout.flush previous_pending_line_count += output_message.call(downloadable, promise) end @@ -292,11 +297,13 @@ module Homebrew sleep 0.05 rescue Interrupt print "\n" * previous_pending_line_count + $stdout.flush raise end end ensure - print Tty.show_cursor + $stdout.print Tty.show_cursor + $stdout.flush end end