Skip to content

Commit

Permalink
Improve output.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jul 16, 2024
1 parent b115219 commit 874a32a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ def download_queue

class Spinner
FRAMES = [
"◜",
"◠",
"◝",
"◞",
"◡",
"◟",
"⠋",
"⠙",
"⠚",
"⠞",
"⠖",
"⠦",
"⠴",
"⠲",
"⠳",
"⠓",
].freeze

sig { void }
Expand Down Expand Up @@ -221,22 +225,20 @@ def run
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}"

Check warning on line 231 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L231

Added line #L231 was not covered by tests
Homebrew.failed = true if downloadable.is_a?(Resource::Patch)
end
else

spinner = Spinner.new

remaining_downloads = downloads.dup

previous_pending_line_count = 0

Check warning on line 237 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L236-L237

Added lines #L236 - L237 were not covered by tests

begin
print Tty.hide_cursor
$stdout.print Tty.hide_cursor
$stdout.flush

Check warning on line 241 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L240-L241

Added lines #L240 - L241 were not covered by tests

output_message = lambda do |downloadable, promise|
status = case promise.state

Check warning on line 244 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L243-L244

Added lines #L243 - L244 were not covered by tests
Expand All @@ -245,13 +247,14 @@ def run
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

Check warning on line 257 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L255-L257

Added lines #L255 - L257 were not covered by tests

if promise.rejected? && (e = promise.reason).is_a?(ChecksumMismatchError)
opoo "#{downloadable.download_type.capitalize} reports different checksum: #{e.expected}"
Expand All @@ -273,6 +276,7 @@ def run
finished_downloads.each do |downloadable, promise|
previous_pending_line_count -= 1
print "\033[K"
$stdout.flush
output_message.call(downloadable, promise)

Check warning on line 280 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L276-L280

Added lines #L276 - L280 were not covered by tests
end

Expand All @@ -281,6 +285,7 @@ def run
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)

Check warning on line 289 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L287-L289

Added lines #L287 - L289 were not covered by tests
end

Expand All @@ -292,11 +297,13 @@ def run
sleep 0.05

Check warning on line 297 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L297

Added line #L297 was not covered by tests
rescue Interrupt
print "\n" * previous_pending_line_count
$stdout.flush
raise

Check warning on line 301 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L299-L301

Added lines #L299 - L301 were not covered by tests
end
end
ensure
print Tty.show_cursor
$stdout.print Tty.show_cursor
$stdout.flush

Check warning on line 306 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L305-L306

Added lines #L305 - L306 were not covered by tests
end
end

Expand Down

0 comments on commit 874a32a

Please sign in to comment.