lib/grepg/formatter.rb in grepg-0.0.5 vs lib/grepg/formatter.rb in grepg-0.0.6

- old
+ new

@@ -1,22 +1,26 @@ require 'colorize' module GrepPage class Formatter # Displays an array of cheats # TODO: Highlight search term - DESCRIPTION_COLOR= :green - COMMAND_COLOR= :blue + DESCRIPTION_COLOR = :green + COMMAND_COLOR = :blue + NONE_FOUND_COLOR = :green + def self.cheat_rows(cheats, search_term, colorize) cheats.map do |cheat| description = cheat[:description] command = cheat[:command] - if colorize - description = description.colorize(DESCRIPTION_COLOR) - command = command.colorize(COMMAND_COLOR) - end - puts description - puts command + print description, DESCRIPTION_COLOR, colorize + print command, COMMAND_COLOR, colorize puts end + print "None found", NONE_FOUND_COLOR, colorize if cheats.size == 0 + end + + def self.print(text, color, colorize) + text = text.colorize(color) if colorize + puts text end end end