From 6d8ee395fa5878282a1ce3975b632103448be042 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 26 Aug 2016 16:04:47 +0200 Subject: [PATCH 1/4] Refactor Tty. --- Library/Homebrew/brew.rb | 4 +- .../Homebrew/cask/lib/hbc/artifact/moved.rb | 5 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 2 +- Library/Homebrew/cask/lib/hbc/utils.rb | 11 +-- Library/Homebrew/cmd/doctor.rb | 2 +- Library/Homebrew/cmd/help.rb | 10 +- Library/Homebrew/cmd/info.rb | 4 +- Library/Homebrew/cmd/update-report.rb | 2 +- Library/Homebrew/debrew.rb | 2 +- Library/Homebrew/descriptions.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 2 +- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/migrator.rb | 2 +- Library/Homebrew/test/test_utils.rb | 36 +++++--- Library/Homebrew/utils.rb | 92 ++----------------- Library/Homebrew/utils/github.rb | 6 +- Library/Homebrew/utils/tty.rb | 64 +++++++++++++ 19 files changed, 125 insertions(+), 127 deletions(-) create mode 100644 Library/Homebrew/utils/tty.rb diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 1ba3fb8c26..4ea830806a 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 6095887e3d..ff6e5f273e 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 7fbdff3ebb..e2f3602964 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 66117da8b6..bb179fb0c5 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 f0cc0d1a9d..1002be4605 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 9159544a63..c6a970fcac 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 89f32dc25f..e6b5fcba07 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 2a814b90ba..05a3003cc8 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 6f242039cc..9721585cfd 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 18f2f370ca..c275606e28 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 1c5047a8c9..668a0b4d22 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 0ef4316d34..63f2dd6489 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 b2aa3b2c50..e5a6f4ebdf 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 07658c6e7f..9810d8bfad 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 4f8cba1ce0..7b53f2fd19 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 c88c0f4169..a40a567759 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 58083fe1be..5c0aa601d2 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 b7ec538f9f..e71039e12f 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 0000000000..505165dc53 --- /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 From 75e8b59aad4814112a53119f68ed629d60b3f97b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 30 Aug 2016 21:38:13 +0200 Subject: [PATCH 2/4] Add `Formatter` module. --- Library/Homebrew/brew.rb | 4 +- .../Homebrew/cask/lib/hbc/artifact/moved.rb | 6 +-- .../cask/lib/hbc/artifact/symlinked.rb | 15 ++++-- Library/Homebrew/cask/lib/hbc/checkable.rb | 10 ++-- Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 4 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 8 +-- Library/Homebrew/cask/lib/hbc/installer.rb | 2 +- Library/Homebrew/cask/lib/hbc/utils.rb | 8 ++- Library/Homebrew/cmd/doctor.rb | 6 +-- Library/Homebrew/cmd/info.rb | 4 +- Library/Homebrew/descriptions.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 2 +- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/formula_installer.rb | 6 +-- Library/Homebrew/migrator.rb | 6 +-- Library/Homebrew/utils.rb | 21 ++++---- Library/Homebrew/utils/formatter.rb | 52 +++++++++++++++++++ Library/Homebrew/utils/github.rb | 6 +-- 18 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 Library/Homebrew/utils/formatter.rb diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 4ea830806a..c4a34d2981 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 "Please report this bug:" - $stderr.puts " #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}" + $stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}" + $stderr.puts " #{Formatter.url(OS::ISSUES_URL)}" 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 ff6e5f273e..22124005c7 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -79,12 +79,10 @@ module Hbc load_specification artifact_spec if target.exist? - target_abv = " (#{target.abv})" + "#{printable_target} (#{target.abv})" else - error = "#{Tty.red}Missing #{self.class.artifact_english_name}:#{Tty.reset} " + Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") end - - "#{error}#{printable_target}#{target_abv}" end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb index 3ab45cccc1..46dd42322a 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb @@ -57,12 +57,17 @@ module Hbc def summarize_artifact(artifact_spec) load_specification artifact_spec - return unless self.class.islink?(target) + if self.class.islink?(target) && target.exist? && target.readlink.exist? + "#{printable_target} -> #{target.readlink} (#{target.readlink.abv})" + else + string = if self.class.islink?(target) + "#{printable_target} -> #{target.readlink}" + else + printable_target + end - link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? - target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? - - "#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}" + Formatter.error(string, label: "Broken Link") + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/checkable.rb b/Library/Homebrew/cask/lib/hbc/checkable.rb index 42c47ea78b..03f0526292 100644 --- a/Library/Homebrew/cask/lib/hbc/checkable.rb +++ b/Library/Homebrew/cask/lib/hbc/checkable.rb @@ -28,11 +28,11 @@ module Hbc def result if errors? - "#{Tty.red}failed#{Tty.reset}" + Formatter.error("failed") elsif warnings? - "#{Tty.yellow}warning#{Tty.reset}" + Formatter.warning("warning") else - "#{Tty.green}passed#{Tty.reset}" + Formatter.success("passed") end end @@ -40,11 +40,11 @@ module Hbc summary = ["#{summary_header}: #{result}"] errors.each do |error| - summary << " #{Tty.red}-#{Tty.reset} #{error}" + summary << " #{Formatter.error("-")} #{error}" end warnings.each do |warning| - summary << " #{Tty.yellow}-#{Tty.reset} #{warning}" + summary << " #{Formatter.warning("-")} #{warning}" end summary.join("\n") diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 34f000b29e..e36999200d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -122,11 +122,11 @@ module Hbc end def self.notfound_string - "#{Tty.red}Not Found - Unknown Error#{Tty.reset}" + Formatter.error("Not Found - Unknown Error") end def self.error_string(string = "Error") - "#{Tty.red}(#{string})#{Tty.reset}" + Formatter.error("(#{string})") end def self.render_with_none(string) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index e2f3602964..0957ba4fd0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -18,9 +18,9 @@ module Hbc def self.info(cask) puts "#{cask.token}: #{cask.version}" - puts formatted_url(cask.homepage) if cask.homepage + puts Formatter.url(cask.homepage) if cask.homepage installation_info(cask) - puts "From: #{formatted_url(github_info(cask))}" if github_info(cask) + puts "From: #{Formatter.url(github_info(cask))}" if github_info(cask) name_info(cask) artifact_info(cask) Installer.print_caveats(cask) @@ -37,7 +37,7 @@ module Hbc puts versioned_staged_path.to_s .concat(" (") - .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : "#{Tty.red}does not exist#{Tty.reset}") + .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist")) .concat(")") end else @@ -47,7 +47,7 @@ module Hbc def self.name_info(cask) ohai cask.name.size > 1 ? "Names" : "Name" - puts cask.name.empty? ? "#{Tty.red}None#{Tty.reset}" : cask.name + puts cask.name.empty? ? Formatter.error("None") : cask.name end def self.github_info(cask) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 1002be4605..4d29acb752 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.bold}Success!#{Tty.reset} " + Formatter.headline("Success! ", color: :blue) 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 c6a970fcac..d42d78ef70 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -32,7 +32,7 @@ end def odebug(title, *sput) return unless Hbc.respond_to?(:debug) return unless Hbc.debug - puts "#{Tty.magenta}==>#{Tty.reset} #{Tty.white}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :magenta) puts sput unless sput.empty? end @@ -146,12 +146,10 @@ module Hbc def self.error_message_with_suggestions <<-EOS.undent Most likely, this means you have an outdated version of Homebrew-Cask. Please run: - - #{Tty.green}#{UPDATE_CMD}#{Tty.reset} + #{UPDATE_CMD} If this doesn’t fix the problem, please report this bug: - - #{Tty.underline}#{ISSUES_URL}#{Tty.reset} + #{Formatter.url(ISSUES_URL)} EOS end diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index e6b5fcba07..0fcd3a74df 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -42,9 +42,9 @@ module Homebrew next if out.nil? || out.empty? if first_warning $stderr.puts <<-EOS.undent - #{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} + #{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 end diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 9721585cfd..2cfb89ea55 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.underline}#{f.homepage}#{Tty.reset}" if f.homepage + puts Formatter.url(f.homepage) 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.underline}#{github_info(f)}#{Tty.reset}" + puts "From: #{Formatter.url(github_info(f))}" unless f.deps.empty? ohai "Dependencies" diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index 63f2dd6489..cc690c050e 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -119,7 +119,7 @@ class Descriptions # Take search results -- a hash mapping formula names to descriptions -- and # print them. def print - blank = "#{Tty.yellow}[no description]#{Tty.reset}" + blank = Formatter.warning("[no description]") @descriptions.keys.sort.each do |full_name| short_name = short_names[full_name] printed_name = short_name_counts[short_name] == 1 ? short_name : full_name diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index e5a6f4ebdf..8c6d3e5646 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -54,7 +54,7 @@ module Homebrew return if @put_filenames.include? filename - puts "#{Tty.red}#{filename}#{Tty.reset}" + puts Formatter.error(filename.to_s) @put_filenames << filename end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 9810d8bfad..601bde5285 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.underline}READ THIS#{Tty.reset.red}:#{Tty.reset} #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}" + puts Formatter.error("READ THIS: #{Formatter.url(OS::ISSUES_URL)}") if formula.tap case formula.tap.name when "homebrew/boneyard" diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 652f87ae37..09c11318ee 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -214,7 +214,7 @@ class FormulaInstaller opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!" end - oh1 "Installing #{Tty.green}#{formula.full_name}#{Tty.reset}" if show_header? + oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header? if formula.tap && !formula.tap.private? options = [] @@ -426,7 +426,7 @@ class FormulaInstaller if deps.empty? && only_deps? puts "All dependencies for #{formula.full_name} are satisfied." elsif !deps.empty? - oh1 "Installing dependencies for #{formula.full_name}: #{Tty.green}#{deps.map(&:first)*", "}#{Tty.reset}", + oh1 "Installing dependencies for #{formula.full_name}: #{deps.map(&:first).map(&Formatter.method(:identifier)).join(", ")}", truncate: false deps.each { |dep, options| install_dependency(dep, options) } end @@ -476,7 +476,7 @@ class FormulaInstaller fi.verbose = verbose? && !quieter? fi.debug = debug? fi.prelude - oh1 "Installing #{formula.full_name} dependency: #{Tty.green}#{dep.name}#{Tty.reset}" + oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish rescue Exception diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 7b53f2fd19..fe480cd3b6 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.reset} to #{Tty.green.bold}#{newname}#{Tty.reset}" + oh1 "Migrating #{Formatter.identifier(oldname)} to #{Formatter.identifier(newname)}" lock unlink_oldname move_to_new_directory @@ -200,7 +200,7 @@ class Migrator end def unlink_oldname - oh1 "Unlinking #{Tty.green}#{oldname}#{Tty.reset}" + oh1 "Unlinking #{Formatter.identifier(oldname)}" old_cellar.subdirs.each do |d| keg = Keg.new(d) keg.unlink @@ -208,7 +208,7 @@ class Migrator end def link_newname - oh1 "Linking #{Tty.green}#{newname}#{Tty.reset}" + oh1 "Linking #{Formatter.identifier(newname)}" new_keg = Keg.new(new_linked_keg_record) # If old_keg wasn't linked then we just optlink a keg. diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 5c0aa601d2..8d91c15c0d 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -1,6 +1,7 @@ require "pathname" require "emoji" require "exceptions" +require "utils/formatter" require "utils/hash" require "utils/json" require "utils/inreplace" @@ -14,7 +15,7 @@ require "utils/tty" def ohai(title, *sput) title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? - puts "#{Tty.blue}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :blue) puts sput end @@ -22,16 +23,16 @@ def oh1(title, options = {}) if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto title = Tty.truncate(title) end - puts "#{Tty.green}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :green) end # Print a warning (do this rarely) -def opoo(warning) - $stderr.puts "#{Tty.yellow.underline}Warnin#{Tty.reset.yellow}g:#{Tty.reset} #{warning}" +def opoo(message) + $stderr.puts Formatter.warning(message, label: "Warning") end -def onoe(error) - $stderr.puts "#{Tty.red.underline}Error#{Tty.reset.red}:#{Tty.reset} #{error}" +def onoe(message) + $stderr.puts Formatter.error(message, label: "Error") end def ofail(error) @@ -97,9 +98,9 @@ def pretty_installed(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.success(Emoji.tick)}#{Tty.reset}" else - "#{Tty.green.bold}#{f} (installed)#{Tty.reset}" + Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}") end end @@ -107,9 +108,9 @@ def pretty_uninstalled(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.error(Emoji.cross)}#{Tty.reset}" else - "#{Tty.red.bold}#{f} (uninstalled)#{Tty.reset}" + Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}") end end diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb new file mode 100644 index 0000000000..cb4f041f43 --- /dev/null +++ b/Library/Homebrew/utils/formatter.rb @@ -0,0 +1,52 @@ +require "utils/tty" + +module Formatter + module_function + + def arrow(string, color: nil) + prefix("==>", string, color) + end + + def headline(string, color: nil) + arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color) + end + + def identifier(string) + "#{Tty.green}#{string}#{Tty.reset}" + end + + def success(string, label: nil) + label(label, string, :green) + end + + def warning(string, label: nil) + label(label, string, :yellow) + end + + def error(string, label: nil) + label(label, string, :red) + end + + def url(string) + "#{Tty.underline}#{string}#{Tty.no_underline}" + end + + def label(label, string, color) + label = "#{label}:" unless label.nil? + prefix(label, string, color) + end + private_class_method :label + + def prefix(prefix, string, color) + if prefix.nil? && color.nil? + string + elsif prefix.nil? + "#{Tty.send(color)}#{string}#{Tty.reset}" + elsif color.nil? + "#{prefix} #{string}" + else + "#{Tty.send(color)}#{prefix}#{Tty.reset} #{string}" + end + end + private_class_method :prefix +end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index e71039e12f..1443a93361 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.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} 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.underline}https://github.com/settings/tokens#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens")} 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.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token" EOS end From 884b26850615d5624e09762e1ae8bc5b104a934a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 17 Sep 2016 03:21:51 +0200 Subject: [PATCH 3/4] Use Formatter for all URLs. --- Library/Homebrew/blacklist.rb | 10 +++++----- Library/Homebrew/cask/lib/hbc/dsl/caveats.rb | 6 +++--- Library/Homebrew/cmd/help.rb | 11 ++++++----- Library/Homebrew/cmd/update-report.rb | 2 +- Library/Homebrew/diagnostic.rb | 12 ++++++------ Library/Homebrew/exceptions.rb | 4 ++-- Library/Homebrew/requirements.rb | 2 +- Library/Homebrew/utils/github.rb | 4 ++-- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Library/Homebrew/blacklist.rb b/Library/Homebrew/blacklist.rb index 4312d0bf3b..1c79da1593 100644 --- a/Library/Homebrew/blacklist.rb +++ b/Library/Homebrew/blacklist.rb @@ -16,7 +16,7 @@ def blacklisted?(name) Homebrew provides pip via: `brew install python`. However you will then have two Pythons installed on your Mac, so alternatively you can install pip via the instructions at: - https://pip.readthedocs.io/en/stable/installing/ + #{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")} EOS when "pil" then <<-EOS.undent Instead of PIL, consider `pip install pillow` or `brew install Homebrew/python/pillow`. @@ -24,7 +24,7 @@ def blacklisted?(name) when "macruby" then <<-EOS.undent MacRuby is not packaged and is on an indefinite development hiatus. You can read more about it at: - https://github.com/MacRuby/MacRuby + #{Formatter.url("https://github.com/MacRuby/MacRuby")} EOS when /(lib)?lzma/ "lzma is now part of the xz formula." @@ -50,7 +50,7 @@ def blacklisted?(name) To install Clojure you should install Leiningen: brew install leiningen and then follow the tutorial: - https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md + #{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")} EOS when "osmium" then <<-EOS.undent The creator of Osmium requests that it not be packaged and that people @@ -65,8 +65,8 @@ def blacklisted?(name) brew install typesafe-activator You can read more about this change at: - https://www.playframework.com/documentation/2.3.x/Migration23 - https://www.playframework.com/documentation/2.3.x/Highlights23 + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Migration23")} + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Highlights23")} EOS when "haskell-platform" then <<-EOS.undent We no longer package haskell-platform. Consider installing ghc diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index 5efd7d5621..9dd9abab1c 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb @@ -102,12 +102,12 @@ module Hbc A report has been made to Apple about this app. Their certificate will hopefully be revoked. See the public report at - https://openradar.appspot.com/#{radar_number} + #{Formatter.url("https://openradar.appspot.com/#{radar_number}")} If this report is accurate, please duplicate it at - https://bugreport.apple.com/ + #{Formatter.url("https://bugreport.apple.com/")} If this report is a mistake, please let us know by opening an issue at - https://github.com/caskroom/homebrew-cask/issues/new + #{Formatter.url("https://github.com/caskroom/homebrew-cask/issues/new")} EOS end diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb index 05a3003cc8..c8845b086e 100644 --- a/Library/Homebrew/cmd/help.rb +++ b/Library/Homebrew/cmd/help.rb @@ -78,11 +78,12 @@ module Homebrew HOMEBREW_HELP else help_lines.map do |line| - 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", "") + line.slice(2..-1) + .sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} ") + .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}") + .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) } + .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}") + .gsub("@hide_from_man_page", "") end.join.strip end end diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index c275606e28..f97191bdaf 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -288,7 +288,7 @@ module Homebrew Please try to resolve this error yourself and then run `brew update` again to complete the migration. If you need help please +1 an existing error or comment with your new error in issue: - #{Tty.em}https://github.com/Homebrew/brew/issues/987#{Tty.reset} + #{Formatter.url("https://github.com/Homebrew/brew/issues/987")} EOS $stderr.puts e.backtrace end diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index ca8ade9ff8..6546714e87 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -473,7 +473,7 @@ module Homebrew If you have trouble downloading packages with Homebrew, then maybe this is the problem? If the following command doesn't work, then try removing your curlrc: - curl https://github.com + curl #{Formatter.url("https://github.com")} EOS end @@ -610,7 +610,7 @@ module Homebrew Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. Having this set is common if you use this software: - http://asepsis.binaryage.com/ + #{Formatter.url("http://asepsis.binaryage.com/")} EOS end @@ -752,7 +752,7 @@ module Homebrew Without a correctly configured origin, Homebrew won't update properly. You can solve this by adding the Homebrew remote: cd #{HOMEBREW_REPOSITORY} - git remote add origin https://github.com/Homebrew/brew.git + git remote add origin #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS elsif origin !~ %r{Homebrew/brew(\.git)?$} <<-EOS.undent @@ -764,7 +764,7 @@ module Homebrew Unless you have compelling reasons, consider setting the origin remote to point at the main repository, located at: - https://github.com/Homebrew/brew.git + #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS end end @@ -956,8 +956,8 @@ module Homebrew <<-EOS.undent A .pydistutils.cfg file was found in $HOME, which may cause Python builds to fail. See: - https://bugs.python.org/issue6138 - https://bugs.python.org/issue4655 + #{Formatter.url("https://bugs.python.org/issue6138")} + #{Formatter.url("https://bugs.python.org/issue4655")} EOS end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 601bde5285..e01a60c758 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 Formatter.error("READ THIS: #{Formatter.url(OS::ISSUES_URL)}") + puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS") if formula.tap case formula.tap.name when "homebrew/boneyard" @@ -327,7 +327,7 @@ class BuildError < RuntimeError else if issues_url = formula.tap.issues_url puts "If reporting this issue please do so at (not Homebrew/brew):" - puts " #{issues_url}" + puts " #{Formatter.url(issues_url)}" end end end diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index 274ba5c9b8..87b315cb76 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -44,7 +44,7 @@ class XcodeRequirement < Requirement EOS else message + <<-EOS.undent - Xcode can be installed from https://developer.apple.com/xcode/downloads/ + Xcode can be installed from #{Formatter.url("https://developer.apple.com/xcode/downloads/")} EOS end end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 1443a93361..5611f9aadd 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -106,14 +106,14 @@ module GitHub onoe <<-EOS.undent Your macOS keychain GitHub credentials do not have sufficient scope! Scopes they have: #{credentials_scopes} - Create a personal access token: https://github.com/settings/tokens + Create a personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS when :environment onoe <<-EOS.undent Your HOMEBREW_GITHUB_API_TOKEN does not have sufficient scope! Scopes it has: #{credentials_scopes} - Create a new personal access token: https://github.com/settings/tokens + Create a new personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set the new HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS end From 1eab17235ca80c86850d1079ccb255b076d4b557 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Oct 2016 20:15:17 +0200 Subject: [PATCH 4/4] Add temporary compatibility layer for `Tty.white`. --- Library/Homebrew/compat.rb | 1 + Library/Homebrew/compat/utils.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index eabc7dfa0e..98624aebd7 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -15,3 +15,4 @@ require "compat/dependency_collector" require "compat/language/haskell" require "compat/xcode" require "compat/software_spec" +require "compat/utils" diff --git a/Library/Homebrew/compat/utils.rb b/Library/Homebrew/compat/utils.rb index 7de5e85c32..7b529f04e3 100644 --- a/Library/Homebrew/compat/utils.rb +++ b/Library/Homebrew/compat/utils.rb @@ -8,3 +8,11 @@ def shell_profile else "~/.bash_profile" end end + +module Tty + module_function + + def white + reset.bold + end +end