Skip to content

Commit

Permalink
Use full terminal height for concurrent output.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 1, 2025
1 parent 9465364 commit e118d0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def run
$stdout.print Tty.hide_cursor
$stdout.flush

output_message = lambda do |downloadable, future|
output_message = lambda do |downloadable, future, last|

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L243

Added line #L243 was not covered by tests
status = case future.state
when :fulfilled
"#{Tty.green}✔︎#{Tty.reset}"
Expand All @@ -253,7 +253,7 @@ def run
end

message = "#{downloadable.download_type.capitalize} #{downloadable.name}"
$stdout.puts "#{status} #{message}"
$stdout.print "#{status} #{message}#{last ? "" : "\n"}"
$stdout.flush

if future.rejected? && (e = future.reason).is_a?(ChecksumMismatchError)
Expand All @@ -277,21 +277,26 @@ def run
previous_pending_line_count -= 1
$stdout.print Tty.clear_to_end
$stdout.flush
output_message.call(downloadable, future)
output_message.call(downloadable, future, false)

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#L280

Added line #L280 was not covered by tests
end

previous_pending_line_count = 0
remaining_downloads.each do |downloadable, future|
# FIXME: Allow printing full terminal height.
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min
max_lines = [concurrency, Tty.height].min
remaining_downloads.each_with_index do |(downloadable, future), i|

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L284-L285

Added lines #L284 - L285 were not covered by tests
break if previous_pending_line_count >= max_lines

$stdout.print Tty.clear_to_end
$stdout.flush
previous_pending_line_count += output_message.call(downloadable, future)
last = i == max_lines - 1 || i == remaining_downloads.count - 1
previous_pending_line_count += output_message.call(downloadable, future, last)

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L290-L291

Added lines #L290 - L291 were not covered by tests
end

if previous_pending_line_count.positive?
$stdout.print Tty.move_cursor_up_beginning(previous_pending_line_count)
if (previous_pending_line_count - 1).zero?
$stdout.print Tty.move_cursor_beginning
else
$stdout.print Tty.move_cursor_up_beginning(previous_pending_line_count - 1)
end
$stdout.flush
end

Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/utils/tty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def move_cursor_up_beginning(line_count)
"\033[#{line_count}F"
end

sig { returns(String) }
def move_cursor_beginning
"\033[0G"

Check warning on line 75 in Library/Homebrew/utils/tty.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/tty.rb#L75

Added line #L75 was not covered by tests
end

sig { params(line_count: Integer).returns(String) }
def move_cursor_down(line_count)
"\033[#{line_count}B"
Expand Down

0 comments on commit e118d0a

Please sign in to comment.