colorin 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/colorin.rb +78 -47
- data/lib/configuration.yml +283 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05fa2d63303f6876d8cf957fd773cb7511186bac
|
4
|
+
data.tar.gz: 7e9cf809944f43f71ef9033d1203cb34011a7bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ad57565513cb4f2d76c53afb92aa87cf2e4585d2862071fcbef1e9bd953cc68ec5f26009e4ed1a94e2fcc6f3a3189fda32ba506d69c03ecc9c2776c9ba46cbb
|
7
|
+
data.tar.gz: a2bca0c1af103e3d16c6f4f5acaedd85ee3269c42f680a294dff6efff83fab38ad8ea29d9f762a67683bdf5a02843477be37559fd8172847edc13e9944afae0f
|
data/lib/colorin.rb
CHANGED
@@ -1,59 +1,90 @@
|
|
1
|
-
|
1
|
+
require 'yaml'
|
2
2
|
|
3
|
-
|
3
|
+
class Colorin < String
|
4
4
|
|
5
|
-
|
5
|
+
configuration = YAML.load_file File.join(File.dirname(__FILE__), 'configuration.yml')
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
magenta_light: 95,
|
29
|
-
cyan_light: 96,
|
30
|
-
|
31
|
-
on_black: 40,
|
32
|
-
on_red: 41,
|
33
|
-
on_green: 42,
|
34
|
-
on_yellow: 43,
|
35
|
-
on_blue: 44,
|
36
|
-
on_magenta: 45,
|
37
|
-
on_cyan: 46,
|
38
|
-
on_gray: 47,
|
39
|
-
on_black_light: 100,
|
40
|
-
on_red_light: 101,
|
41
|
-
on_green_light: 102,
|
42
|
-
on_yellow_light: 103,
|
43
|
-
on_blue_light: 104,
|
44
|
-
on_magenta_light: 105,
|
45
|
-
on_cyan_light: 106,
|
46
|
-
on_white: 107
|
47
|
-
}
|
48
|
-
|
49
|
-
CODES.each do |name, value|
|
7
|
+
VERSION = '2.0.0'
|
8
|
+
|
9
|
+
STYLES = configuration[:styles].freeze
|
10
|
+
|
11
|
+
DEFAULT_COLORS = configuration[:default_colors].freeze
|
12
|
+
|
13
|
+
CUSTOM_COLORS = configuration[:custom_colors].freeze
|
14
|
+
|
15
|
+
[STYLES, DEFAULT_COLORS].each do |config|
|
16
|
+
config.each do |name, value|
|
17
|
+
define_method name do
|
18
|
+
wrap value
|
19
|
+
end
|
20
|
+
|
21
|
+
define_singleton_method name do |string|
|
22
|
+
Colorin.new(string).send name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
CUSTOM_COLORS.each do |name, value|
|
50
28
|
define_method name do
|
51
|
-
|
29
|
+
hex value
|
30
|
+
end
|
31
|
+
|
32
|
+
define_method "on_#{name}" do
|
33
|
+
on_hex value
|
52
34
|
end
|
53
35
|
|
54
36
|
define_singleton_method name do |string|
|
55
37
|
Colorin.new(string).send name
|
56
38
|
end
|
39
|
+
|
40
|
+
define_singleton_method "on_#{name}" do |string|
|
41
|
+
Colorin.new(string).send "on_#{name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def rgb(r, g, b)
|
46
|
+
wrap "38;5;#{rgb_to_256(r, g, b)}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def on_rgb(r, g, b)
|
50
|
+
wrap "48;5;#{rgb_to_256(r, g, b)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def hex(hex)
|
54
|
+
rgb *hex_to_rgb(hex)
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_hex(hex)
|
58
|
+
on_rgb *hex_to_rgb(hex)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.color_palette
|
62
|
+
DEFAULT_COLORS.keys.reject { |c| c.to_s.start_with? 'on_' }.map { |color| "#{Colorin.send "on_#{color}", ' ' } #{Colorin.send color, color.to_s}" }
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.custom_color_palette
|
66
|
+
CUSTOM_COLORS.keys.map { |color| "#{Colorin.send "on_#{color}", ' ' } #{Colorin.send color, color.to_s}" }
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def wrap(code)
|
72
|
+
Colorin.new "\e[#{code}m#{self}\e[#{STYLES[:clear]}m"
|
73
|
+
end
|
74
|
+
|
75
|
+
def hex_to_rgb(hex)
|
76
|
+
raise ArgumentError, "Invalid hexadecimal: #{hex}" unless hex.match /[0-9abcdef]{6}/i
|
77
|
+
[
|
78
|
+
hex[0,2].to_i(16),
|
79
|
+
hex[2,2].to_i(16),
|
80
|
+
hex[4,2].to_i(16),
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
def rgb_to_256(r, g, b)
|
85
|
+
raise ArgumentError, "Color out of range (0-255): r: #{r}, g: #{g}, b: #{b}" if [r,g,b].any? { |c| c < 0 || c > 255 }
|
86
|
+
red, green, blue = [r, g, b].map { |c| (6 * (c / 256.0)).to_i }
|
87
|
+
(red * 36 + green * 6 + blue + 16).abs
|
57
88
|
end
|
58
89
|
|
59
90
|
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
:styles:
|
2
|
+
:clear: 0
|
3
|
+
:bold: 1
|
4
|
+
:dark: 2
|
5
|
+
:italic: 3
|
6
|
+
:underline: 4
|
7
|
+
:blink: 5
|
8
|
+
:rapid: 6
|
9
|
+
:negative: 7
|
10
|
+
:hide: 8
|
11
|
+
:strike: 9
|
12
|
+
|
13
|
+
:default_colors:
|
14
|
+
:red: 31
|
15
|
+
:green: 32
|
16
|
+
:yellow: 33
|
17
|
+
:blue: 34
|
18
|
+
:magenta: 35
|
19
|
+
:cyan: 36
|
20
|
+
:on_red: 41
|
21
|
+
:on_green: 42
|
22
|
+
:on_yellow: 43
|
23
|
+
:on_blue: 44
|
24
|
+
:on_magenta: 45
|
25
|
+
:on_cyan: 46
|
26
|
+
|
27
|
+
:custom_colors:
|
28
|
+
:white: "ffffff"
|
29
|
+
:black: "000000"
|
30
|
+
:red_50: "ffebee"
|
31
|
+
:red_100: "ffcdd2"
|
32
|
+
:red_200: "ef9a9a"
|
33
|
+
:red_300: "e57373"
|
34
|
+
:red_400: "ef5350"
|
35
|
+
:red_500: "f44336"
|
36
|
+
:red_600: "e53935"
|
37
|
+
:red_700: "d32f2f"
|
38
|
+
:red_800: "c62828"
|
39
|
+
:red_900: "b71c1c"
|
40
|
+
:red_a100: "ff8a80"
|
41
|
+
:red_a200: "ff5252"
|
42
|
+
:red_a400: "ff1744"
|
43
|
+
:red_a700: "d50000"
|
44
|
+
:pink_50: "fce4ec"
|
45
|
+
:pink_100: "f8bbd0"
|
46
|
+
:pink_200: "f48fb1"
|
47
|
+
:pink_300: "f06292"
|
48
|
+
:pink_400: "ec407a"
|
49
|
+
:pink_500: "e91e63"
|
50
|
+
:pink_600: "d81b60"
|
51
|
+
:pink_700: "c2185b"
|
52
|
+
:pink_800: "ad1457"
|
53
|
+
:pink_900: "880e4f"
|
54
|
+
:pink_a100: "ff80ab"
|
55
|
+
:pink_a200: "ff4081"
|
56
|
+
:pink_a400: "f50057"
|
57
|
+
:pink_a700: "c51162"
|
58
|
+
:purple_50: "f3e5f5"
|
59
|
+
:purple_100: "e1bee7"
|
60
|
+
:purple_200: "ce93d8"
|
61
|
+
:purple_300: "ba68c8"
|
62
|
+
:purple_400: "ab47bc"
|
63
|
+
:purple_500: "9c27b0"
|
64
|
+
:purple_600: "8e24aa"
|
65
|
+
:purple_700: "7b1fa2"
|
66
|
+
:purple_800: "6a1b9a"
|
67
|
+
:purple_900: "4a148c"
|
68
|
+
:purple_a100: "ea80fc"
|
69
|
+
:purple_a200: "e040fb"
|
70
|
+
:purple_a400: "d500f9"
|
71
|
+
:purple_a700: "aa00ff"
|
72
|
+
:deep_purple_50: "ede7f6"
|
73
|
+
:deep_purple_100: "d1c4e9"
|
74
|
+
:deep_purple_200: "b39ddb"
|
75
|
+
:deep_purple_300: "9575cd"
|
76
|
+
:deep_purple_400: "7e57c2"
|
77
|
+
:deep_purple_500: "673ab7"
|
78
|
+
:deep_purple_600: "5e35b1"
|
79
|
+
:deep_purple_700: "512da8"
|
80
|
+
:deep_purple_800: "4527a0"
|
81
|
+
:deep_purple_900: "311b92"
|
82
|
+
:deep_purple_a100: "b388ff"
|
83
|
+
:deep_purple_a200: "7c4dff"
|
84
|
+
:deep_purple_a400: "651fff"
|
85
|
+
:deep_purple_a700: "6200ea"
|
86
|
+
:indigo_50: "e8eaf6"
|
87
|
+
:indigo_100: "c5cae9"
|
88
|
+
:indigo_200: "9fa8da"
|
89
|
+
:indigo_300: "7986cb"
|
90
|
+
:indigo_400: "5c6bc0"
|
91
|
+
:indigo_500: "3f51b5"
|
92
|
+
:indigo_600: "3949ab"
|
93
|
+
:indigo_700: "303f9f"
|
94
|
+
:indigo_800: "283593"
|
95
|
+
:indigo_900: "1a237e"
|
96
|
+
:indigo_a100: "8c9eff"
|
97
|
+
:indigo_a200: "536dfe"
|
98
|
+
:indigo_a400: "3d5afe"
|
99
|
+
:indigo_a700: "304ffe"
|
100
|
+
:blue_50: "e3f2fd"
|
101
|
+
:blue_100: "bbdefb"
|
102
|
+
:blue_200: "90caf9"
|
103
|
+
:blue_300: "64b5f6"
|
104
|
+
:blue_400: "42a5f5"
|
105
|
+
:blue_500: "2196f3"
|
106
|
+
:blue_600: "1e88e5"
|
107
|
+
:blue_700: "1976d2"
|
108
|
+
:blue_800: "1565c0"
|
109
|
+
:blue_900: "0d47a1"
|
110
|
+
:blue_a100: "82b1ff"
|
111
|
+
:blue_a200: "448aff"
|
112
|
+
:blue_a400: "2979ff"
|
113
|
+
:blue_a700: "2962ff"
|
114
|
+
:light_blue_50: "e1f5fe"
|
115
|
+
:light_blue_100: "b3e5fc"
|
116
|
+
:light_blue_200: "81d4fa"
|
117
|
+
:light_blue_300: "4fc3f7"
|
118
|
+
:light_blue_400: "29b6f6"
|
119
|
+
:light_blue_500: "03a9f4"
|
120
|
+
:light_blue_600: "039be5"
|
121
|
+
:light_blue_700: "0288d1"
|
122
|
+
:light_blue_800: "0277bd"
|
123
|
+
:light_blue_900: "01579b"
|
124
|
+
:light_blue_a100: "80d8ff"
|
125
|
+
:light_blue_a200: "40c4ff"
|
126
|
+
:light_blue_a400: "00b0ff"
|
127
|
+
:light_blue_a700: "0091ea"
|
128
|
+
:cyan_50: "e0f7fa"
|
129
|
+
:cyan_100: "b2ebf2"
|
130
|
+
:cyan_200: "80deea"
|
131
|
+
:cyan_300: "4dd0e1"
|
132
|
+
:cyan_400: "26c6da"
|
133
|
+
:cyan_500: "00bcd4"
|
134
|
+
:cyan_600: "00acc1"
|
135
|
+
:cyan_700: "0097a7"
|
136
|
+
:cyan_800: "00838f"
|
137
|
+
:cyan_900: "006064"
|
138
|
+
:cyan_a100: "84ffff"
|
139
|
+
:cyan_a200: "18ffff"
|
140
|
+
:cyan_a400: "00e5ff"
|
141
|
+
:cyan_a700: "00b8d4"
|
142
|
+
:teal_50: "e0f2f1"
|
143
|
+
:teal_100: "b2dfdb"
|
144
|
+
:teal_200: "80cbc4"
|
145
|
+
:teal_300: "4db6ac"
|
146
|
+
:teal_400: "26a69a"
|
147
|
+
:teal_500: "009688"
|
148
|
+
:teal_600: "00897b"
|
149
|
+
:teal_700: "00796b"
|
150
|
+
:teal_800: "00695c"
|
151
|
+
:teal_900: "004d40"
|
152
|
+
:teal_a100: "a7ffeb"
|
153
|
+
:teal_a200: "64ffda"
|
154
|
+
:teal_a400: "1de9b6"
|
155
|
+
:teal_a700: "00bfa5"
|
156
|
+
:green_50: "e8f5e9"
|
157
|
+
:green_100: "c8e6c9"
|
158
|
+
:green_200: "a5d6a7"
|
159
|
+
:green_300: "81c784"
|
160
|
+
:green_400: "66bb6a"
|
161
|
+
:green_500: "4caf50"
|
162
|
+
:green_600: "43a047"
|
163
|
+
:green_700: "388e3c"
|
164
|
+
:green_800: "2e7d32"
|
165
|
+
:green_900: "1b5e20"
|
166
|
+
:green_a100: "b9f6ca"
|
167
|
+
:green_a200: "69f0ae"
|
168
|
+
:green_a400: "00e676"
|
169
|
+
:green_a700: "00c853"
|
170
|
+
:light_green_50: "f1f8e9"
|
171
|
+
:light_green_100: "dcedc8"
|
172
|
+
:light_green_200: "c5e1a5"
|
173
|
+
:light_green_300: "aed581"
|
174
|
+
:light_green_400: "9ccc65"
|
175
|
+
:light_green_500: "8bc34a"
|
176
|
+
:light_green_600: "7cb342"
|
177
|
+
:light_green_700: "689f38"
|
178
|
+
:light_green_800: "558b2f"
|
179
|
+
:light_green_900: "33691e"
|
180
|
+
:light_green_a100: "ccff90"
|
181
|
+
:light_green_a200: "b2ff59"
|
182
|
+
:light_green_a400: "76ff03"
|
183
|
+
:light_green_a700: "64dd17"
|
184
|
+
:lime_50: "f9fbe7"
|
185
|
+
:lime_100: "f0f4c3"
|
186
|
+
:lime_200: "e6ee9c"
|
187
|
+
:lime_300: "dce775"
|
188
|
+
:lime_400: "d4e157"
|
189
|
+
:lime_500: "cddc39"
|
190
|
+
:lime_600: "c0ca33"
|
191
|
+
:lime_700: "afb42b"
|
192
|
+
:lime_800: "9e9d24"
|
193
|
+
:lime_900: "827717"
|
194
|
+
:lime_a100: "f4ff81"
|
195
|
+
:lime_a200: "eeff41"
|
196
|
+
:lime_a400: "c6ff00"
|
197
|
+
:lime_a700: "aeea00"
|
198
|
+
:yellow_50: "fffde7"
|
199
|
+
:yellow_100: "fff9c4"
|
200
|
+
:yellow_200: "fff59d"
|
201
|
+
:yellow_300: "fff176"
|
202
|
+
:yellow_400: "ffee58"
|
203
|
+
:yellow_500: "ffeb3b"
|
204
|
+
:yellow_600: "fdd835"
|
205
|
+
:yellow_700: "fbc02d"
|
206
|
+
:yellow_800: "f9a825"
|
207
|
+
:yellow_900: "f57f17"
|
208
|
+
:yellow_a100: "ffff8d"
|
209
|
+
:yellow_a200: "ffff00"
|
210
|
+
:yellow_a400: "ffea00"
|
211
|
+
:yellow_a700: "ffd600"
|
212
|
+
:amber_50: "fff8e1"
|
213
|
+
:amber_100: "ffecb3"
|
214
|
+
:amber_200: "ffe082"
|
215
|
+
:amber_300: "ffd54f"
|
216
|
+
:amber_400: "ffca28"
|
217
|
+
:amber_500: "ffc107"
|
218
|
+
:amber_600: "ffb300"
|
219
|
+
:amber_700: "ffa000"
|
220
|
+
:amber_800: "ff8f00"
|
221
|
+
:amber_900: "ff6f00"
|
222
|
+
:amber_a100: "ffe57f"
|
223
|
+
:amber_a200: "ffd740"
|
224
|
+
:amber_a400: "ffc400"
|
225
|
+
:amber_a700: "ffab00"
|
226
|
+
:orange_50: "fff3e0"
|
227
|
+
:orange_100: "ffe0b2"
|
228
|
+
:orange_200: "ffcc80"
|
229
|
+
:orange_300: "ffb74d"
|
230
|
+
:orange_400: "ffa726"
|
231
|
+
:orange_500: "ff9800"
|
232
|
+
:orange_600: "fb8c00"
|
233
|
+
:orange_700: "f57c00"
|
234
|
+
:orange_800: "ef6c00"
|
235
|
+
:orange_900: "e65100"
|
236
|
+
:orange_a100: "ffd180"
|
237
|
+
:orange_a200: "ffab40"
|
238
|
+
:orange_a400: "ff9100"
|
239
|
+
:orange_a700: "ff6d00"
|
240
|
+
:deep_orange_50: "fbe9e7"
|
241
|
+
:deep_orange_100: "ffccbc"
|
242
|
+
:deep_orange_200: "ffab91"
|
243
|
+
:deep_orange_300: "ff8a65"
|
244
|
+
:deep_orange_400: "ff7043"
|
245
|
+
:deep_orange_500: "ff5722"
|
246
|
+
:deep_orange_600: "f4511e"
|
247
|
+
:deep_orange_700: "e64a19"
|
248
|
+
:deep_orange_800: "d84315"
|
249
|
+
:deep_orange_900: "bf360c"
|
250
|
+
:deep_orange_a100: "ff9e80"
|
251
|
+
:deep_orange_a200: "ff6e40"
|
252
|
+
:deep_orange_a400: "ff3d00"
|
253
|
+
:deep_orange_a700: "dd2c00"
|
254
|
+
:brown_50: "efebe9"
|
255
|
+
:brown_100: "d7ccc8"
|
256
|
+
:brown_200: "bcaaa4"
|
257
|
+
:brown_300: "a1887f"
|
258
|
+
:brown_400: "8d6e63"
|
259
|
+
:brown_500: "795548"
|
260
|
+
:brown_600: "6d4c41"
|
261
|
+
:brown_700: "5d4037"
|
262
|
+
:brown_800: "4e342e"
|
263
|
+
:brown_900: "3e2723"
|
264
|
+
:grey_50: "fafafa"
|
265
|
+
:grey_100: "f5f5f5"
|
266
|
+
:grey_200: "eeeeee"
|
267
|
+
:grey_300: "e0e0e0"
|
268
|
+
:grey_400: "bdbdbd"
|
269
|
+
:grey_500: "9e9e9e"
|
270
|
+
:grey_600: "757575"
|
271
|
+
:grey_700: "616161"
|
272
|
+
:grey_800: "424242"
|
273
|
+
:grey_900: "212121"
|
274
|
+
:blue_grey_50: "eceff1"
|
275
|
+
:blue_grey_100: "cfd8dc"
|
276
|
+
:blue_grey_200: "b0bec5"
|
277
|
+
:blue_grey_300: "90a4ae"
|
278
|
+
:blue_grey_400: "78909c"
|
279
|
+
:blue_grey_500: "607d8b"
|
280
|
+
:blue_grey_600: "546e7a"
|
281
|
+
:blue_grey_700: "455a64"
|
282
|
+
:blue_grey_800: "37474f"
|
283
|
+
:blue_grey_900: "263238"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- colorin.gemspec
|
70
70
|
- lib/colorin.rb
|
71
|
+
- lib/configuration.yml
|
71
72
|
homepage: https://github.com/gabynaiman/colorin
|
72
73
|
licenses:
|
73
74
|
- MIT
|