diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 3f73fcd2e1..992aca583d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -39,7 +39,7 @@ module Hbc end if exact_match ohai "Exact match" - puts exact_match + puts highlight_installed exact_match end return if partial_matches.empty? @@ -49,7 +49,12 @@ module Hbc else ohai "Partial matches" end - puts Formatter.columns(partial_matches) + puts Formatter.columns(partial_matches.map(&method(:highlight_installed))) + end + + def self.highlight_installed(token) + return token unless Cask.new(token).installed? + pretty_installed token end def self.help diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 0bcff809af..9843a6de67 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -56,4 +56,16 @@ describe Hbc::CLI::Search, :cask do Hbc::CLI::Search.run("caskroom") }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout end + + it "doesn't highlight packages that aren't installed" do + expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq("local-caffeine") + end + + it "highlights installed packages" do + shutup do + Hbc::CLI::Install.run("local-caffeine") + end + + expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq(pretty_installed("local-caffeine")) + end end