Module: NerdQuiz::Color

Included in:
Quiz
Defined in:
lib/nerd_quiz/color.rb

Overview

Thanks to @wycats for Color class! github.com/wycats/thor

Constant Summary collapse

CLEAR =

Embed in a String to clear all previous ANSI sequences.

"\e[0m"
BOLD =

The start of an ANSI bold sequence.

"\e[1m"
BLACK =

Set the terminal’s foreground ANSI color to black.

"\e[30m"
RED =

Set the terminal’s foreground ANSI color to red.

"\e[31m"
GREEN =

Set the terminal’s foreground ANSI color to green.

"\e[32m"
YELLOW =

Set the terminal’s foreground ANSI color to yellow.

"\e[33m"
BLUE =

Set the terminal’s foreground ANSI color to blue.

"\e[34m"
MAGENTA =

Set the terminal’s foreground ANSI color to magenta.

"\e[35m"
CYAN =

Set the terminal’s foreground ANSI color to cyan.

"\e[36m"
WHITE =

Set the terminal’s foreground ANSI color to white.

"\e[37m"
ON_BLACK =

Set the terminal’s background ANSI color to black.

"\e[40m"
ON_RED =

Set the terminal’s background ANSI color to red.

"\e[41m"
ON_GREEN =

Set the terminal’s background ANSI color to green.

"\e[42m"
ON_YELLOW =

Set the terminal’s background ANSI color to yellow.

"\e[43m"
ON_BLUE =

Set the terminal’s background ANSI color to blue.

"\e[44m"
ON_MAGENTA =

Set the terminal’s background ANSI color to magenta.

"\e[45m"
ON_CYAN =

Set the terminal’s background ANSI color to cyan.

"\e[46m"
ON_WHITE =

Set the terminal’s background ANSI color to white.

"\e[47m"

Instance Method Summary collapse

Instance Method Details

#set_color(string, 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 Highline implementation and it automatically appends CLEAR to the end of the returned String.



49
50
51
52
53
# File 'lib/nerd_quiz/color.rb', line 49

def set_color(string, color, bold=false)
  color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
  bold  = bold ? BOLD : ""
  "#{bold}#{color}#{string}#{CLEAR}"
end