aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/brew.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/moved.rb5
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/info.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb11
-rw-r--r--Library/Homebrew/cmd/doctor.rb2
-rw-r--r--Library/Homebrew/cmd/help.rb10
-rw-r--r--Library/Homebrew/cmd/info.rb4
-rw-r--r--Library/Homebrew/cmd/update-report.rb2
-rw-r--r--Library/Homebrew/debrew.rb2
-rw-r--r--Library/Homebrew/descriptions.rb2
-rw-r--r--Library/Homebrew/dev-cmd/bottle.rb2
-rw-r--r--Library/Homebrew/exceptions.rb2
-rw-r--r--Library/Homebrew/migrator.rb2
-rw-r--r--Library/Homebrew/test/test_utils.rb36
-rw-r--r--Library/Homebrew/utils.rb92
-rw-r--r--Library/Homebrew/utils/github.rb6
-rw-r--r--Library/Homebrew/utils/tty.rb64
19 files changed, 125 insertions, 127 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb
index 1ba3fb8c2..4ea830806 100644
--- a/Library/Homebrew/brew.rb
+++ b/Library/Homebrew/brew.rb
@@ -147,8 +147,8 @@ rescue Exception => e
Utils::Analytics.report_exception(e)
onoe e
if internal_cmd && defined?(OS::ISSUES_URL)
- $stderr.puts "#{Tty.white}Please report this bug:"
- $stderr.puts " #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}"
+ $stderr.puts "Please report this bug:"
+ $stderr.puts " #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}"
end
$stderr.puts e.backtrace
exit 1
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
index 6095887e3..ff6e5f273 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
@@ -81,11 +81,10 @@ module Hbc
if target.exist?
target_abv = " (#{target.abv})"
else
- warning = "Missing #{self.class.artifact_english_name}"
- warning = "#{Tty.red}#{warning}#{Tty.reset}: "
+ error = "#{Tty.red}Missing #{self.class.artifact_english_name}:#{Tty.reset} "
end
- "#{warning}#{printable_target}#{target_abv}"
+ "#{error}#{printable_target}#{target_abv}"
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb
index 7fbdff3eb..e2f360296 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/info.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -27,7 +27,7 @@ module Hbc
end
def self.formatted_url(url)
- "#{Tty.em}#{url}#{Tty.reset}"
+ "#{Tty.underline}#{url}#{Tty.reset}"
end
def self.installation_info(cask)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index 66117da8b..bb179fb0c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -30,7 +30,7 @@ module Hbc
begin
Homebrew.install_gem_setup_path! "rubocop-cask", RUBOCOP_CASK_VERSION, "rubocop"
rescue SystemExit
- raise CaskError, $stderr.string.chomp.sub("#{Tty.red}Error#{Tty.reset}: ", "")
+ raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "")
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index f0cc0d1a9..1002be460 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -87,7 +87,7 @@ module Hbc
s = if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"]
(ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " "
else
- "#{Tty.blue}==>#{Tty.reset} #{Tty.white}Success!#{Tty.reset} "
+ "#{Tty.blue}==>#{Tty.reset} #{Tty.bold}Success!#{Tty.reset} "
end
s << "#{@cask} was successfully installed!"
end
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index 9159544a6..c6a970fca 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -32,11 +32,6 @@ end
def odebug(title, *sput)
return unless Hbc.respond_to?(:debug)
return unless Hbc.debug
-
- width = Tty.width * 4 - 6
- if $stdout.tty? && title.to_s.length > width
- title = title.to_s[0, width - 3] + "..."
- end
puts "#{Tty.magenta}==>#{Tty.reset} #{Tty.white}#{title}#{Tty.reset}"
puts sput unless sput.empty?
end
@@ -152,11 +147,11 @@ module Hbc
<<-EOS.undent
Most likely, this means you have an outdated version of Homebrew-Cask. Please run:
- #{Tty.green}#{UPDATE_CMD}
+ #{Tty.green}#{UPDATE_CMD}#{Tty.reset}
- #{Tty.reset}If this doesn’t fix the problem, please report this bug:
+ If this doesn’t fix the problem, please report this bug:
- #{Tty.em}#{ISSUES_URL}#{Tty.reset}
+ #{Tty.underline}#{ISSUES_URL}#{Tty.reset}
EOS
end
diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb
index 89f32dc25..e6b5fcba0 100644
--- a/Library/Homebrew/cmd/doctor.rb
+++ b/Library/Homebrew/cmd/doctor.rb
@@ -42,7 +42,7 @@ module Homebrew
next if out.nil? || out.empty?
if first_warning
$stderr.puts <<-EOS.undent
- #{Tty.white}Please note that these warnings are just used to help the Homebrew maintainers
+ #{Tty.bold}Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!#{Tty.reset}
EOS
diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb
index 2a814b90b..05a3003cc 100644
--- a/Library/Homebrew/cmd/help.rb
+++ b/Library/Homebrew/cmd/help.rb
@@ -78,11 +78,11 @@ module Homebrew
HOMEBREW_HELP
else
help_lines.map do |line|
- line.slice(2..-1)
- .sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ")
- .gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}")
- .gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}")
- .gsub("@hide_from_man_page", "")
+ line.slice(2..-1).
+ sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} ").
+ gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}").
+ gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}").
+ gsub("@hide_from_man_page", "")
end.join.strip
end
end
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb
index 6f242039c..9721585cf 100644
--- a/Library/Homebrew/cmd/info.rb
+++ b/Library/Homebrew/cmd/info.rb
@@ -117,7 +117,7 @@ module Homebrew
puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}"
puts f.desc if f.desc
- puts "#{Tty.em}#{f.homepage}#{Tty.reset}" if f.homepage
+ puts "#{Tty.underline}#{f.homepage}#{Tty.reset}" if f.homepage
conflicts = f.conflicts.map(&:name).sort!
puts "Conflicts with: #{conflicts*", "}" unless conflicts.empty?
@@ -133,7 +133,7 @@ module Homebrew
end
end
- puts "From: #{Tty.em}#{github_info(f)}#{Tty.reset}"
+ puts "From: #{Tty.underline}#{github_info(f)}#{Tty.reset}"
unless f.deps.empty?
ohai "Dependencies"
diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 18f2f370c..c275606e2 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -282,7 +282,7 @@ module Homebrew
EOS
rescue => e
ofail <<-EOS.undent
- #{Tty.white}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}!
+ #{Tty.bold}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}!#{Tty.reset}
The error was:
#{e}
Please try to resolve this error yourself and then run `brew update` again to
diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb
index 1c5047a8c..668a0b4d2 100644
--- a/Library/Homebrew/debrew.rb
+++ b/Library/Homebrew/debrew.rb
@@ -111,7 +111,7 @@ module Debrew
begin
puts e.backtrace.first.to_s
- puts "#{Tty.red}#{e.class.name}#{Tty.reset}: #{e}"
+ puts Formatter.error(e, label: e.class.name)
loop do
Menu.choose do |menu|
diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb
index 0ef4316d3..63f2dd648 100644
--- a/Library/Homebrew/descriptions.rb
+++ b/Library/Homebrew/descriptions.rb
@@ -124,7 +124,7 @@ class Descriptions
short_name = short_names[full_name]
printed_name = short_name_counts[short_name] == 1 ? short_name : full_name
description = @descriptions[full_name] || blank
- puts "#{Tty.white}#{printed_name}:#{Tty.reset} #{description}"
+ puts "#{Tty.bold}#{printed_name}:#{Tty.reset} #{description}"
end
end
diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb
index b2aa3b2c5..e5a6f4ebd 100644
--- a/Library/Homebrew/dev-cmd/bottle.rb
+++ b/Library/Homebrew/dev-cmd/bottle.rb
@@ -93,7 +93,7 @@ module Homebrew
next unless ARGV.verbose? && !text_matches.empty?
print_filename string, file
text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset|
- puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
+ puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.bold}0x#{offset}#{Tty.reset}"
end
if text_matches.size > MAXIMUM_STRING_MATCHES
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 07658c6e7..9810d8bfa 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -318,7 +318,7 @@ class BuildError < RuntimeError
def dump
if !ARGV.verbose?
puts
- puts "#{Tty.red}READ THIS#{Tty.reset}: #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}"
+ puts "#{Tty.red.underline}READ THIS#{Tty.reset.red}:#{Tty.reset} #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}"
if formula.tap
case formula.tap.name
when "homebrew/boneyard"
diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb
index 4f8cba1ce..7b53f2fd1 100644
--- a/Library/Homebrew/migrator.rb
+++ b/Library/Homebrew/migrator.rb
@@ -153,7 +153,7 @@ class Migrator
end
begin
- oh1 "Migrating #{Tty.green}#{oldname}#{Tty.white} to #{Tty.green}#{newname}#{Tty.reset}"
+ oh1 "Migrating #{Tty.green}#{oldname}#{Tty.reset} to #{Tty.green.bold}#{newname}#{Tty.reset}"
lock
unlink_oldname
move_to_new_directory
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb
index c88c0f416..a40a56775 100644
--- a/Library/Homebrew/test/test_utils.rb
+++ b/Library/Homebrew/test/test_utils.rb
@@ -5,8 +5,11 @@ require "utils/shell"
class TtyTests < Homebrew::TestCase
def test_strip_ansi
- assert_equal "hello",
- Tty.strip_ansi("\033\[36;7mhello\033\[0m")
+ assert_equal "hello", Tty.strip_ansi("\033\[36;7mhello\033\[0m")
+ end
+
+ def test_width
+ assert_kind_of Integer, Tty.width
end
def test_truncate
@@ -21,15 +24,26 @@ class TtyTests < Homebrew::TestCase
def test_no_tty_formatting
$stdout.stubs(:tty?).returns false
- assert_nil Tty.blue
- assert_nil Tty.white
- assert_nil Tty.red
- assert_nil Tty.green
- assert_nil Tty.gray
- assert_nil Tty.yellow
- assert_nil Tty.reset
- assert_nil Tty.em
- assert_nil Tty.highlight
+ assert_equal "", Tty.to_s
+ assert_equal "", Tty.red.to_s
+ assert_equal "", Tty.green.to_s
+ assert_equal "", Tty.yellow.to_s
+ assert_equal "", Tty.blue.to_s
+ assert_equal "", Tty.magenta.to_s
+ assert_equal "", Tty.cyan.to_s
+ assert_equal "", Tty.default.to_s
+ end
+
+ def test_formatting
+ $stdout.stubs(:tty?).returns(true)
+ assert_equal "", Tty.to_s
+ assert_equal "\033[31m", Tty.red.to_s
+ assert_equal "\033[32m", Tty.green.to_s
+ assert_equal "\033[33m", Tty.yellow.to_s
+ assert_equal "\033[34m", Tty.blue.to_s
+ assert_equal "\033[35m", Tty.magenta.to_s
+ assert_equal "\033[36m", Tty.cyan.to_s
+ assert_equal "\033[39m", Tty.default.to_s
end
end
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 58083fe1b..5c0aa601d 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -10,85 +10,11 @@ require "utils/git"
require "utils/analytics"
require "utils/github"
require "utils/curl"
-
-class Tty
- class << self
- def strip_ansi(string)
- string.gsub(/\033\[\d+(;\d+)*m/, "")
- end
-
- def blue
- bold 34
- end
-
- def white
- bold 39
- end
-
- def magenta
- bold 35
- end
-
- def red
- underline 31
- end
-
- def yellow
- underline 33
- end
-
- def reset
- escape 0
- end
-
- def em
- underline 39
- end
-
- def green
- bold 32
- end
-
- def gray
- bold 30
- end
-
- def highlight
- bold 39
- end
-
- def width
- `/usr/bin/tput cols`.strip.to_i
- end
-
- def truncate(str)
- w = width
- w > 10 ? str.to_s[0, w - 4] : str
- end
-
- private
-
- def color(n)
- escape "0;#{n}"
- end
-
- def bold(n)
- escape "1;#{n}"
- end
-
- def underline(n)
- escape "4;#{n}"
- end
-
- def escape(n)
- "\033[#{n}m" if $stdout.tty?
- end
- end
-end
+require "utils/tty"
def ohai(title, *sput)
title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose?
- puts "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}"
+ puts "#{Tty.blue}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}"
puts sput
end
@@ -96,16 +22,16 @@ def oh1(title, options = {})
if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto
title = Tty.truncate(title)
end
- puts "#{Tty.green}==>#{Tty.white} #{title}#{Tty.reset}"
+ puts "#{Tty.green}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}"
end
# Print a warning (do this rarely)
def opoo(warning)
- $stderr.puts "#{Tty.yellow}Warning#{Tty.reset}: #{warning}"
+ $stderr.puts "#{Tty.yellow.underline}Warnin#{Tty.reset.yellow}g:#{Tty.reset} #{warning}"
end
def onoe(error)
- $stderr.puts "#{Tty.red}Error#{Tty.reset}: #{error}"
+ $stderr.puts "#{Tty.red.underline}Error#{Tty.reset.red}:#{Tty.reset} #{error}"
end
def ofail(error)
@@ -171,9 +97,9 @@ def pretty_installed(f)
if !$stdout.tty?
f.to_s
elsif Emoji.enabled?
- "#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
+ "#{Tty.bold}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
else
- "#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
+ "#{Tty.green.bold}#{f} (installed)#{Tty.reset}"
end
end
@@ -181,9 +107,9 @@ def pretty_uninstalled(f)
if !$stdout.tty?
f.to_s
elsif Emoji.enabled?
- "#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
+ "#{Tty.bold}#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
else
- "#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
+ "#{Tty.red.bold}#{f} (uninstalled)#{Tty.reset}"
end
end
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index b7ec538f9..e71039e12 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -14,7 +14,7 @@ module GitHub
super <<-EOS.undent
GitHub API Error: #{error}
Try again in #{pretty_ratelimit_reset(reset)}, or create a personal access token:
- #{Tty.em}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset}
+ #{Tty.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset}
and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
EOS
end
@@ -30,7 +30,7 @@ module GitHub
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
message << <<-EOS.undent
HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check:
- #{Tty.em}https://github.com/settings/tokens#{Tty.reset}
+ #{Tty.underline}https://github.com/settings/tokens#{Tty.reset}
EOS
else
message << <<-EOS.undent
@@ -38,7 +38,7 @@ module GitHub
Clear them with:
printf "protocol=https\\nhost=github.com\\n" | git credential-osxkeychain erase
Or create a personal access token:
- #{Tty.em}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset}
+ #{Tty.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset}
and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
EOS
end
diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb
new file mode 100644
index 000000000..505165dc5
--- /dev/null
+++ b/Library/Homebrew/utils/tty.rb
@@ -0,0 +1,64 @@
+module Tty
+ module_function
+
+ def strip_ansi(string)
+ string.gsub(/\033\[\d+(;\d+)*m/, "")
+ end
+
+ def width
+ `/usr/bin/tput cols`.strip.to_i
+ end
+
+ def truncate(string)
+ (w = width).zero? ? string.to_s : string.to_s[0, w - 4]
+ end
+
+ COLOR_CODES = {
+ red: 31,
+ green: 32,
+ yellow: 33,
+ blue: 34,
+ magenta: 35,
+ cyan: 36,
+ default: 39,
+ }.freeze
+
+ STYLE_CODES = {
+ reset: 0,
+ bold: 1,
+ italic: 3,
+ underline: 4,
+ strikethrough: 9,
+ no_underline: 24,
+ }.freeze
+
+ CODES = COLOR_CODES.merge(STYLE_CODES).freeze
+
+ def append_to_escape_sequence(code)
+ @escape_sequence ||= []
+ @escape_sequence << code
+ self
+ end
+
+ def current_escape_sequence
+ return "" if @escape_sequence.nil?
+ "\033[#{@escape_sequence.join(";")}m"
+ end
+
+ def reset_escape_sequence!
+ @escape_sequence = nil
+ end
+
+ CODES.each do |name, code|
+ define_singleton_method(name) do
+ append_to_escape_sequence(code)
+ end
+ end
+
+ def to_s
+ return "" unless $stdout.tty?
+ current_escape_sequence
+ ensure
+ reset_escape_sequence!
+ end
+end