Use (installed) and emoji ticks consistently.
Across info, search and update. Closes Homebrew/homebrew#45131. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
d603c03aa3
commit
bf2315b1f4
@ -147,24 +147,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def decorate_dependencies(dependencies)
|
def decorate_dependencies(dependencies)
|
||||||
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
|
|
||||||
tick = ["2714".hex].pack("U*")
|
|
||||||
cross = ["2718".hex].pack("U*")
|
|
||||||
|
|
||||||
deps_status = dependencies.collect do |dep|
|
deps_status = dependencies.collect do |dep|
|
||||||
if dep.installed?
|
dep.installed? ? pretty_installed(dep) : pretty_uninstalled(dep)
|
||||||
color = Tty.green
|
|
||||||
symbol = tick
|
|
||||||
else
|
|
||||||
color = Tty.red
|
|
||||||
symbol = cross
|
|
||||||
end
|
|
||||||
if ENV["HOMEBREW_NO_EMOJI"]
|
|
||||||
colored_dep = "#{color}#{dep}"
|
|
||||||
else
|
|
||||||
colored_dep = "#{dep} #{color}#{symbol}"
|
|
||||||
end
|
|
||||||
"#{colored_dep}#{Tty.reset}"
|
|
||||||
end
|
end
|
||||||
deps_status * ", "
|
deps_status * ", "
|
||||||
end
|
end
|
||||||
|
|||||||
@ -42,8 +42,7 @@ module Homebrew
|
|||||||
query = ARGV.first
|
query = ARGV.first
|
||||||
rx = query_regexp(query)
|
rx = query_regexp(query)
|
||||||
local_results = search_formulae(rx)
|
local_results = search_formulae(rx)
|
||||||
local_results_installed = local_results.select { |f| f.end_with? "(installed)" }
|
puts_columns(local_results)
|
||||||
puts_columns(local_results, local_results_installed)
|
|
||||||
tap_results = search_taps(rx)
|
tap_results = search_taps(rx)
|
||||||
puts_columns(tap_results)
|
puts_columns(tap_results)
|
||||||
|
|
||||||
@ -157,7 +156,7 @@ module Homebrew
|
|||||||
if aliases.include?(name) && results.include?(canonical_full_name)
|
if aliases.include?(name) && results.include?(canonical_full_name)
|
||||||
next
|
next
|
||||||
elsif (HOMEBREW_CELLAR/canonical_name).directory?
|
elsif (HOMEBREW_CELLAR/canonical_name).directory?
|
||||||
"#{name} (installed)"
|
pretty_installed(name)
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|||||||
@ -455,30 +455,20 @@ class Report
|
|||||||
end
|
end
|
||||||
|
|
||||||
def dump_formula_report(key, title)
|
def dump_formula_report(key, title)
|
||||||
formula = select_formula(key)
|
formula = select_formula(key).map do |name, new_name|
|
||||||
unless formula.empty?
|
# Format list items of renamed formulae
|
||||||
# Determine list item indices of installed formulae.
|
|
||||||
formula_installed_index = formula.each_index.select do |index|
|
|
||||||
name, newname = formula[index]
|
|
||||||
installed?(name) || (newname && installed?(newname))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Format list items of renamed formulae.
|
|
||||||
if key == :R
|
if key == :R
|
||||||
formula.map! { |oldname, newname| "#{oldname} -> #{newname}" }
|
new_name = pretty_installed(new_name) if installed?(name)
|
||||||
|
"#{name} -> #{new_name}"
|
||||||
|
else
|
||||||
|
installed?(name) ? pretty_installed(name) : name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Append suffix '(installed)' to list items of installed formulae.
|
unless formula.empty?
|
||||||
formula_installed_index.each do |index|
|
|
||||||
formula[index] += " (installed)"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fetch list items of installed formulae for highlighting.
|
|
||||||
formula_installed = formula.values_at(*formula_installed_index)
|
|
||||||
|
|
||||||
# Dump formula list.
|
# Dump formula list.
|
||||||
ohai title
|
ohai title
|
||||||
puts_columns(formula, formula_installed)
|
puts_columns(formula)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,20 @@ require "open-uri"
|
|||||||
|
|
||||||
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)
|
||||||
|
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
||||||
|
end
|
||||||
|
|
||||||
def blue
|
def blue
|
||||||
bold 34
|
bold 34
|
||||||
end
|
end
|
||||||
@ -103,6 +117,26 @@ def odie(error)
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_installed(f)
|
||||||
|
if !$stdout.tty?
|
||||||
|
"#{f}"
|
||||||
|
elsif ENV["HOMEBREW_NO_EMOJI"]
|
||||||
|
"#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}"
|
||||||
|
else
|
||||||
|
"#{Tty.highlight}#{f} #{Tty.green}#{Tty.tick}#{Tty.reset}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pretty_uninstalled(f)
|
||||||
|
if !$stdout.tty?
|
||||||
|
"#{f}"
|
||||||
|
elsif ENV["HOMEBREW_NO_EMOJI"]
|
||||||
|
"#{Tty.red}#{f} (uninstalled)#{Tty.reset}"
|
||||||
|
else
|
||||||
|
"#{f} #{Tty.red}#{Tty.cross}#{Tty.reset}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pretty_duration(s)
|
def pretty_duration(s)
|
||||||
return "2 seconds" if s < 3 # avoids the plural problem ;)
|
return "2 seconds" if s < 3 # avoids the plural problem ;)
|
||||||
return "#{s.to_i} seconds" if s < 120
|
return "#{s.to_i} seconds" if s < 120
|
||||||
@ -267,7 +301,7 @@ def curl(*args)
|
|||||||
safe_system curl, *args
|
safe_system curl, *args
|
||||||
end
|
end
|
||||||
|
|
||||||
def puts_columns(items, highlight = [])
|
def puts_columns(items)
|
||||||
return if items.empty?
|
return if items.empty?
|
||||||
|
|
||||||
unless $stdout.tty?
|
unless $stdout.tty?
|
||||||
@ -278,7 +312,8 @@ def puts_columns(items, highlight = [])
|
|||||||
# TTY case: If possible, output using multiple columns.
|
# TTY case: If possible, output using multiple columns.
|
||||||
console_width = Tty.width
|
console_width = Tty.width
|
||||||
console_width = 80 if console_width <= 0
|
console_width = 80 if console_width <= 0
|
||||||
max_len = items.max_by(&:length).length
|
plain_item_lengths = items.map { |s| Tty.strip_ansi(s).length }
|
||||||
|
max_len = plain_item_lengths.max
|
||||||
col_gap = 2 # number of spaces between columns
|
col_gap = 2 # number of spaces between columns
|
||||||
gap_str = " " * col_gap
|
gap_str = " " * col_gap
|
||||||
cols = (console_width + col_gap) / (max_len + col_gap)
|
cols = (console_width + col_gap) / (max_len + col_gap)
|
||||||
@ -286,13 +321,6 @@ def puts_columns(items, highlight = [])
|
|||||||
rows = (items.size + cols - 1) / cols
|
rows = (items.size + cols - 1) / cols
|
||||||
cols = (items.size + rows - 1) / rows # avoid empty trailing columns
|
cols = (items.size + rows - 1) / rows # avoid empty trailing columns
|
||||||
|
|
||||||
plain_item_lengths = items.map(&:length) if cols >= 2
|
|
||||||
if highlight && highlight.any?
|
|
||||||
items = items.map do |item|
|
|
||||||
highlight.include?(item) ? "#{Tty.highlight}#{item}#{Tty.reset}" : item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cols >= 2
|
if cols >= 2
|
||||||
col_width = (console_width + col_gap) / cols - col_gap
|
col_width = (console_width + col_gap) / cols - col_gap
|
||||||
items = items.each_with_index.map do |item, index|
|
items = items.each_with_index.map do |item, index|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user