cask tty removed

This commit is contained in:
AnastasiaSulyagina 2016-08-23 09:11:09 +03:00
parent 0dbf485c4f
commit 65579f27dd
10 changed files with 20 additions and 146 deletions

View File

@ -35,6 +35,7 @@ require "hbc/url_checker"
require "hbc/utils"
require "hbc/verify"
require "hbc/version"
require "utils"
require "vendor/plist"

View File

@ -80,7 +80,7 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
target_abv = " (#{target.abv})"
else
warning = "Missing #{self.class.artifact_english_name}"
warning = "#{Hbc::Utils::Tty.red.underline}#{warning}#{Hbc::Utils::Tty.reset}: "
warning = "#{Tty.red}#{warning}#{Tty.reset}: "
end
"#{warning}#{printable_target}#{target_abv}"

View File

@ -57,7 +57,7 @@ class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated
return unless self.class.islink?(target)
link_description = "#{Hbc::Utils::Tty.red.underline}Broken Link#{Hbc::Utils::Tty.reset}: " unless target.exist?
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}"

View File

@ -27,11 +27,11 @@ module Hbc::Checkable
def result
if errors?
"#{Hbc::Utils::Tty.red.underline}failed#{Hbc::Utils::Tty.reset}"
"#{Tty.red}failed#{Tty.reset}"
elsif warnings?
"#{Hbc::Utils::Tty.yellow.underline}warning#{Hbc::Utils::Tty.reset}"
"#{Tty.yellow}warning#{Tty.reset}"
else
"#{Hbc::Utils::Tty.green}passed#{Hbc::Utils::Tty.reset}"
"#{Tty.green}passed#{Tty.reset}"
end
end
@ -39,11 +39,11 @@ module Hbc::Checkable
summary = ["#{summary_header}: #{result}"]
errors.each do |error|
summary << " #{Hbc::Utils::Tty.red}-#{Hbc::Utils::Tty.reset} #{error}"
summary << " #{Tty.red}-#{Tty.reset} #{error}"
end
warnings.each do |warning|
summary << " #{Hbc::Utils::Tty.yellow}-#{Hbc::Utils::Tty.reset} #{warning}"
summary << " #{Tty.yellow}-#{Tty.reset} #{warning}"
end
summary.join("\n")

View File

@ -124,11 +124,11 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
end
def self.notfound_string
"#{Hbc::Utils::Tty.red.underline}Not Found - Unknown Error#{Hbc::Utils::Tty.reset}"
"#{Tty.red}Not Found - Unknown Error#{Tty.reset}"
end
def self.error_string(string = "Error")
"#{Hbc::Utils::Tty.red.underline}(#{string})#{Hbc::Utils::Tty.reset}"
"#{Tty.red}(#{string})#{Tty.reset}"
end
def self.render_with_none(string)

View File

@ -25,7 +25,7 @@ class Hbc::CLI::Info < Hbc::CLI::Base
end
def self.formatted_url(url)
"#{Hbc::Utils::Tty.underline}#{url}#{Hbc::Utils::Tty.reset}"
"#{Tty.em}#{url}#{Tty.reset}"
end
def self.installation_info(cask)
@ -35,7 +35,7 @@ class Hbc::CLI::Info < Hbc::CLI::Base
puts versioned_staged_path.to_s
.concat(" (")
.concat(versioned_staged_path.exist? ? versioned_staged_path.abv : "#{Hbc::Utils::Tty.red}does not exist#{Hbc::Utils::Tty.reset}")
.concat(versioned_staged_path.exist? ? versioned_staged_path.abv : "#{Tty.red}does not exist#{Tty.reset}")
.concat(")")
end
else
@ -45,7 +45,7 @@ class Hbc::CLI::Info < Hbc::CLI::Base
def self.name_info(cask)
ohai cask.name.size > 1 ? "Names" : "Name"
puts cask.name.empty? ? "#{Hbc::Utils::Tty.red}None#{Hbc::Utils::Tty.reset}" : cask.name
puts cask.name.empty? ? "#{Tty.red}None#{Tty.reset}" : cask.name
end
def self.github_info(cask)

View File

@ -28,7 +28,7 @@ class Hbc::CLI::Style < Hbc::CLI::Base
begin
Homebrew.install_gem_setup_path! "rubocop-cask", RUBOCOP_CASK_VERSION, "rubocop"
rescue SystemExit
raise Hbc::CaskError, $stderr.string.chomp.sub("#{::Tty.red}Error#{::Tty.reset}: ", "")
raise Hbc::CaskError, $stderr.string.chomp.sub("#{Tty.red}Error#{Tty.reset}: ", "")
end
end
end

View File

