diff options
| author | Mike McQuaid | 2015-12-07 13:11:34 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2015-12-07 14:56:30 +0000 |
| commit | bf2315b1f4ae0cb7c9bb80b651ef6389f66020b2 (patch) | |
| tree | 5e155d3b7869721b2ce260c2d8229154745ce5a8 /Library/Homebrew/utils.rb | |
| parent | d603c03aa3dac553124d09e1e2b78dff8f408284 (diff) | |
| download | brew-bf2315b1f4ae0cb7c9bb80b651ef6389f66020b2.tar.bz2 | |
Use `(installed)` and emoji ticks consistently.
Across info, search and update.
Closes Homebrew/homebrew#45131.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 5700314f2..c874ec03c 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -9,6 +9,20 @@ require "open-uri" 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 + def blue bold 34 end @@ -103,6 +117,26 @@ def odie(error) exit 1 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) return "2 seconds" if s < 3 # avoids the plural problem ;) return "#{s.to_i} seconds" if s < 120 @@ -267,7 +301,7 @@ def curl(*args) safe_system curl, *args end -def puts_columns(items, highlight = []) +def puts_columns(items) return if items.empty? unless $stdout.tty? @@ -278,7 +312,8 @@ def puts_columns(items, highlight = []) # TTY case: If possible, output using multiple columns. console_width = Tty.width 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 gap_str = " " * 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 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 col_width = (console_width + col_gap) / cols - col_gap items = items.each_with_index.map do |item, index| |
