emoji: extract logic into generic OS classes. (#450)
This commit is contained in:
parent
4da990587f
commit
a5ec0aa259
24
Library/Homebrew/emoji.rb
Normal file
24
Library/Homebrew/emoji.rb
Normal 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"
|
||||
6
Library/Homebrew/extend/os/emoji.rb
Normal file
6
Library/Homebrew/extend/os/emoji.rb
Normal file
@ -0,0 +1,6 @@
|
||||
require "os"
|
||||
require "emoji"
|
||||
|
||||
if OS.mac?
|
||||
require "extend/os/mac/emoji"
|
||||
end
|
||||
7
Library/Homebrew/extend/os/mac/emoji.rb
Normal file
7
Library/Homebrew/extend/os/mac/emoji.rb
Normal file
@ -0,0 +1,7 @@
|
||||
module Emoji
|
||||
class << self
|
||||
def enabled?
|
||||
generic_enabled? && MacOS.version >= :lion
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user