Skip to content

Commit

Permalink
Move escape code to Tty.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Aug 14, 2024
1 parent 8bb8b5a commit 12143e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def run

finished_downloads.each do |downloadable, future|
previous_pending_line_count -= 1
print "\033[K"
print Tty.clear_to_end
$stdout.flush
output_message.call(downloadable, future)
end
Expand All @@ -284,7 +284,7 @@ def run
remaining_downloads.each do |downloadable, future|
break if previous_pending_line_count >= [concurrency, (Tty.height - 1)].min

print "\033[K"
print Tty.clear_to_end
$stdout.flush
previous_pending_line_count += output_message.call(downloadable, future)
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 @@ -51,6 +51,11 @@ def strip_ansi(string)
string.gsub(/\033\[\d+(;\d+)*m/, "")
end

sig { returns(String) }
def clear_to_end
"\033[K"
end

sig { returns(String) }
def hide_cursor
"\033[?25l"
Expand Down

0 comments on commit 12143e0

Please sign in to comment.