Merge pull request #19194 from Homebrew/concurrent-downloads-full-height
Use full terminal height for concurrent output.
This commit is contained in:
commit
f66edcd636
@ -240,7 +240,7 @@ module Homebrew
|
|||||||
$stdout.print Tty.hide_cursor
|
$stdout.print Tty.hide_cursor
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
|
|
||||||
output_message = lambda do |downloadable, future|
|
output_message = lambda do |downloadable, future, last|
|
||||||
status = case future.state
|
status = case future.state
|
||||||
when :fulfilled
|
when :fulfilled
|
||||||
"#{Tty.green}✔︎#{Tty.reset}"
|
"#{Tty.green}✔︎#{Tty.reset}"
|
||||||
@ -253,7 +253,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
message = "#{downloadable.download_type.capitalize} #{downloadable.name}"
|
message = "#{downloadable.download_type.capitalize} #{downloadable.name}"
|
||||||
$stdout.puts "#{status} #{message}"
|
$stdout.print "#{status} #{message}#{"\n" unless last}"
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
|
|
||||||
if future.rejected? && (e = future.reason).is_a?(ChecksumMismatchError)
|
if future.rejected? && (e = future.reason).is_a?(ChecksumMismatchError)
|
||||||
@ -277,21 +277,26 @@ module Homebrew
|
|||||||
previous_pending_line_count -= 1
|
previous_pending_line_count -= 1
|
||||||
$stdout.print Tty.clear_to_end
|
$stdout.print Tty.clear_to_end
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
output_message.call(downloadable, future)
|
output_message.call(downloadable, future, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
previous_pending_line_count = 0
|
previous_pending_line_count = 0
|
||||||
remaining_downloads.each do |downloadable, future|
|
max_lines = [concurrency, Tty.height].min
|
||||||
# FIXME: Allow printing full terminal height.
|
remaining_downloads.each_with_index do |(downloadable, future), i|
|
||||||
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min
|
break if previous_pending_line_count >= max_lines
|
||||||
|
|
||||||
$stdout.print Tty.clear_to_end
|
$stdout.print Tty.clear_to_end
|
||||||
$stdout.flush
|
$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)
|
||||||
end
|
end
|
||||||
|
|
||||||
if previous_pending_line_count.positive?
|
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
|
$stdout.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -70,6 +70,11 @@ module Tty
|
|||||||
"\033[#{line_count}F"
|
"\033[#{line_count}F"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def move_cursor_beginning
|
||||||
|
"\033[0G"
|
||||||
|
end
|
||||||
|
|
||||||
sig { params(line_count: Integer).returns(String) }
|
sig { params(line_count: Integer).returns(String) }
|
||||||
def move_cursor_down(line_count)
|
def move_cursor_down(line_count)
|
||||||
"\033[#{line_count}B"
|
"\033[#{line_count}B"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user