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 "debrew"
|
||||||
require "sandbox"
|
require "sandbox"
|
||||||
require "requirements/cctools_requirement"
|
require "requirements/cctools_requirement"
|
||||||
|
require "emoji"
|
||||||
|
|
||||||
class FormulaInstaller
|
class FormulaInstaller
|
||||||
include FormulaCellarChecks
|
include FormulaCellarChecks
|
||||||
@ -492,13 +493,9 @@ class FormulaInstaller
|
|||||||
unlock
|
unlock
|
||||||
end
|
end
|
||||||
|
|
||||||
def emoji
|
|
||||||
ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba"
|
|
||||||
end
|
|
||||||
|
|
||||||
def summary
|
def summary
|
||||||
s = ""
|
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 << "#{formula.prefix}: #{formula.prefix.abv}"
|
||||||
s << ", built in #{pretty_duration build_time}" if build_time
|
s << ", built in #{pretty_duration build_time}" if build_time
|
||||||
s
|
s
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
require "pathname"
|
require "pathname"
|
||||||
|
require "emoji"
|
||||||
require "exceptions"
|
require "exceptions"
|
||||||
require "utils/hash"
|
require "utils/hash"
|
||||||
require "utils/json"
|
require "utils/json"
|
||||||
@ -12,16 +13,6 @@ require "utils/curl"
|
|||||||
|
|
||||||
class Tty
|
class Tty
|
||||||
class << self
|
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)
|
def strip_ansi(string)
|
||||||
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
||||||
end
|
end
|
||||||
@ -124,20 +115,20 @@ end
|
|||||||
def pretty_installed(f)
|
def pretty_installed(f)
|
||||||
if !$stdout.tty?
|
if !$stdout.tty?
|
||||||
"#{f}"
|
"#{f}"
|
||||||
elsif ENV["HOMEBREW_NO_EMOJI"]
|
elsif Emoji.enabled?
|
||||||
"#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
|
"#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
|
||||||
else
|
else
|
||||||
"#{Tty.highlight}#{f} #{Tty.green}#{Tty.tick}#{Tty.reset}"
|
"#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_uninstalled(f)
|
def pretty_uninstalled(f)
|
||||||
if !$stdout.tty?
|
if !$stdout.tty?
|
||||||
"#{f}"
|
"#{f}"
|
||||||
elsif ENV["HOMEBREW_NO_EMOJI"]
|
elsif Emoji.enabled?
|
||||||
"#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
|
"#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
|
||||||
else
|
else
|
||||||
"#{f} #{Tty.red}#{Tty.cross}#{Tty.reset}"
|
"#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user