colours 0.5.41

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.

Potentially problematic release.


This version of colours might be problematic. Click here for more details.

Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +862 -0
  4. data/bin/colours +7 -0
  5. data/bin/html_colour_to_hex_value +7 -0
  6. data/bin/html_colourize +7 -0
  7. data/bin/print_rainbow_line +7 -0
  8. data/bin/rainbow_colours +7 -0
  9. data/colours.gemspec +75 -0
  10. data/doc/COLOUR_CODES_CHART.md +28 -0
  11. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
  12. data/doc/README.gen +845 -0
  13. data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
  14. data/lib/colours/autoalias_e.rb +10 -0
  15. data/lib/colours/autogenerated/README.md +2 -0
  16. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  17. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  18. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
  19. data/lib/colours/autoinclude.rb +14 -0
  20. data/lib/colours/base/base.rb +23 -0
  21. data/lib/colours/basic_colours/README.md +4 -0
  22. data/lib/colours/basic_colours/basic_colours.rb +279 -0
  23. data/lib/colours/colour_methods/README.md +11 -0
  24. data/lib/colours/colour_methods/default_colour.rb +66 -0
  25. data/lib/colours/colour_methods/sargument.rb +70 -0
  26. data/lib/colours/colour_methods/scomments.rb +105 -0
  27. data/lib/colours/colour_methods/sdir.rb +66 -0
  28. data/lib/colours/colour_methods/sfancy.rb +84 -0
  29. data/lib/colours/colour_methods/sfile.rb +71 -0
  30. data/lib/colours/colour_methods/simportant.rb +92 -0
  31. data/lib/colours/colour_methods/snormal.rb +66 -0
  32. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  33. data/lib/colours/colour_methods/swarn.rb +76 -0
  34. data/lib/colours/colour_table/README.md +3 -0
  35. data/lib/colours/colour_table/colour_table.rb +275 -0
  36. data/lib/colours/colours_e_autoinclude.rb +9 -0
  37. data/lib/colours/commandline/README.md +2 -0
  38. data/lib/colours/commandline/commandline.rb +44 -0
  39. data/lib/colours/commandline/menu.rb +111 -0
  40. data/lib/colours/constants/colour_constants.rb +299 -0
  41. data/lib/colours/constants/file_constants.rb +72 -0
  42. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  43. data/lib/colours/constants/misc.rb +59 -0
  44. data/lib/colours/constants/newline.rb +14 -0
  45. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  46. data/lib/colours/e/README.md +13 -0
  47. data/lib/colours/e/autoinclude.rb +11 -0
  48. data/lib/colours/e/e.rb +35 -0
  49. data/lib/colours/e.rb +5 -0
  50. data/lib/colours/eparse/eparse.rb +77 -0
  51. data/lib/colours/everything/autoinclude.rb +11 -0
  52. data/lib/colours/html_colours/README.md +1 -0
  53. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  54. data/lib/colours/html_colours/hash_html_colours.rb +63 -0
  55. data/lib/colours/html_colours/html_colourize.rb +48 -0
  56. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  57. data/lib/colours/html_colours/misc.rb +186 -0
  58. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  59. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  60. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  61. data/lib/colours/module.rb +11 -0
  62. data/lib/colours/project/project_base_directory.rb +22 -0
  63. data/lib/colours/rainbow_colours/README.md +2 -0
  64. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  65. data/lib/colours/rainbow_colours/constants.rb +30 -0
  66. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  67. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  68. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  69. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  70. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  71. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  72. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  73. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  74. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  75. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  76. data/lib/colours/requires/require_commandline.rb +7 -0
  77. data/lib/colours/requires/require_eparse.rb +11 -0
  78. data/lib/colours/requires/require_rgb.rb +5 -0
  79. data/lib/colours/requires/require_sdir.rb +5 -0
  80. data/lib/colours/requires/require_sfile.rb +5 -0
  81. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  82. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  83. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  84. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  85. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  86. data/lib/colours/requires/require_the_constants.rb +11 -0
  87. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  88. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  89. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  90. data/lib/colours/revert/revert.rb +106 -0
  91. data/lib/colours/rgb/rgb.rb +538 -0
  92. data/lib/colours/testing/README.md +2 -0
  93. data/lib/colours/testing/testing.rb +157 -0
  94. data/lib/colours/toplevel_methods/bold.rb +35 -0
  95. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  96. data/lib/colours/toplevel_methods/cat.rb +39 -0
  97. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  98. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  99. data/lib/colours/toplevel_methods/col.rb +56 -0
  100. data/lib/colours/toplevel_methods/e.rb +63 -0
  101. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  102. data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
  103. data/lib/colours/toplevel_methods/html_colourize.rb +65 -0
  104. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  105. data/lib/colours/toplevel_methods/italic.rb +104 -0
  106. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  107. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +314 -0
  108. data/lib/colours/toplevel_methods/misc.rb +95 -0
  109. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  110. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
  111. data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
  112. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  113. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +107 -0
  114. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  115. data/lib/colours/toplevel_methods/underline.rb +114 -0
  116. data/lib/colours/toplevel_methods/use_colours.rb +311 -0
  117. data/lib/colours/utility_scripts/README.md +2 -0
  118. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  119. data/lib/colours/version/version.rb +25 -0
  120. data/lib/colours/yaml/256_colours.yml +277 -0
  121. data/lib/colours/yaml/basic_colours.yml +23 -0
  122. data/lib/colours/yaml/html_colours.yml +835 -0
  123. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  124. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  125. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
  126. data/lib/colours.rb +5 -0
  127. data/test/test.html +18 -0
  128. data/test/testing_256_colours_support.rb +29 -0
  129. data/test/testing_col.rb +10 -0
  130. data/test/testing_colours.rb +95 -0
  131. data/test/testing_colours_e.rb +13 -0
  132. data/test/testing_eparse.rb +13 -0
  133. data/test/testing_kde_colour_palette.rb +30 -0
  134. data/test/testing_konsole_submodule.rb +226 -0
  135. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  136. data/test/testing_rgb_to_hex.rb +32 -0
  137. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  138. data/test/testing_the_colour_methods.rb +36 -0
  139. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  140. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  141. data/test/testing_whether_colours_will_be_used.rb +7 -0
  142. metadata +224 -0
