Move escape codes to Tty.
This commit is contained in:
parent
404176af1d
commit
984cde114a
@ -275,7 +275,7 @@ module Homebrew
|
|||||||
|
|
||||||
finished_downloads.each do |downloadable, future|
|
finished_downloads.each do |downloadable, future|
|
||||||
previous_pending_line_count -= 1
|
previous_pending_line_count -= 1
|
||||||
print "\033[K"
|
$stdout.print Tty.clear_to_end
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
output_message.call(downloadable, future)
|
output_message.call(downloadable, future)
|
||||||
end
|
end
|
||||||
@ -284,13 +284,13 @@ module Homebrew
|
|||||||
remaining_downloads.each do |downloadable, future|
|
remaining_downloads.each do |downloadable, future|
|
||||||
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min
|
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min
|
||||||
|
|
||||||
print "\033[K"
|
$stdout.print Tty.clear_to_end
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
previous_pending_line_count += output_message.call(downloadable, future)
|
previous_pending_line_count += output_message.call(downloadable, future)
|
||||||
end
|
end
|
||||||
|
|
||||||
if previous_pending_line_count.positive?
|
if previous_pending_line_count.positive?
|
||||||
$stdout.print "\033[#{previous_pending_line_count}A"
|
$stdout.print Tty.move_cursor_up(previous_pending_line_count)
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -300,8 +300,11 @@ module Homebrew
|
|||||||
# FIXME: Implement cancellation of running downloads.
|
# FIXME: Implement cancellation of running downloads.
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n" * previous_pending_line_count
|
if previous_pending_line_count.positive?
|
||||||
$stdout.flush
|
$stdout.print Tty.move_cursor_down(previous_pending_line_count - 1)
|
||||||
|
$stdout.flush
|
||||||
|
end
|
||||||
|
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -51,6 +51,21 @@ module Tty
|
|||||||
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(line_count: Integer).returns(String) }
|
||||||
|
def move_cursor_up(line_count)
|
||||||
|
"\033[#{line_count}A"
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(line_count: Integer).returns(String) }
|
||||||
|
def move_cursor_down(line_count)
|
||||||
|
"\033[#{line_count}B"
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def clear_to_end
|
||||||
|
"\033[K"
|
||||||
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def hide_cursor
|
def hide_cursor
|
||||||
"\033[?25l"
|
"\033[?25l"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user