@ -87,7 +87,7 @@ class Hbc::Installer
s = if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"]
(ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " "
else
"#{Hbc::Utils::Tty.blue.bold}==>#{Hbc::Utils::Tty.reset.bold} Success!#{Hbc::Utils::Tty.reset} "
"#{Tty.blue}==>#{Tty.reset} #{Tty.white}Success!#{Tty.reset} "
end
s << "#{@cask} was successfully installed!"
end

View File

@ -5,7 +5,6 @@ require "open3"
require "stringio"
require "hbc/utils/file"
require "hbc/utils/tty"
UPDATE_CMD = "brew uninstall --force brew-cask; brew untap phinze/cask; brew untap caskroom/cask; brew update; brew cleanup; brew cask cleanup".freeze
ISSUES_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs".freeze
@ -34,11 +33,11 @@ end
def odebug(title, *sput)
if Hbc.respond_to?(:debug) && Hbc.debug
width = Hbc::Utils::Tty.width * 4 - 6
width = Tty.width * 4 - 6
if $stdout.tty? && title.to_s.length > width
title = title.to_s[0, width - 3] + "..."
end
puts "#{Hbc::Utils::Tty.magenta.bold}==>#{Hbc::Utils::Tty.reset.bold} #{title}#{Hbc::Utils::Tty.reset}"
puts "#{Tty.magenta}==> #{title}#{Tty.reset}"
puts sput unless sput.empty?
end
end
@ -151,14 +150,13 @@ module Hbc::Utils
def self.error_message_with_suggestions
<<-EOS.undent
#{Hbc::Utils::Tty.reset.bold}
Most likely, this means you have an outdated version of Homebrew-Cask. Please run:
#{Hbc::Utils::Tty.green.normal}#{UPDATE_CMD}
#{Tty.green}#{UPDATE_CMD}
#{Hbc::Utils::Tty.reset.bold}If this doesnt fix the problem, please report this bug:
#{Tty.reset}If this doesnt fix the problem, please report this bug:
#{Hbc::Utils::Tty.underline}#{ISSUES_URL}#{Hbc::Utils::Tty.reset}
#{Tty.em}#{ISSUES_URL}#{Tty.reset}
EOS
end

View File

@ -1,125 +0,0 @@
# originally from Homebrew utils.rb
class Hbc::Utils::Tty
COLORS = {
black: 0,
red: 1,
green: 2,
yellow: 3,
blue: 4,
magenta: 5,
cyan: 6,
white: 7,
default: 9,
}.freeze
ATTRIBUTES = {
reset: 0,
bold: 1,
dim: 2,
italic: 3,
underline: 4,
blink: 5,
inverse: 7,
invisible: 8,
strikethrough: 9,
normal: 22,
}.freeze
@sequence = []
class << self
COLORS.keys.each do |sym|
define_method(sym) do
foreground(COLORS[sym])
end
define_method("fg_#{sym}".to_sym) do
foreground(COLORS[sym])
end
define_method("bg_#{sym}".to_sym) do
background(COLORS[sym])
end
end
ATTRIBUTES.keys.each do |sym|
define_method(sym) do
deferred_emit(ATTRIBUTES[sym])
end
end
def width
`/usr/bin/tput cols`.strip.to_i
end
def truncate(str)
str.to_s[0, width - 4]
end
private
def foreground(color)
deferred_emit(to_foreground_code(color))
end
def background(color)
deferred_emit(to_background_code(color))
end
def to_color_code(space, color)
return unless (num = to_color_number(color))
return space + num if num < space
return space + 9 if num > space
num
end
def to_foreground_code(color)
to_color_code(30, color)
end
def to_background_code(color)
to_color_code(40, color)
end
def to_color_number(color)
COLORS[color] || color.is_a?(Integer) ? color : nil
end
def to_attribute_number(attribute)
ATTRIBUTES[attribute] || attribute.is_a?(Integer) ? attribute : nil
end
def sanitize_integer(arg)
return arg.to_i if arg.is_a?(Integer)
return 0 if arg.to_s =~ %r{^0+$}
if arg.respond_to?(:to_i) && (int = arg.to_i) > 0
return int
end
$stderr.puts "Warning: bad Tty code #{arg}"
ATTRIBUTES[:reset]
end
def deferred_emit(*codes)
@sequence.concat Array(*codes).map(&method(:sanitize_integer))
Hbc::Utils::Tty
end
def to_s
sequence = @sequence
@sequence = []
return "" unless $stdout.tty?
if sequence.empty?
$stderr.puts "Warning: empty Tty sequence"
sequence = [ATTRIBUTES[:reset]]
end
"#{initiate}#{sequence.join(';')}#{terminate}"
end
def initiate
"\033["
end
def terminate
"m"
end
end
end