emoji: extract logic into generic OS classes. (#450)

This commit is contained in:
Mike McQuaid 2016-07-09 13:51:43 +01:00 committed by GitHub
parent 4da990587f
commit a5ec0aa259
5 changed files with 46 additions and 21 deletions

24
Library/Homebrew/emoji.rb Normal file
View File

@ -0,0 +1,24 @@
module Emoji
class << self
def tick
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
@tick ||= ["2714".hex].pack("U*")
end
def cross
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
@cross ||= ["2718".hex].pack("U*")
end
def install_badge
ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba"
end
def enabled?
!ENV["HOMEBREW_NO_EMOJI"]
end
alias generic_enabled? enabled?
end
end
require "extend/os/emoji"

View File

@ -0,0 +1,6 @@
require "os"
require "emoji"
if OS.mac?
require "extend/os/mac/emoji"
end

View File

@ -0,0 +1,7 @@
module Emoji
class << self
def enabled?
generic_enabled? && MacOS.version >= :lion
end
end
end

View File

@ -13,6 +13,7 @@ require "hooks/bottles"
require "debrew"
require "sandbox"
require "requirements/cctools_requirement"
require "emoji"
class FormulaInstaller
include FormulaCellarChecks
@ -492,13 +493,9 @@ class FormulaInstaller
unlock
end
def emoji
ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba"
end
def summary
s = ""
s << "#{emoji} " if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"]
s << "#{Emoji.install_badge} " if Emoji.enabled?
s << "#{formula.prefix}: #{formula.prefix.abv}"
s << ", built in #{pretty_duration build_time}" if build_time
s

View File

@ -1,4 +1,5 @@
require "pathname"
require "emoji"
require "exceptions"
require "utils/hash"
require "utils/json"
@ -12,16 +13,6 @@ require "utils/curl"
class Tty
class << self
def tick
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
@tick ||= ["2714".hex].pack("U*")
end
def cross
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
@cross ||= ["2718".hex].pack("U*")
end
def strip_ansi(string)
string.gsub(/\033\[\d+(;\d+)*m/, "")
end
@ -124,20 +115,20 @@ end
def pretty_installed(f)
if !$stdout.tty?
"#{f}"
elsif ENV["HOMEBREW_NO_EMOJI"]
"#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
elsif Emoji.enabled?
"#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
else
"#{Tty.highlight}#{f} #{Tty.green}#{Tty.tick}#{Tty.reset}"
"#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
end
end
def pretty_uninstalled(f)
if !$stdout.tty?
"#{f}"
elsif ENV["HOMEBREW_NO_EMOJI"]
"#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
elsif Emoji.enabled?
"#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
else
"#{f} #{Tty.red}#{Tty.cross}#{Tty.reset}"
"#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
end
end