Module: TermColor

Defined in:
lib/term_color.rb

Overview

Just some methods for outputting colorized text to a terminal with ansi codes, cribbed from rails.

Constant Summary collapse

CLEAR =

Embed in a String to clear all previous ANSI sequences.

"\e[0m"
BOLD =
"\e[1m"
BLACK =

Colors

"\e[30m"
RED =
"\e[31m"
GREEN =
"\e[32m"
YELLOW =
"\e[33m"
BLUE =
"\e[34m"
MAGENTA =
"\e[35m"
CYAN =
"\e[36m"
WHITE =
"\e[37m"

Class Method Summary collapse

Class Method Details

.color(text, color, bold = false) ⇒ Object

Set color by using a string or one of the defined constants. If a third option is set to true, it also adds bold to the string. This is based on the Highline implementation and will automatically append CLEAR to the end of the returned String.



34
35
36
37
38
39
# File 'lib/term_color.rb', line 34

def self.color(text, color, bold=false)
  return text unless colorize_logging
  color = self.const_get(color.to_s.upcase) if color.is_a?(Symbol)
  bold  = bold ? BOLD : ""
  "#{bold}#{color}#{text}#{CLEAR}"
end