Module: Colorize::ClassMethods

Included in:
ColorizedString, String
Defined in:
lib/colorize/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#color_codesObject

Color codes hash


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/colorize/class_methods.rb', line 61

def color_codes
  {
    :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
  }
end

#color_matrix(_ = '') ⇒ Object

Method removed, raise NoMethodError


52
53
54
# File 'lib/colorize/class_methods.rb', line 52

def color_matrix(_ = '')
  fail NoMethodError, '#color_matrix method was removed, try #color_samples instead'
end

#color_methodsObject

Generate color and on_color methods


93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/colorize/class_methods.rb', line 93

def color_methods
  colors.each do |key|
    next if key == :default

    define_method key do
      colorize(:color => key)
    end

    define_method "on_#{key}" do
      colorize(:background => key)
    end
  end
end

#color_samplesObject

Display color samples


42
43
44
45
46
47
# File 'lib/colorize/class_methods.rb', line 42

def color_samples
  colors.permutation(2).each do |background, color|
    sample_text = "#{color.inspect.rjust(15)} on #{background.inspect.ljust(15)}"
    puts "#{new(sample_text).colorize(:color => color, :background => background)} #{sample_text}"
  end
end

#colorsObject

Return array of available colors used by colorize


28
29
30
# File 'lib/colorize/class_methods.rb', line 28

def colors
  color_codes.keys
end

#disable_colorization(value = nil) ⇒ Object

Property to disable colorization


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/colorize/class_methods.rb', line 6

def disable_colorization(value = nil)
  if value.nil?
    if defined?(@disable_colorization)
      @disable_colorization || false
    else
      false
    end
  else
    @disable_colorization = (value || false)
  end
end

#disable_colorization=(value) ⇒ Object

Setter for disable colorization


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

def disable_colorization=(value)
  @disable_colorization = (value || false)
end

#mode_codesObject

Mode codes hash


78
79
80
81
82
83
84
85
86
87
88
# File 'lib/colorize/class_methods.rb', line 78

def mode_codes
  {
    :default   => 0, # Turn off all attributes
    :bold      => 1, # Set bold mode
    :italic    => 3, # Set italic 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)
  }
end

#modesObject

Return array of available modes used by colorize


35
36
37
# File 'lib/colorize/class_methods.rb', line 35

def modes
  mode_codes.keys
end

#modes_methodsObject

Generate modes methods


110
111
112
113
114
115
116
117
118
# File 'lib/colorize/class_methods.rb', line 110

def modes_methods
  modes.each do |key|
    next if key == :default

    define_method key do
      colorize(:mode => key)
    end
  end
end