@@ -0,0 +1,538 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Colours::RGB
6
+ #
7
+ # The Colours::RBG class was used to convert from RGB values to hex
8
+ # format. However had these days it is not as widely used anymore
9
+ # within the colours project.
10
+ #
11
+ # Code in this .rb file here in general can be used for RGB-related
12
+ # functionality. A good example for what can be done with this is to
13
+ # convert a HTML colour, such as "slateblue", into its RGB
14
+ # representation.
15
+ # =========================================================================== #
16
+ # require 'colours/rgb/rgb.rb'
17
+ # =========================================================================== #
18
+ require 'colours/toplevel_methods/random_html_colour.rb'
19
+ require 'colours/html_colours/hash_html_colours.rb'
20
+ require 'colours/html_colours/is_this_html_colour_included.rb'
21
+ require 'colours/constants/misc.rb'
22
+ require 'colours/toplevel_methods/random_value.rb'
23
+
24
+ module Colours
25
+
26
+ class RGB # === Colours::RGB
27
+
28
+ # ========================================================================= #
29
+ # === DEFAULT_VALUES
30
+ # ========================================================================= #
31
+ DEFAULT_VALUES = [255, 0, 0]
32
+
33
+ # ========================================================================= #
34
+ # === DEFAULT_VALUE
35
+ # ========================================================================= #
36
+ DEFAULT_VALUE = 0
37
+
38
+ # =========================================================================== #
39
+ # === initialize
40
+ #
41
+ # Keep in mind that the first argument could be something like:
42
+ #
43
+ # [106, 90, 205]
44
+ #
45
+ # In that case, we need to continue differently.
46
+ # =========================================================================== #
47
+ def initialize(
48
+ original_input = ARGV,
49
+ run_already = true
50
+ )
51
+ reset
52
+ set_commandline_arguments(
53
+ original_input
54
+ )
55
+ run if run_already
56
+ end
57
+
58
+ # =========================================================================== #
59
+ # === set_commandline_arguments
60
+ # =========================================================================== #
61
+ def set_commandline_arguments(i)
62
+ @commandline_arguments = [i].flatten.compact
63
+ end
64
+
65
+ # =========================================================================== #
66
+ # === reset
67
+ # =========================================================================== #
68
+ def reset
69
+ @r, @g, @b = 0, 0, 0 # Use default values for RGB.
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === b?
74
+ # ========================================================================= #
75
+ def b?
76
+ @b
77
+ end; alias b b? # === b
78
+
79
+ # ========================================================================= #
80
+ # === g?
81
+ # ========================================================================= #
82
+ def g?
83
+ @g
84
+ end; alias g g? # === g
85
+
86
+ # ========================================================================= #
87
+ # === hexstring?
88
+ # ========================================================================= #
89
+ def hexstring?
90
+ @hexstring
91
+ end; alias hexstring hexstring? # === hexstring
92
+
93
+ # ========================================================================= #
94
+ # === r?
95
+ # ========================================================================= #
96
+ def r?
97
+ @r
98
+ end; alias r r? # === r
99
+
100
+ # ========================================================================= #
101
+ # === determine_rgb_values_from_the_commandline_arguments
102
+ # ========================================================================= #
103
+ def determine_rgb_values_from_the_commandline_arguments
104
+ _ = @commandline_arguments
105
+ first = _.first
106
+ if first.is_? Array
107
+ set_r(first[0])
108
+ set_g(first[1])
109
+ set_b(first[2])
110
+ end
111
+ end
112
+
113
+ # ========================================================================= #
114
+ # === rgb
115
+ # ========================================================================= #
116
+ def rgb
117
+ [ @r, @g, @b ]
118
+ end
119
+
120
+ # ========================================================================= #
121
+ # === check_validity_of
122
+ #
123
+ # We check if the input is higher than 255, in which case we give back
124
+ # an ArgumentError.
125
+ # ========================================================================= #
126
+ def check_validity_of(i)
127
+ if i.to_i > 255
128
+ raise ArgumentError,
129
+ 'Error: RGB values can not be higher than 255.'
130
+ end
131
+ end
132
+
133
+ # ========================================================================= #
134
+ # === do_the_conversion
135
+ # ========================================================================= #
136
+ def do_the_conversion
137
+ @hexstring = '#%02x%02x%02x'.upcase % rgb()
138
+ return @hexstring
139
+ end; alias update_hexstring do_the_conversion # === update_hexstring
140
+
141
+ # ========================================================================= #
142
+ # === set_rgb
143
+ # ========================================================================= #
144
+ def set_rgb(r,g,b)
145
+ set_r(r)
146
+ set_g(g)
147
+ set_b(b)
148
+ end
149
+
150
+ # ========================================================================= #
151
+ # === set_r
152
+ # ========================================================================= #
153
+ def set_r(i = DEFAULT_VALUES[0])
154
+ i = i.to_i
155
+ check_validity_of(i)
156
+ @r = i
157
+ end
158
+
159
+ # ========================================================================= #
160
+ # === set_g
161
+ # ========================================================================= #
162
+ def set_g(i = nil)
163
+ i = DEFAULT_VALUE if i.nil?
164
+ i = i.to_i
165
+ check_validity_of(i)
166
+ @g = i
167
+ end
168
+
169
+ # ========================================================================= #
170
+ # === set_b
171
+ # ========================================================================= #
172
+ def set_b(i = nil)
173
+ i = DEFAULT_VALUE if i.nil?
174
+ i = i.to_i
175
+ check_validity_of(i)
176
+ @b = i
177
+ end
178
+
179
+ # ========================================================================= #
180
+ # === lighten
181
+ #
182
+ # This lightens up a colour.
183
+ # RgbToHex.new('#ffffff').lighten # => "#232323"
184
+ # ========================================================================= #
185
+ def lighten
186
+ add(35) # Hardcoded to add +35 to each of R, G and B.
187
+ end
188
+
189
+ # ========================================================================= #
190
+ # === add
191
+ #
192
+ # This method can be used to lighten a R,G,B colour in general. We
193
+ # also use another method for this, though, called .lighten().
194
+ # ========================================================================= #
195
+ def add(i = 1)
196
+ i = i.to_i
197
+ @r += i
198
+ @g += i
199
+ @b += i
200
+ update_hexstring
201
+ end
202
+
203
+ # =========================================================================== #
204
+ # === run
205
+ # =========================================================================== #
206
+ def run
207
+ determine_rgb_values_from_the_commandline_arguments
208
+ do_the_conversion
209
+ end
210
+
211
+ # ========================================================================= #
212
+ # === RgbToHex[]
213
+ #
214
+ # Easier access to the conversion facility.
215
+ #
216
+ # Usage example:
217
+ # RgbToHex[22,33,44] # => "#16212C"
218
+ # ========================================================================= #
219
+ def self.[](r = 255, g = 0, b = 0)
220
+ _ = RgbToHex.new(r,g,b)
221
+ return '#%02x%02x%02x'.upcase % _.rgb
222
+ end
223
+
224
+ end
225
+
226
+ # =========================================================================== #
227
+ # === Colours.convert_this_rgb_value_into_a_html_colour
228
+ #
229
+ # This method will convert a RGB value (input assumed to be an Array)
230
+ # into the corresponding HTML colour.
231
+ # =========================================================================== #
232
+ def self.convert_this_rgb_value_into_a_html_colour(i, g = nil, b = nil)
233
+ if i.is_a?(Numeric) and g and b
234
+ i = [i, g, b] # Re-compose the input in this case, as we provided only one Array.
235
+ end
236
+ _ = Colours.hash_html_colours?
237
+ possible_matches = _.select {|key, inner_array|
238
+ (i[0] == inner_array[0]) and
239
+ (i[1] == inner_array[1]) and
240
+ (i[2] == inner_array[2])
241
+ }
242
+ possible_matches.keys.first
243
+ end
244
+
245
+ # =========================================================================== #
246
+ # === Colours.convert_this_html_colour_into_an_array_of_rgb_values
247
+ #
248
+ # This method will take a String as input, a HTML colour such as 'slateblue',
249
+ # and proceed to return an Array containing three entries (R, G, B) as
250
+ # its value.
251
+ #
252
+ # For RGB colours we specify the code like this:
253
+ #
254
+ # 38;2;$R;$G;$B
255
+ #
256
+ # Thus:
257
+ #
258
+ # \e[38;2;R;G;Bm
259
+ #
260
+ # =========================================================================== #
261
+ def self.convert_this_html_colour_into_an_array_of_rgb_values(
262
+ html_colour = :random
263
+ )
264
+ case html_colour
265
+ when :random
266
+ html_colour = return_random_html_colour
267
+ end
268
+ if Colours.include_this_html_colour? html_colour
269
+ pointer = Colours.hash_html_colours?[html_colour.to_s] # <- Must be an input-String.
270
+ [ pointer[0], pointer[1], pointer[2] ] # <- Build the Array here.
271
+ else # else it is not included
272
+ nil
273
+ end
274
+ end; self.instance_eval { alias convert_html_colour_to_rgb_array convert_this_html_colour_into_an_array_of_rgb_values } # === Colours.convert_html_colour_to_rgb_array
275
+
276
+ # =========================================================================== #
277
+ # === Colours.return_random_rgb
278
+ # =========================================================================== #
279
+ def self.return_random_rgb
280
+ [random_value?, random_value?, random_value?]
281
+ end; self.instance_eval { alias return_rgb_as_array return_random_rgb } # === Colours.return_rgb_as_array
282
+
283
+ # =========================================================================== #
284
+ # === return_random_rgb
285
+ # =========================================================================== #
286
+ def return_random_rgb
287
+ Colours.return_random_rgb
288
+ end; alias return_rgb_as_array return_random_rgb # === return_rgb_as_array
289
+
290
+ # =========================================================================== #
291
+ # === rgb_value_as_escape_code_string
292
+ # =========================================================================== #
293
+ def rgb_value_as_escape_code_string(
294
+ array = [
295
+ random_value?,
296
+ random_value?,
297
+ random_value?
298
+ ],
299
+ g = nil,
300
+ b = nil
301
+ )
302
+ end; alias build_this_rgb_string rgb_value_as_escape_code_string # === build_this_rgb_string
303
+ alias rgb_value_as_string rgb_value_as_escape_code_string # === rgb_value_as_string
304
+ alias rgb rgb_value_as_escape_code_string # === rgb
305
+ alias rgb_format rgb_value_as_escape_code_string # === rgb_format
306
+ alias rgb_as_string rgb_value_as_escape_code_string # === rgb_as_string
307
+ alias colour_to_rgb_value rgb_value_as_escape_code_string # === colour_to_rgb_value
308
+
309
+ # =========================================================================== #
310
+ # === convert_this_rgb_value_to_that_hexadecimal_representation
311
+ # =========================================================================== #
312
+ def convert_this_rgb_value_to_that_hexadecimal_representation(
313
+ r, g = nil, b = nil
314
+ )
315
+ Colours.convert_this_rgb_value_to_that_hexadecimal_representation(r, g, b)
316
+ end; alias rgb_to_hex convert_this_rgb_value_to_that_hexadecimal_representation # === rgb_to_hex
317
+ alias to_hex convert_this_rgb_value_to_that_hexadecimal_representation # === to_hex
318
+
319
+ # =========================================================================== #
320
+ # === Colours.random_html_colour_with_this_text
321
+ #
322
+ # The first argument is the text that we wish to display.
323
+ #
324
+ # Usage example:
325
+ #
326
+ # puts Colours.random_html_colour_with_this_text 'foo bar'
327
+ #
328
+ # =========================================================================== #
329
+ def self.random_html_colour_with_this_text(
330
+ use_this_text = ''
331
+ )
332
+ "#{rgb_value_as_escape_code_string}#{use_this_text}#{restore?}"
333
+ end
334
+
335
+ # =========================================================================== #
336
+ # === Colours.rgb_print
337
+ #
338
+ # The first argument to this method should be an Array.
339
+ #
340
+ # We will print here. If you need a newline appended, you have to do
341
+ # so on your own, by appending a \n onto the text variable given to
342
+ # this method - or use Colours.rgb_puts() instead.
343
+ #
344
+ # Specific usage examples:
345
+ # Colours.rgb_print ["100", "247", "63"], 'Hello '
346
+ # Colours.rgb_print ["100", "247", "25"], 'World!'
347
+ # =========================================================================== #
348
+ def self.rgb_print(
349
+ array = %w( 100 247 63 ),
350
+ text = 'Hello world!'
351
+ )
352
+ print "#{rgb_value_as_escape_code_string(array)}#{text}#{REVERT}"
353
+ end
354
+
355
+ # =========================================================================== #
356
+ # === Colours.rgb_puts
357
+ #
358
+ # First argument should be an Array.
359
+ #
360
+ # We will use puts here.
361
+ #
362
+ # Specific usage examples:
363
+ # Colours.rgb_puts ["100", "247", "63"], 'Hello '
364
+ # Colours.rgb_puts ["100", "247", "25"], 'World!'
365
+ # =========================================================================== #
366
+ def self.rgb_puts(
367
+ array = %w( 100 247 63 ),
368
+ text = 'Hello world!'
369
+ )
370
+ rgb_print(array, "#{text}\n")
371
+ end
372
+
373
+ # =========================================================================== #
374
+ # === Colours.return_this_text_in_random_colour
375
+ #
376
+ # Invocation example:
377
+ # puts Colours.return_this_text_in_random_colour('Hello World!')
378
+ # =========================================================================== #
379
+ def self.return_this_text_in_random_colour(
380
+ show_this_text = ''
381
+ )
382
+ use_this_colour = ::Colours.random_colour?
383
+ "#{rgb(use_this_colour)}#{show_this_text}#{restore?}"
384
+ end; self.instance_eval { alias return_this_in_random_colour return_this_text_in_random_colour } # === Colours.return_this_in_random_colour
385
+
386
+ # =========================================================================== #
387
+ # === Colours.write_this_in_random_colour
388
+ #
389
+ # Usage example:
390
+ # Colours.write_this_in_random_colour 'hi there'
391
+ # =========================================================================== #
392
+ def self.write_this_in_random_colour(
393
+ i = ''
394
+ )
395
+ e return_this_text_in_random_colour(i)
396
+ end; self.instance_eval { alias output_in_a_random_colour write_this_in_random_colour } # === Colours.write_this_in_random_colour
397
+
398
+ # =========================================================================== #
399
+ # === Colours.rgb_value_as_escape_code_string
400
+ #
401
+ # This method will take a R,G,B value and show us a String representation
402
+ # =========================================================================== #
403
+ def self.rgb_value_as_escape_code_string(
404
+ array = [
405
+ random_value?,
406
+ random_value?,
407
+ random_value?
408
+ ],
409
+ g = nil,
410
+ b = nil
411
+ )
412
+ if array.is_a? Symbol
413
+ array = array.to_s
414
+ end
415
+ if array.is_a?(Array) and (array.size == 3)
416
+ r = array[0]
417
+ g = array[1]
418
+ b = array[2]
419
+ elsif array.is_a?(String) and g.nil? and b.nil?
420
+ # ======================================================================= #
421
+ # In this case we will assume a HTML colour. We thus have to
422
+ # determine its rgb value.
423
+ # ======================================================================= #
424
+ if ::Colours.is_this_html_colour_included?(array)
425
+ set_last_colour_used(array)
426
+ r, g, b = Colours.convert_this_html_colour_into_an_array_of_rgb_values(array)
427
+ else
428
+ puts 'The input is not a HTML colour:'
429
+ pp array
430
+ end
431
+ end
432
+ # =========================================================================== #
433
+ # The String that we build up in this method will have the ANSI escape
434
+ # code on the left side.
435
+ # =========================================================================== #
436
+ return "#{left?}#{r};#{g};#{b}m"
437
+ end; self.instance_eval { alias build_this_rgb_string rgb_value_as_escape_code_string } # === Colours.build_this_rgb_string
438
+ self.instance_eval { alias rgb_value_as_string rgb_value_as_escape_code_string } # === Colours.rgb_value_as_string
439
+ self.instance_eval { alias rgb rgb_value_as_escape_code_string } # === Colours.rgb
440
+ self.instance_eval { alias rgb_format rgb_value_as_escape_code_string } # === Colours.rgb_format
441
+ self.instance_eval { alias rgb_as_string rgb_value_as_escape_code_string } # === Colours.rgb_as_string
442
+ self.instance_eval { alias colour_to_rgb_value rgb_value_as_escape_code_string } # === Colours.colour_to_rgb_value
443
+
444
+ # =========================================================================== #
445
+ # === Colours.convert_this_rgb_value_to_that_hexadecimal_representation
446
+ #
447
+ # This method will convert RGB values to their hexadecimal (hex)
448
+ # representation.
449
+ #
450
+ # Invocation example:
451
+ #
452
+ # Colours.convert_this_rgb_value_to_that_hexadecimal_representation([240, 248, 255]) # => "F0F8FF"
453
+ # Colours.rgb_to_hex(255,0,0) # => "FF0000"
454
+ # Colours.rgb_to_hex('255255255')
455
+ # Colours.rgb_to_hex(:slateblue)
456
+ #
457
+ # =========================================================================== #
458
+ def self.convert_this_rgb_value_to_that_hexadecimal_representation(
459
+ r, g = nil, b = nil
460
+ )
461
+ hash = Colours.hash_html_colours?
462
+ if r.is_a?(Symbol) and g.nil? and b.nil? and
463
+ is_this_a_html_colour?(r)
464
+ return hash[r.to_s][3]
465
+ end
466
+ if r.is_a?(String) and !r.include?('#') and g.nil? and b.nil?
467
+ # ======================================================================= #
468
+ # In this case assume input such as '255255255'
469
+ # ======================================================================= #
470
+ splitted = r.split(/(...)/).reject(&:empty?)
471
+ r, g, b = splitted
472
+ end
473
+ if r.is_a?(Array) and (r.size > 1) and g.nil? and b.nil?
474
+ # ======================================================================= #
475
+ # In this case the user supplied only a single Array as input.
476
+ # ======================================================================= #
477
+ this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r)
478
+ else
479
+ this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r, g, b)
480
+ end
481
+ if this_html_colour
482
+ hash[this_html_colour][3]
483
+ else
484
+ nil
485
+ end
486
+ end; self.instance_eval { alias rgb_to_hex convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.rgb_to_hex
487
+ self.instance_eval { alias to_hex convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.to_hex
488
+ self.instance_eval { alias return_hexvalue_of_this_colour convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.return_hexvalue_of_this_colour
489
+
490
+ # =========================================================================== #
491
+ # === Colours.html_colour_to_rgb_value
492
+ #
493
+ # This method will return a String, representing the RGB values.
494
+ #
495
+ # It will, other than that, not make any other modifications; in particular
496
+ # it will NOT append a trailing "m" token.
497
+ #
498
+ # By default the R, G, B values will be separated via a ';' token. If
499
+ # you don't want this then modify it e. g. via: .tr(';',',').
500
+ #
501
+ # Usage examples:
502
+ #
503
+ # Colours.html_colour_to_rgb_value('slateblue') # => "106;90;205"
504
+ # Colours.html_colour_to_rgb_value('crimson') # => "220;20;60"
505
+ #
506
+ # =========================================================================== #
507
+ def self.html_colour_to_rgb_value(
508
+ this_html_colour = 'slateblue'
509
+ )
510
+ _ = Colours.convert_this_html_colour_into_an_array_of_rgb_values(this_html_colour)
511
+ return "#{_[0]};#{_[1]};#{_[2]}"
512
+ end; self.instance_eval { alias colour_to_rgb_value html_colour_to_rgb_value } # === Colours.colour_to_rgb_value
513
+ self.instance_eval { alias convert_html_colour_to_rgb_value html_colour_to_rgb_value } # === Colours.convert_html_colour_to_rgb_value
514
+ self.instance_eval { alias html_colour_to_stringified_rgb_values html_colour_to_rgb_value } # === Colours.html_colour_to_stringified_rgb_values
515
+
516
+ end
517
+
518
+ if __FILE__ == $PROGRAM_NAME
519
+ alias e puts
520
+ array = [240, 248, 255]
521
+ e 'Testing the RGB-functionality of the Colours project next.'
522
+ pp Colours.convert_this_html_colour_into_an_array_of_rgb_values
523
+ _ = 'royalblue'; e _+':'
524
+ pp Colours.convert_this_html_colour_into_an_array_of_rgb_values _
525
+ pp '[240, 248, 255] -> '+
526
+ Colours.convert_this_rgb_value_into_a_html_colour(array)
527
+ pp Colours.rgb_value_as_escape_code_string
528
+ pp Colours.colour_to_rgb_value('slateblue')
529
+ pp Colours.colour_to_rgb_value('crimson')
530
+ pp Colours.convert_this_rgb_value_to_that_hexadecimal_representation(array)
531
+ e
532
+ e Colours.rgb(122,56,141)+'Hello world!'
533
+ e Colours.colour_to_rgb_value('slateblue')
534
+ e Colours.rgb('slateblue')
535
+ e 'R;G;B value: '
536
+ pp Colours.colour_to_rgb_value('slateblue')
537
+ e
538
+ end
@@ -0,0 +1,2 @@
1
+ This directory will contain colour-related code for testing the
2
+ colours project programmatically.
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Add the test() method to the Colours module here.
6
+ # =========================================================================== #
7
+ # require 'colours/testing/testing.rb'
8
+ # =========================================================================== #
9
+ require 'colours/toplevel_methods/e.rb'
10
+ require 'colours/toplevel_methods/show_basic_colour_palette.rb'
11
+ require 'colours/toplevel_methods/make_colour.rb'
12
+
13
+ module Colours
14
+
15
+ # ========================================================================= #
16
+ # === Colours.test
17
+ #
18
+ # This class-method can be used to test the Colours module.
19
+ #
20
+ # It will be called from the test.rb file, in order to test all components
21
+ # of the Colours module.
22
+ #
23
+ # To invoke it, do:
24
+ #
25
+ # Colours.test
26
+ #
27
+ # ========================================================================= #
28
+ def self.test
29
+ require 'colours/basic_colours/basic_colours.rb'
30
+ require 'colours/colour_table/colour_table.rb'
31
+ cliner
32
+ show_basic_colour_palette
33
+ cliner
34
+ e red('Hello ')+cyan('World!')
35
+ e 'Hi '+Colours.red+'there.'+rev
36
+ e 'Hi '+Colours.cyan+'there.'+rev
37
+ e 'Hi '+Colours::BasicColours.bold_white+'there.'+rev
38
+ e 'Hi '+Colours.pink+'there.'+rev
39
+ e 'Hi '+Colours.brown+'there.'+rev
40
+ cliner
41
+ e CYAN+'Hi there.'
42
+ e BWHITE+'Hi there.'+BBLUE+' Yo there.'+rev
43
+ e sfancy('yo')+simp(' there')
44
+ disable_colours(true)
45
+ e sfancy('yo')+simp(' there')
46
+ enable_colours(true)
47
+ e sfancy('yo')+simp(' there')
48
+ e rgb_to_hex('155255255')
49
+ e col '/Depot/Audio'
50
+ e col '/Depot/Audio/Westbam_Sunshine.mp3'
51
+ e rev+'This is '+simp('elegant => simportant()')+'.'
52
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
53
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
54
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
55
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
56
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
57
+ ecomment 'An this # could be a comment.'
58
+ e
59
+ e 'Changing colour codes now. We should see different colours '+
60
+ 'when compared to the above.'
61
+ e
62
+ Colours.update_the_colour_codes_with
63
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
64
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
65
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
66
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
67
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
68
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
69
+ e 'Do we use colours? '+use_colours?.to_s
70
+ e cyan+' ==> Hi there.'
71
+ e red+' ==> Hi there.'
72
+ e green+' ==> Hi there.'
73
+ e brown+' ==> Hi there.'
74
+ e blue+' ==> Hi there.'
75
+ e teal+' ==> Hi there.'
76
+ e white+' ==> Hi there.'
77
+ e grey+' ==> Hi there.'
78
+ e lightblue+' ==> Hi there.'+red()+' yo'
79
+ e RED+'This is red galore.'
80
+ e 'right?'+Colours.rev
81
+ e BLUE+'This is blue now.'
82
+ e 'right?'+rev
83
+ e 'Hi there - this should be white.'
84
+ # html_colours?
85
+ p main_colours
86
+ main_colours.each {|entry|
87
+ send(entry, 'test')
88
+ }
89
+ e 'yo this should '+pink('be pink.')
90
+ puts CFANCY+' Hi there.'
91
+ puts CIMPORTANT+' Hi there.'
92
+ # Next, we will disable the colours.
93
+ disable_colours(true)
94
+ # The following ones have a newline.
95
+ e rev+'This is '+simportant('elegant => simportant().',true)
96
+ e rev+'This is '+sfancy('elegant => sfancy().',true)
97
+ e rev+'This is '+sdir('elegant => sdir().',true)
98
+ e rev+'This is '+sfile('elegant => sfancy().',true)
99
+ Colours.enable_colours(true)
100
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
101
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
102
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
103
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'; e
104
+ e 'Next, trying to underline:'
105
+ underline 'Hi there'
106
+ e 'Next trying eparse:'
107
+ eparse 'Joe: Hey Tim, how do you do?'
108
+ eparse 'Tim: Really fine. How about you?'
109
+ eparse ' Joe: ok man let us proceed'
110
+ eparse ' [name of character here] # show when this character last logged in'
111
+ e
112
+ e 'Next some tests with col():'
113
+ e
114
+ e ' '+col('/Depot/Audio/AVAILABLE_SONGS').to_s
115
+ e ' '+col('/Depot/Audio').to_s
116
+ e
117
+ cliner
118
+ e 'Now testing Colours.red("foobar"):'
119
+ e red('foobar')
120
+ e 'Next, we test Colours.enable() and Colours.disable()'
121
+ disable
122
+ e 'Colours.disable()'
123
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
124
+ e 'Colours.enable()'
125
+ enable
126
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
127
+ e rev+'The colour for symlinks is: '+simportant('Colours.colour_for_symlinks')
128
+ pp colour_for_symlinks
129
+ e rev+'A classical Hello World! example, and the colour-code for it.'
130
+ efancy 'Hello World!'
131
+ pp sfancy('Hello World!')
132
+ e 'Next removing some escape sequences:'
133
+ e
134
+ e remove_escape_sequences(" \e[1;31mhello world\e[0;0m # <-- "+
135
+ "This here is not coloured and it also does not have "+
136
+ "escape-sequences either.")
137
+ e
138
+ e 'Next testing whether Colours.yellow() works:'
139
+ e
140
+ e " hello #{Colours.yellow('world!')}#{rev}"
141
+ e
142
+ e 'Next testing Colours.eparse():'
143
+ e
144
+ eparse ' hello # world!'
145
+ e
146
+ e 'Next testing Colours.ecomment():'
147
+ e
148
+ ecomment ' hello # world!'
149
+ e
150
+ end
151
+
152
+ end
153
+
154
+ if __FILE__ == $PROGRAM_NAME
155
+ include Colours
156
+ Colours.test
157
+ end