colorize 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/{History.txt → CHANGELOG.rdoc} +4 -0
- data/{README.txt → README.rdoc} +4 -4
- data/Rakefile +13 -22
- data/VERSION +1 -0
- data/colorize.gemspec +49 -0
- data/lib/colorize.rb +190 -3
- metadata +50 -51
- data/Manifest.txt +0 -8
- data/lib/colorize/colorize.rb +0 -188
data/.gitignore
ADDED
data/{README.txt → README.rdoc}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
colorize
|
2
|
-
|
3
|
-
http://
|
1
|
+
== colorize
|
2
|
+
http://colorize.rubyforge.org
|
3
|
+
http://fazibear.prv.pl
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
Ruby string class extension. It add some methods to set color, background color and text effect on console easier
|
7
|
+
Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences.
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
data/Rakefile
CHANGED
@@ -1,26 +1,17 @@
|
|
1
|
-
# -*- ruby -*-
|
2
1
|
require 'rubygems'
|
3
|
-
require '
|
4
|
-
require "#{File.dirname(__FILE__)}/lib/colorize.rb"
|
2
|
+
require 'rake'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gemspec|
|
7
|
+
gemspec.name = "colorize"
|
8
|
+
gemspec.summary = "Add colors methods to string class"
|
9
|
+
gemspec.email = "fazibear@gmail.com"
|
10
|
+
gemspec.homepage = "http://github.com/fazibear/colorize"
|
11
|
+
gemspec.description = "Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences."
|
12
|
+
gemspec.authors = ["fazibear"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
16
|
end
|
18
17
|
|
19
|
-
desc "Generate Manifest.new for dist"
|
20
|
-
task :manifest do
|
21
|
-
File.open("Manifest.new", "wb") { |manifest|
|
22
|
-
Dir["**/*"].each { |file|
|
23
|
-
manifest.puts file if File.file? file
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.6
|
data/colorize.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{colorize}
|
8
|
+
s.version = "0.5.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["fazibear"]
|
12
|
+
s.date = %q{2009-11-23}
|
13
|
+
s.description = %q{Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences.}
|
14
|
+
s.email = %q{fazibear@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"CHANGELOG.rdoc",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"colorize.gemspec",
|
25
|
+
"lib/colorize.rb",
|
26
|
+
"test/test_colorize.rb",
|
27
|
+
"test/test_helper.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/fazibear/colorize}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Add colors methods to string class}
|
34
|
+
s.test_files = [
|
35
|
+
"test/test_helper.rb",
|
36
|
+
"test/test_colorize.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/lib/colorize.rb
CHANGED
@@ -1,4 +1,191 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
#
|
2
|
+
# Colorize String class extension.
|
3
|
+
#
|
4
|
+
class String
|
5
|
+
|
6
|
+
#
|
7
|
+
# Colors Hash
|
8
|
+
#
|
9
|
+
COLORS = {
|
10
|
+
:black => 0,
|
11
|
+
:red => 1,
|
12
|
+
:green => 2,
|
13
|
+
:yellow => 3,
|
14
|
+
:blue => 4,
|
15
|
+
:magenta => 5,
|
16
|
+
:cyan => 6,
|
17
|
+
:white => 7,
|
18
|
+
:default => 9,
|
19
|
+
|
20
|
+
:light_black => 10,
|
21
|
+
:light_red => 11,
|
22
|
+
:light_green => 12,
|
23
|
+
:light_yellow => 13,
|
24
|
+
:light_blue => 14,
|
25
|
+
:light_magenta => 15,
|
26
|
+
:light_cyan => 16,
|
27
|
+
:light_white => 17
|
28
|
+
}
|
29
|
+
|
30
|
+
#
|
31
|
+
# Modes Hash
|
32
|
+
#
|
33
|
+
MODES = {
|
34
|
+
:default => 0, # Turn off all attributes
|
35
|
+
#:bright => 1, # Set bright mode
|
36
|
+
:underline => 4, # Set underline mode
|
37
|
+
:blink => 5, # Set blink mode
|
38
|
+
:swap => 7, # Exchange foreground and background colors
|
39
|
+
:hide => 8 # Hide text (foreground color would be the same as background)
|
40
|
+
}
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
#
|
45
|
+
# Set color values in new string intance
|
46
|
+
#
|
47
|
+
def set_color_parameters( params )
|
48
|
+
if (params.instance_of?(Hash))
|
49
|
+
@color = params[:color]
|
50
|
+
@background = params[:background]
|
51
|
+
@mode = params[:mode]
|
52
|
+
@uncolorized = params[:uncolorized]
|
53
|
+
self
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
public
|
60
|
+
|
61
|
+
#
|
62
|
+
# Change color of string
|
63
|
+
#
|
64
|
+
# Examples:
|
65
|
+
#
|
66
|
+
# puts "This is blue".colorize( :blue )
|
67
|
+
# puts "This is light blue".colorize( :light_blue )
|
68
|
+
# puts "This is also blue".colorize( :color => :blue )
|
69
|
+
# puts "This is blue with red background".colorize( :color => :light_blue, :background => :red )
|
70
|
+
# puts "This is blue with red background".colorize( :light_blue ).colorize( :background => :red )
|
71
|
+
# puts "This is blue text on red".blue.on_red
|
72
|
+
# puts "This is red on blue".colorize( :red ).on_blue
|
73
|
+
# puts "This is red on blue and underline".colorize( :red ).on_blue.underline
|
74
|
+
# puts "This is blue text on red".blue.on_red.blink
|
75
|
+
#
|
76
|
+
def colorize( params )
|
77
|
+
|
78
|
+
return self unless STDOUT.isatty
|
79
|
+
|
80
|
+
begin
|
81
|
+
require 'Win32/Console/ANSI' if PLATFORM =~ /win32/
|
82
|
+
rescue LoadError
|
83
|
+
raise 'You must gem install win32console to use color on Windows'
|
84
|
+
end
|
85
|
+
|
86
|
+
color_parameters = {}
|
87
|
+
|
88
|
+
if (params.instance_of?(Hash))
|
89
|
+
color_parameters[:color] = COLORS[params[:color]]
|
90
|
+
color_parameters[:background] = COLORS[params[:background]]
|
91
|
+
color_parameters[:mode] = MODES[params[:mode]]
|
92
|
+
elsif (params.instance_of?(Symbol))
|
93
|
+
color_parameters[:color] = COLORS[params]
|
94
|
+
end
|
95
|
+
|
96
|
+
color_parameters[:color] ||= @color || 9
|
97
|
+
color_parameters[:background] ||= @background || 9
|
98
|
+
color_parameters[:mode] ||= @mode || 0
|
99
|
+
|
100
|
+
color_parameters[:uncolorized] ||= @uncolorized || self.dup
|
101
|
+
|
102
|
+
# calculate bright mode
|
103
|
+
color_parameters[:color] += 50 if color_parameters[:color] > 10
|
104
|
+
|
105
|
+
color_parameters[:background] += 50 if color_parameters[:background] > 10
|
106
|
+
|
107
|
+
return "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
#
|
112
|
+
# Return uncolorized string
|
113
|
+
#
|
114
|
+
def uncolorize
|
115
|
+
return @uncolorized || self
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Return true if sting is colorized
|
120
|
+
#
|
121
|
+
def colorized?
|
122
|
+
return !@uncolorized.nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# Make some color and on_color methods
|
127
|
+
#
|
128
|
+
COLORS.each_key do | key |
|
129
|
+
eval <<-"end_eval"
|
130
|
+
def #{key.to_s}
|
131
|
+
return self.colorize( :color => :#{key.to_s} )
|
132
|
+
end
|
133
|
+
def on_#{key.to_s}
|
134
|
+
return self.colorize( :background => :#{key.to_s} )
|
135
|
+
end
|
136
|
+
end_eval
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Methods for modes
|
141
|
+
#
|
142
|
+
MODES.each_key do | key |
|
143
|
+
eval <<-"end_eval"
|
144
|
+
def #{key.to_s}
|
145
|
+
return self.colorize( :mode => :#{key.to_s} )
|
146
|
+
end
|
147
|
+
end_eval
|
148
|
+
end
|
149
|
+
|
150
|
+
class << self
|
151
|
+
|
152
|
+
#
|
153
|
+
# Return array of available modes used by colorize method
|
154
|
+
#
|
155
|
+
def modes
|
156
|
+
keys = []
|
157
|
+
MODES.each_key do | key |
|
158
|
+
keys << key
|
159
|
+
end
|
160
|
+
keys
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Return array of available colors used by colorize method
|
165
|
+
#
|
166
|
+
def colors
|
167
|
+
keys = []
|
168
|
+
COLORS.each_key do | key |
|
169
|
+
keys << key
|
170
|
+
end
|
171
|
+
keys
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Display color matrix with color names.
|
176
|
+
#
|
177
|
+
def color_matrix( txt = "[X]" )
|
178
|
+
size = String.colors.length
|
179
|
+
String.colors.each do | color |
|
180
|
+
String.colors.each do | back |
|
181
|
+
print txt.colorize( :color => color, :background => back )
|
182
|
+
end
|
183
|
+
puts " < #{color}"
|
184
|
+
end
|
185
|
+
String.colors.reverse.each_with_index do | back, index |
|
186
|
+
puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
puts
|
4
191
|
end
|
metadata
CHANGED
@@ -1,65 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: colorize
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-08-11 00:00:00 +02:00
|
8
|
-
summary: Ruby string class extension. It add some methods to set color, background color and text effect on console easier using ANSI escape sequences.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: fazibear@gmail.com
|
12
|
-
homepage: " by Michal Kalbarczyk (FaziBear)"
|
13
|
-
rubyforge_project: colorize
|
14
|
-
description: "== FEATURES/PROBLEMS: * change string color * change string background * change string effect == SYNOPSIS: Some usage samples: puts \"This is blue\".colorize( :blue ) puts \"This is light blue\".colorize( :light_blue ) puts \"This is also blue\".colorize( :color => :blue ) puts \"This is blue with red background\".colorize( :color => :light_blue, :background => :red ) puts \"This is blue with red background\".colorize( :light_blue ).colorize( :background => :red ) puts \"This is blue text on red\".blue.on_red puts \"This is red on blue\".colorize( :red ).on_blue puts \"This is uncolorized\".blue.on_red.uncolorize puts \"This is red on blue and underline\".colorize( :red ).on_blue.underline puts \"This is blue text on red\".blue.on_red.blink"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.5.6
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- fazibear
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-23 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences.
|
17
|
+
email: fazibear@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
31
24
|
files:
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- README.
|
25
|
+
- .gitignore
|
26
|
+
- CHANGELOG.rdoc
|
27
|
+
- README.rdoc
|
35
28
|
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- colorize.gemspec
|
36
31
|
- lib/colorize.rb
|
37
|
-
- lib/colorize/colorize.rb
|
38
|
-
- test/test_helper.rb
|
39
32
|
- test/test_colorize.rb
|
40
|
-
test_files:
|
41
33
|
- test/test_helper.rb
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
- README.txt
|
46
|
-
extra_rdoc_files:
|
47
|
-
- History.txt
|
48
|
-
- Manifest.txt
|
49
|
-
- README.txt
|
50
|
-
executables: []
|
51
|
-
|
52
|
-
extensions: []
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/fazibear/colorize
|
36
|
+
licenses: []
|
53
37
|
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
54
55
|
requirements: []
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
version: 1.2.2
|
65
|
-
version:
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Add colors methods to string class
|
62
|
+
test_files:
|
63
|
+
- test/test_helper.rb
|
64
|
+
- test/test_colorize.rb
|
data/Manifest.txt
DELETED
data/lib/colorize/colorize.rb
DELETED
@@ -1,188 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
#
|
4
|
-
# Colors Hash
|
5
|
-
#
|
6
|
-
COLORS = {
|
7
|
-
:black => 0,
|
8
|
-
:red => 1,
|
9
|
-
:green => 2,
|
10
|
-
:yellow => 3,
|
11
|
-
:blue => 4,
|
12
|
-
:magenta => 5,
|
13
|
-
:cyan => 6,
|
14
|
-
:white => 7,
|
15
|
-
:default => 9,
|
16
|
-
|
17
|
-
:light_black => 10,
|
18
|
-
:light_red => 11,
|
19
|
-
:light_green => 12,
|
20
|
-
:light_yellow => 13,
|
21
|
-
:light_blue => 14,
|
22
|
-
:light_magenta => 15,
|
23
|
-
:light_cyan => 16,
|
24
|
-
:light_white => 17
|
25
|
-
}
|
26
|
-
|
27
|
-
#
|
28
|
-
# Modes Hash
|
29
|
-
#
|
30
|
-
MODES = {
|
31
|
-
:default => 0, # Turn off all attributes
|
32
|
-
#:bright => 1, # Set bright mode
|
33
|
-
:underline => 4, # Set underline mode
|
34
|
-
:blink => 5, # Set blink mode
|
35
|
-
:swap => 7, # Exchange foreground and background colors
|
36
|
-
:hide => 8 # Hide text (foreground color would be the same as background)
|
37
|
-
}
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
#
|
42
|
-
# Set color values in new string intance
|
43
|
-
#
|
44
|
-
def set_color_parameters( params )
|
45
|
-
if (params.instance_of?(Hash))
|
46
|
-
@color = params[:color]
|
47
|
-
@background = params[:background]
|
48
|
-
@mode = params[:mode]
|
49
|
-
@uncolorized = params[:uncolorized]
|
50
|
-
self
|
51
|
-
else
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
public
|
57
|
-
|
58
|
-
#
|
59
|
-
# Change color of string
|
60
|
-
#
|
61
|
-
# Examples:
|
62
|
-
#
|
63
|
-
# puts "This is blue".colorize( :blue )
|
64
|
-
# puts "This is light blue".colorize( :light_blue )
|
65
|
-
# puts "This is also blue".colorize( :color => :blue )
|
66
|
-
# puts "This is blue with red background".colorize( :color => :light_blue, :background => :red )
|
67
|
-
# puts "This is blue with red background".colorize( :light_blue ).colorize( :background => :red )
|
68
|
-
# puts "This is blue text on red".blue.on_red
|
69
|
-
# puts "This is red on blue".colorize( :red ).on_blue
|
70
|
-
# puts "This is red on blue and underline".colorize( :red ).on_blue.underline
|
71
|
-
# puts "This is blue text on red".blue.on_red.blink
|
72
|
-
#
|
73
|
-
def colorize( params )
|
74
|
-
|
75
|
-
return self unless STDOUT.isatty
|
76
|
-
|
77
|
-
begin
|
78
|
-
require 'Win32/Console/ANSI' if PLATFORM =~ /win32/
|
79
|
-
rescue LoadError
|
80
|
-
raise 'You must gem install win32console to use color on Windows'
|
81
|
-
end
|
82
|
-
|
83
|
-
color_parameters = {}
|
84
|
-
|
85
|
-
if (params.instance_of?(Hash))
|
86
|
-
color_parameters[:color] = COLORS[params[:color]]
|
87
|
-
color_parameters[:background] = COLORS[params[:background]]
|
88
|
-
color_parameters[:mode] = MODES[params[:mode]]
|
89
|
-
elsif (params.instance_of?(Symbol))
|
90
|
-
color_parameters[:color] = COLORS[params]
|
91
|
-
end
|
92
|
-
|
93
|
-
color_parameters[:color] ||= @color || 9
|
94
|
-
color_parameters[:background] ||= @background || 9
|
95
|
-
color_parameters[:mode] ||= @mode || 0
|
96
|
-
|
97
|
-
color_parameters[:uncolorized] ||= @uncolorized || self.dup
|
98
|
-
|
99
|
-
# calculate bright mode
|
100
|
-
color_parameters[:color] += 50 if color_parameters[:color] > 10
|
101
|
-
|
102
|
-
color_parameters[:background] += 50 if color_parameters[:background] > 10
|
103
|
-
|
104
|
-
return "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
# Return uncolorized string
|
110
|
-
#
|
111
|
-
def uncolorize
|
112
|
-
return @uncolorized || self
|
113
|
-
end
|
114
|
-
|
115
|
-
#
|
116
|
-
# Return true if sting is colorized
|
117
|
-
#
|
118
|
-
def colorized?
|
119
|
-
return !@uncolorized.nil?
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
# Make some color and on_color methods
|
124
|
-
#
|
125
|
-
COLORS.each_key do | key |
|
126
|
-
eval <<-"end_eval"
|
127
|
-
def #{key.to_s}
|
128
|
-
return self.colorize( :color => :#{key.to_s} )
|
129
|
-
end
|
130
|
-
def on_#{key.to_s}
|
131
|
-
return self.colorize( :background => :#{key.to_s} )
|
132
|
-
end
|
133
|
-
end_eval
|
134
|
-
end
|
135
|
-
|
136
|
-
#
|
137
|
-
# Methods for modes
|
138
|
-
#
|
139
|
-
MODES.each_key do | key |
|
140
|
-
eval <<-"end_eval"
|
141
|
-
def #{key.to_s}
|
142
|
-
return self.colorize( :mode => :#{key.to_s} )
|
143
|
-
end
|
144
|
-
end_eval
|
145
|
-
end
|
146
|
-
|
147
|
-
class << self
|
148
|
-
|
149
|
-
#
|
150
|
-
# Return array of available modes used by colorize method
|
151
|
-
#
|
152
|
-
def modes
|
153
|
-
keys = []
|
154
|
-
MODES.each_key do | key |
|
155
|
-
keys << key
|
156
|
-
end
|
157
|
-
keys
|
158
|
-
end
|
159
|
-
|
160
|
-
#
|
161
|
-
# Return array of available colors used by colorize method
|
162
|
-
#
|
163
|
-
def colors
|
164
|
-
keys = []
|
165
|
-
COLORS.each_key do | key |
|
166
|
-
keys << key
|
167
|
-
end
|
168
|
-
keys
|
169
|
-
end
|
170
|
-
|
171
|
-
#
|
172
|
-
# Display color matrix with color names.
|
173
|
-
#
|
174
|
-
def color_matrix( txt = "[X]" )
|
175
|
-
size = String.colors.length
|
176
|
-
String.colors.each do | color |
|
177
|
-
String.colors.each do | back |
|
178
|
-
print txt.colorize( :color => color, :background => back )
|
179
|
-
end
|
180
|
-
puts " < #{color}"
|
181
|
-
end
|
182
|
-
String.colors.reverse.each_with_index do | back, index |
|
183
|
-
puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
puts
|
188
|
-
end
|