diff options
| author | Markus Reiter | 2016-10-02 05:36:50 +0200 |
|---|---|---|
| committer | GitHub | 2016-10-02 05:36:50 +0200 |
| commit | 8b06a01e5b94fec9876a4fdfea1177496a0b7c93 (patch) | |
| tree | 90ed60f4960de7642276534e568419f7d61d7c86 /Library/Homebrew/cask | |
| parent | fa14c262454c2678ca9c8a1caa2f0080833ac67a (diff) | |
| parent | 1eab17235ca80c86850d1079ccb255b076d4b557 (diff) | |
| download | brew-8b06a01e5b94fec9876a4fdfea1177496a0b7c93.tar.bz2 | |
Merge pull request #823 from reitermarkus/refactoring-tty
Refactor Tty.
Diffstat (limited to 'Library/Homebrew/cask')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/checkable.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/info.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/caveats.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/installer.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/utils.rb | 15 |
9 files changed, 33 insertions, 38 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 6095887e3..22124005c 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -79,13 +79,10 @@ module Hbc load_specification artifact_spec if target.exist? - target_abv = " (#{target.abv})" + "#{printable_target} (#{target.abv})" else - warning = "Missing #{self.class.artifact_english_name}" - warning = "#{Tty.red}#{warning}#{Tty.reset}: " + Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") end - - "#{warning}#{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 3ab45cccc..46dd42322 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) - - link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? - target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? + 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}#{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 42c47ea78..03f052629 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 34f000b29..e36999200 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 7fbdff3eb..0957ba4fd 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -18,16 +18,16 @@ 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) end def self.formatted_url(url) - "#{Tty.em}#{url}#{Tty.reset}" + "#{Tty.underline}#{url}#{Tty.reset}" end def self.installation_info(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/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/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index 5efd7d562..9dd9abab1 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/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index f0cc0d1a9..4d29acb75 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} " + 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 9159544a6..d42d78ef7 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -32,12 +32,7 @@ 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 Formatter.headline(title, color: :magenta) puts sput unless sput.empty? end @@ -151,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: + #{UPDATE_CMD} - #{Tty.green}#{UPDATE_CMD} - - #{Tty.reset}If this doesn’t fix the problem, please report this bug: - - #{Tty.em}#{ISSUES_URL}#{Tty.reset} + If this doesn’t fix the problem, please report this bug: + #{Formatter.url(ISSUES_URL)} EOS end |
