From 12143e0ae3d314ca8f873d8410e5a5a0ad9a1c7f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 14 Aug 2024 21:41:01 +0200 Subject: [PATCH] Move escape code to `Tty`. --- Library/Homebrew/cmd/fetch.rb | 4 ++-- Library/Homebrew/utils/tty.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 3bed8cfe75eb0c..7e728b0d2bdc71 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -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 @@ -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 diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb index 61d8445bcb0d13..de9bbeaa3bddcd 100644 --- a/Library/Homebrew/utils/tty.rb +++ b/Library/Homebrew/utils/tty.rb @@ -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"