Module: Moon::Test::Colorize

Included in:
Colorizer, SpecSuite
Defined in:
lib/moon/packages/test/colorize.rb

Constant Summary collapse

CONSOLE_COLORS =

swiped from colorize.rb

{
  black:   0, light_black:   60,
  red:     1, light_red:     61,
  green:   2, light_green:   62,
  yellow:  3, light_yellow:  63,
  blue:    4, light_blue:    64,
  magenta: 5, light_magenta: 65,
  cyan:    6, light_cyan:    66,
  white:   7, light_white:   67,
  default: 9
}
CONSOLE_MODES =
{
  default:   0, # Turn off all attributes
  bold:      1, # Set bold mode
  underline: 4, # Set underline mode
  blink:     5, # Set blink mode
  swap:      7, # Exchange foreground and background colors
  hide:      8  # Hide text (foreground color would be the same as background)
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled


38
39
40
# File 'lib/moon/packages/test/colorize.rb', line 38

def enabled
  @enabled
end

Instance Attribute Details

#colorize_enabledObject

Returns the value of attribute colorize_enabled


26
27
28
# File 'lib/moon/packages/test/colorize.rb', line 26

def colorize_enabled
  @colorize_enabled
end

Instance Method Details

#colorize(str, fg, bg = :default, mode = :default) ⇒ Object


32
33
34
35
# File 'lib/moon/packages/test/colorize.rb', line 32

def colorize(str, fg, bg = :default, mode = :default)
  return str.dup unless colorize_enabled?
  "\033[#{CONSOLE_MODES[mode]};#{CONSOLE_COLORS[fg] + 30};#{CONSOLE_COLORS[bg] + 40}m#{str}\033[0m"
end

#colorize_enabled?Boolean

Returns:


28
29
30
# File 'lib/moon/packages/test/colorize.rb', line 28

def colorize_enabled?
  @colorize_enabled.nil? ? Colorize.enabled : @colorize_enabled
end