colorizer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/colorize.rb +24 -0
- data/lib/styles.rb +245 -0
- metadata +48 -0
data/lib/colorize.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'styles'
|
2
|
+
module Colorize
|
3
|
+
|
4
|
+
self::VERSION = "0.0.1"
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
class String
|
9
|
+
|
10
|
+
def self.color_set(style=:Terminal)
|
11
|
+
style_name = style
|
12
|
+
style = Colorize::Style.const_get(style)
|
13
|
+
(style::COLORS).keys.each do |meth|
|
14
|
+
class_eval %Q[
|
15
|
+
def #{meth.to_s.downcase}
|
16
|
+
::Colorize::Style::#{style_name}.colorize(self, :#{meth})
|
17
|
+
end
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
String.color_set
|
data/lib/styles.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
module Colorize
|
2
|
+
module Style
|
3
|
+
module Terminal
|
4
|
+
COLORS =
|
5
|
+
{
|
6
|
+
:BOLD => "\e[1m",
|
7
|
+
:FAINT => "\e[2m",
|
8
|
+
:ITALIC => "\e[3m",
|
9
|
+
:BLINK_SLOW => "\e[5m",
|
10
|
+
:BLINK_FAST => "\e[6m",
|
11
|
+
:NEGATIVE_COLOR => "\e[7m",
|
12
|
+
:STRIKE_THROUGH => "\e[9m",
|
13
|
+
:UNDERLINE => "\e[4m",
|
14
|
+
:RED => "\e[31m",
|
15
|
+
:GREEN => "\e[32m",
|
16
|
+
:YELLOW => "\e[33m",
|
17
|
+
:BLUE => "\e[34m",
|
18
|
+
:MAGENTA => "\e[35m",
|
19
|
+
:CYAN => "\e[36m",
|
20
|
+
:WHITE => "\e[37m",
|
21
|
+
:ON_RED => "\e[41m",
|
22
|
+
:ON_GREEN => "\e[42m",
|
23
|
+
:ON_YELLOW => "\e[43m",
|
24
|
+
:ON_BLUE => "\e[44m",
|
25
|
+
:ON_MAGENTA => "\e[45m",
|
26
|
+
:ON_CYAN => "\e[46m",
|
27
|
+
:ON_WHITE => "\e[47m",
|
28
|
+
:CLEAR => "\e[39;49;27m"
|
29
|
+
}
|
30
|
+
|
31
|
+
def self.colorize(str, color)
|
32
|
+
str = "#{COLORS[color]}"#{str}"
|
33
|
+
str.gsub!(/\e\[39;49;27m/, COLORS[color])
|
34
|
+
return str + COLORS[:CLEAR]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Html
|
39
|
+
|
40
|
+
COLORS =
|
41
|
+
{
|
42
|
+
:ALICE_BLUE => "#F0F8FF",
|
43
|
+
:ANTIQUE_WHITE => "#FAEBD7",
|
44
|
+
:AQUA => "#00FFFF",
|
45
|
+
:AQUAMARINE => "#7FFFD4",
|
46
|
+
:AZURE => "#F0FFFF",
|
47
|
+
:BEIGE => "#F5F5DC",
|
48
|
+
:BISQUE => "#FFE4C4",
|
49
|
+
:BLACK => "#000000",
|
50
|
+
:BLANCHED_ALMOND => "#FFEBCD",
|
51
|
+
:BLUE => "#0000FF",
|
52
|
+
:BLUE_VIOLET => "#8A2BE2",
|
53
|
+
:BROWN => "#A52A2A",
|
54
|
+
:BURLY_WOOD => "#DEB887",
|
55
|
+
:CADET_BLUE => "#5F9EA0",
|
56
|
+
:CHARTREUSE => "#7FFF00",
|
57
|
+
:CHOCOLATE => "#D2691E",
|
58
|
+
:CORAL => "#FF7F50",
|
59
|
+
:CORN_FLOWER_BLUE => "#6495ED",
|
60
|
+
:CORN_SILK => "#FFF8DC",
|
61
|
+
:CRIMSON => "#DC143C",
|
62
|
+
:CYAN => "#00FFFF",
|
63
|
+
:DARK_BLUE => "#00008B",
|
64
|
+
:DARK_CYAN => "#008B8B",
|
65
|
+
:DARK_GOLDENROD => "#B8860B",
|
66
|
+
:DARK_GRAY => "#A9A9A9",
|
67
|
+
:DARK_GREY => "#A9A9A9",
|
68
|
+
:DARK_GREEN => "#006400",
|
69
|
+
:DARK_KHAKI => "#BDB76B",
|
70
|
+
:DARK_MAGENTA => "#8B008B",
|
71
|
+
:DARK_OLIVE_GREEN => "#556B2F",
|
72
|
+
:DARK_ORANGE => "#FF8C00",
|
73
|
+
:DARK_ORCHID => "#9932CC",
|
74
|
+
:DARK_RED => "#8B0000",
|
75
|
+
:DARK_SALMON => "#E9967A",
|
76
|
+
:DARK_SEA_GREEN => "#8FBC8F",
|
77
|
+
:DARK_SLATE_BLUE => "#483D8B",
|
78
|
+
:DARK_SLATE_GRAY => "#2F4F4F",
|
79
|
+
:DARK_SLATE_GREY => "#2F4F4F",
|
80
|
+
:DARK_TURQUOISE => "#00CED1",
|
81
|
+
:DARK_VIOLET => "#9400D3",
|
82
|
+
:DEEP_PINK => "#FF1493",
|
83
|
+
:DEEP_SKY_BLUE => "#00BFFF",
|
84
|
+
:DIM_GRAY => "#696969",
|
85
|
+
:DIM_GREY => "#696969",
|
86
|
+
:DODGER_BLUE => "#1E90FF",
|
87
|
+
:FIRE_BRICK => "#B22222",
|
88
|
+
:FLORAL_WHITE => "#FFFAF0",
|
89
|
+
:FOREST_GREEN => "#228B22",
|
90
|
+
:FUCHSIA => "#FF00FF",
|
91
|
+
:GAINSBORO => "#DCDCDC",
|
92
|
+
:GHOST_WHITE => "#F8F8FF",
|
93
|
+
:GOLD => "#FFD700",
|
94
|
+
:GOLDENROD => "#DAA520",
|
95
|
+
:GRAY => "#808080",
|
96
|
+
:GREY => "#808080",
|
97
|
+
:GREEN => "#008000",
|
98
|
+
:GREEN_YELLOW => "#ADFF2F",
|
99
|
+
:HONEY_DEW => "#F0FFF0",
|
100
|
+
:HOT_PINK => "#FF69B4",
|
101
|
+
:INDIAN_RED => "#CD5C5C",
|
102
|
+
:INDIGO => "#4B0082",
|
103
|
+
:IVORY => "#FFFFF0",
|
104
|
+
:KHAKI => "#F0E68C",
|
105
|
+
:LAVENDER => "#E6E6FA",
|
106
|
+
:LAVENDER_BLUSH => "#FFF0F5",
|
107
|
+
:LAWN_GREEN => "#7CFC00",
|
108
|
+
:LEMON_CHIFFON => "#FFFACD",
|
109
|
+
:LIGHT_BLUE => "#ADD8E6",
|
110
|
+
:LIGHT_CORAL => "#F08080",
|
111
|
+
:LIGHT_CYAN => "#E0FFFF",
|
112
|
+
:LIGHT_GOLDENROD_YELLOW => "#FAFAD2",
|
113
|
+
:LIGHT_GRAY => "#D3D3D3",
|
114
|
+
:LIGHT_GREY => "#D3D3D3",
|
115
|
+
:LIGHT_GREEN => "#90EE90",
|
116
|
+
:LIGHT_PINK => "#FFB6C1",
|
117
|
+
:LIGHT_SALMON => "#FFA07A",
|
118
|
+
:LIGHT_SEAGREEN => "#20B2AA",
|
119
|
+
:LIGHT_SKYBLUE => "#87CEFA",
|
120
|
+
:LIGHT_SLATEGRAY => "#778899",
|
121
|
+
:LIGHT_SLATEGREY => "#778899",
|
122
|
+
:LIGHT_STEELBLUE => "#B0C4DE",
|
123
|
+
:LIGHT_YELLOW => "#FFFFE0",
|
124
|
+
:LIME => "#00FF00",
|
125
|
+
:LIME_GREEN => "#32CD32",
|
126
|
+
:LINEN => "#FAF0E6",
|
127
|
+
:MAGENTA => "#FF00FF",
|
128
|
+
:MAROON => "#800000",
|
129
|
+
:MEDIUM_AQUAMARINE => "#66CDAA",
|
130
|
+
:MEDIUM_BLUE => "#0000CD",
|
131
|
+
:MEDIUM_ORCHID => "#BA55D3",
|
132
|
+
:MEDIUM_PURPLE => "#9370D8",
|
133
|
+
:MEDIUM_SEAGREEN => "#3CB371",
|
134
|
+
:MEDIUM_SLATEBLUE => "#7B68EE",
|
135
|
+
:MEDIUM_SPRINGGREEN => "#00FA9A",
|
136
|
+
:MEDIUM_TURQUOISE => "#48D1CC",
|
137
|
+
:MEDIUM_VIOLETRED => "#C71585",
|
138
|
+
:MIDNIGHT_BLUE => "#191970",
|
139
|
+
:MINT_CREAM => "#F5FFFA",
|
140
|
+
:MISTY_ROSE => "#FFE4E1",
|
141
|
+
:MOCCASIN => "#FFE4B5",
|
142
|
+
:NAVAJO_WHITE => "#FFDEAD",
|
143
|
+
:NAVY => "#000080",
|
144
|
+
:OLD_LACE => "#FDF5E6",
|
145
|
+
:OLIVE => "#808000",
|
146
|
+
:OLIVE_DRAB => "#6B8E23",
|
147
|
+
:ORANGE => "#FFA5",
|
148
|
+
:ORANGE_RED => "#FF4500",
|
149
|
+
:ORCHID => "#DA70D6",
|
150
|
+
:PALE_GOLDENROD => "#EEE8AA",
|
151
|
+
:PALE_GREEN => "#98FB98",
|
152
|
+
:PALE_TURQUOISE => "#AFEEEE",
|
153
|
+
:PALE__VIOLET_RED => "#D87093",
|
154
|
+
:PAPAYA_WHIP => "#FFEFD5",
|
155
|
+
:PEACH_PUFF => "#FFDAB9",
|
156
|
+
:PERU => "#CD853F",
|
157
|
+
:PINK => "#FFC0CB",
|
158
|
+
:PLUM => "#DDA0DD",
|
159
|
+
:POWDER_BLUE => "#B0E0E6",
|
160
|
+
:PURPLE => "#800080",
|
161
|
+
:RED => "#FF0000",
|
162
|
+
:ROSY_BROWN => "#BC8F8F",
|
163
|
+
:ROYAL_BLUE => "#4169E1",
|
164
|
+
:SADDLE_BROWN => "#8B4513",
|
165
|
+
:SALMON => "# FA8072",
|
166
|
+
:SANDY_BROWN => "#F4A460",
|
167
|
+
:SEA_GREEN => "#2E8B57",
|
168
|
+
:SEA_SHELL => "#FFF5EE",
|
169
|
+
:SIENNA => "#A0522D",
|
170
|
+
:SILVER => "#C0C0C0",
|
171
|
+
:SKY_BLUE => "#87CEEB",
|
172
|
+
:SLATE_BLUE => "#6A5ACD",
|
173
|
+
:SLATE_GRAY => "#708090",
|
174
|
+
:SLATE_GREY => "#708090",
|
175
|
+
:SNOW => "#FFFAFA",
|
176
|
+
:SPRING_GREEN => "#00FF7F",
|
177
|
+
:STEEL_BLUE => "#4682B4",
|
178
|
+
:TAN => "#D2B48C",
|
179
|
+
:TEAL => "#008080",
|
180
|
+
:THISTLE => "#D8BFD8",
|
181
|
+
:TOMATO => "#FF6347",
|
182
|
+
:TURQUOISE => "#40E0D0",
|
183
|
+
:VIOLET => "#EE82EE",
|
184
|
+
:WHEAT => "#F5DEB3",
|
185
|
+
:WHITE => "#FFFFFF",
|
186
|
+
:WHITE_SMOKE => "#F5F5F5",
|
187
|
+
:YELLOW => "#FFFF00",
|
188
|
+
:YELLOW_GREEN => "#9ACD32"
|
189
|
+
}
|
190
|
+
def self.colorize(str, color)
|
191
|
+
return "<span style=\"font-color: #{COLORS[color]}\">#{str}</span>"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
module IRC
|
196
|
+
XC = "\x3"
|
197
|
+
IRC::COLORS =
|
198
|
+
{
|
199
|
+
:BOLD => [?\x2 , ?\x2],
|
200
|
+
:UNDERLINE => [?\x1F , ?\x1F],
|
201
|
+
:NORMAL => [?\xF , ?\xF],
|
202
|
+
:WHITE => [XC+ "00" , XC],
|
203
|
+
:ON_WHITE => [XC+",00" , XC],
|
204
|
+
:BLACK => [XC+ "01" , XC],
|
205
|
+
:ON_BLACK => [XC+",01" , XC],
|
206
|
+
:BLUE => [XC+ "02" , XC],
|
207
|
+
:ON_BLUE => [XC+",02" , XC],
|
208
|
+
:GREEN => [XC+ "03" , XC],
|
209
|
+
:ON_GREEN => [XC+",03" , XC],
|
210
|
+
:PINK => [XC+ "04" , XC],
|
211
|
+
:ON_PINK => [XC+",04" , XC],
|
212
|
+
:RED => [XC+ "05" , XC],
|
213
|
+
:ON_RED => [XC+",05" , XC],
|
214
|
+
:PURPLE => [XC+ "06" , XC],
|
215
|
+
:ON_PURPLE => [XC+",06" , XC],
|
216
|
+
:BROWN => [XC+ "07" , XC],
|
217
|
+
:ON_BROWN => [XC+",07" , XC],
|
218
|
+
:YELLOW => [XC+ "08" , XC],
|
219
|
+
:ON_YELLOW => [XC+",08" , XC],
|
220
|
+
:LIGHT_GREEN => [XC+ "09" , XC],
|
221
|
+
:ON_LIGHT_GREEN => [XC+",09" , XC],
|
222
|
+
:TURQUOISE => [XC+ "10" , XC],
|
223
|
+
:ON_TURQUOISE => [XC+",10" , XC],
|
224
|
+
:TEAL => [XC+ "11" , XC],
|
225
|
+
:ON_TEAL => [XC+",11" , XC],
|
226
|
+
:LIGHT_BLUE => [XC+ "12" , XC],
|
227
|
+
:ON_LIGHT_BLUE => [XC+",12" , XC],
|
228
|
+
:VIOLET => [XC+ "13" , XC],
|
229
|
+
:ON_VIOLET => [XC+",13" , XC],
|
230
|
+
:DARK_GRAY => [XC+ "14" , XC],
|
231
|
+
:DARK_GREY => [XC+ "14" , XC],
|
232
|
+
:ON_DARK_GRAY => [XC+",14" , XC],
|
233
|
+
:ON_DARK_GREY => [XC+",14" , XC],
|
234
|
+
:LIGHT_GREY => [XC+ "15" , XC],
|
235
|
+
:LIGHT_GRAY => [XC+ "15" , XC],
|
236
|
+
:ON_LIGHT_GRAY => [XC+",15" , XC],
|
237
|
+
:ON_LIGHT_GREY => [XC+",15" , XC]
|
238
|
+
}
|
239
|
+
def self.colorize(str, color)
|
240
|
+
puts color
|
241
|
+
return "#{COLORS[color][0]}#{str}".gsub(/\x3[^\d]/, COLORS[color][0]) + COLORS[color][1]
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: colorizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Carey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Colorization of text output, modular capabilities with out of the box
|
15
|
+
support for terminal coloring and IRC colors.
|
16
|
+
email: matthew.b.carey@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/colorize.rb
|
22
|
+
- lib/styles.rb
|
23
|
+
homepage: http://lsden.net/
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.11
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Colorize Text Output
|
47
|
+
test_files: []
|
48
|
+
has_rdoc:
|