Module: ColorizedText

Defined in:
lib/colorized_text.rb

Overview

Colorizes text with ASCII colors.

Examples:

include ColorizedText

puts green "OK"          # => green output
puts bold "Running...    # => bold output
puts bold green "OK!!!"  # => bold green output

Instance Method Summary collapse

Instance Method Details

#bold(text) ⇒ Object

:nodoc:



31
32
33
# File 'lib/colorized_text.rb', line 31

def bold(text)
  colorize(text, 1)
end

#colorize(text, code) ⇒ Object

Colorize text using ASCII color code



11
12
13
# File 'lib/colorized_text.rb', line 11

def colorize(text, code)
  "\033[#{code}m#{text}\033[0m"
end

#green(text) ⇒ Object

:nodoc:



21
22
23
# File 'lib/colorized_text.rb', line 21

def green(text)
  colorize(text, 32)
end

#red(text) ⇒ Object

:nodoc:



26
27
28
# File 'lib/colorized_text.rb', line 26

def red(text)
  colorize(text, 31)
end

#yellow(text) ⇒ Object

:nodoc:



16
17
18
# File 'lib/colorized_text.rb', line 16

def yellow(text)
  colorize(text, 33)
end