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,314 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file will hold code that relates to the html-colours, such as
6
+ # "steelblue" or "royalblue" and so forth.
7
+ # =========================================================================== #
8
+ # require 'colours/toplevel_methods/methods_related_to_html_colours.rb'
9
+ # Colours.html_colour_to_hex_value(ARGV)
10
+ # =========================================================================== #
11
+ module Colours
12
+
13
+ require 'yaml'
14
+ require 'colours/constants/file_constants.rb'
15
+ require 'colours/html_colours/is_this_html_colour_included.rb'
16
+ require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
17
+
18
+ # ========================================================================= #
19
+ # === USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
20
+ # ========================================================================= #
21
+ USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR = :grey
22
+
23
+ # ========================================================================= #
24
+ # === REGEX_FOR_HTML_COLOURS
25
+ #
26
+ # This regex supports the use case where we can match against HTML
27
+ # colours. (The name is a bit of a misnomer, though.)
28
+ #
29
+ # For the following regex, see this entry at rubular:
30
+ #
31
+ # https://rubular.com/r/o5r4DneMTGOsbX
32
+ #
33
+ # ========================================================================= #
34
+ REGEX_FOR_HTML_COLOURS =
35
+ /<([()a-zA-Z0-9²→\n]+?)>/
36
+
37
+ # ========================================================================= #
38
+ # === Colours.replace_number_words_with_the_corresponding_html_colour
39
+ #
40
+ # The input to this method should be the String that contains HTML
41
+ # numbers such as <one> or <two>.
42
+ #
43
+ # This method can be customized a bit. One way to customize it is
44
+ # to pass the default colour to this method, as second argument.
45
+ # The default colour is (currently, in Oct 2020) grey.
46
+ #
47
+ # The third argument is a Hash. This Hash can be used to denote the
48
+ # default colours for <one>, <two> and so forth. So if you want
49
+ # to change the colours, pass in your own Hash into this method.
50
+ #
51
+ # Usage examples:
52
+ #
53
+ # x = Colours.replace_number_words_with_the_corresponding_html_colour("- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>.")
54
+ # x = "<one>Methämoglobin</one> ist <two>ungeeignet</two> für <three>den</three> Sauerstofftransport; die <two>roten Blutkörperchen</two>. Welches Enzymsystem ist dies?"
55
+ # y = Colours.replace_number_words_with_the_corresponding_html_colour(x)
56
+ #
57
+ # See also:
58
+ #
59
+ # https://rubular.com/r/XUPQJFKlDs2OYP
60
+ #
61
+ # ========================================================================= #
62
+ def self.replace_number_words_with_the_corresponding_html_colour(
63
+ i,
64
+ use_this_colour_for_the_default_colour = :default,
65
+ use_this_as_replacement_hash = :default
66
+ )
67
+ case use_this_colour_for_the_default_colour
68
+ when :default
69
+ use_this_colour_for_the_default_colour = USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
70
+ end
71
+ # ======================================================================= #
72
+ # Specify our "replacement-hash", that is colours used for e. g.
73
+ # <one>, <two> or <three>.
74
+ # ======================================================================= #
75
+ case use_this_as_replacement_hash
76
+ when :default,
77
+ :default_hash
78
+ use_this_as_replacement_hash = {
79
+ 'one' => :teal,
80
+ 'two' => :lightseagreen,
81
+ 'three' => :mediumseagreen, # ← Used to be 'peru' up until 23.11.2019.
82
+ 'four' => :olivedrab,
83
+ 'five' => :lightgreen
84
+ }
85
+ end
86
+ # ======================================================================= #
87
+ # === Enable support for <one>, <two>, <three>, <four> and <five> next.
88
+ # ======================================================================= #
89
+ if i.include?('<one>') or
90
+ i.include?('<two>') or
91
+ i.include?('<three>') or
92
+ i.include?('<four>') or
93
+ i.include?('<five>')
94
+ scanned_results = i.scan(
95
+ REGEX_FOR_HTML_COLOURS
96
+ ).flatten.uniq
97
+ scanned_results.each {|this_numbered_word|
98
+ if use_this_as_replacement_hash.has_key? this_numbered_word
99
+ i = i.dup if i.frozen?
100
+ replacement_colour = use_this_as_replacement_hash[this_numbered_word]
101
+ use_this_regex =
102
+ # =============================================================== #
103
+ # See:
104
+ #
105
+ # https://rubular.com/r/A7cJMTVSqbghej
106
+ #
107
+ # =============================================================== #
108
+ /<#{this_numbered_word}>([-#~≥!\e=><;,→⁻⁺@^„“γα_₂₃₄₅²äöüÄÖÜβß%&:≡°$A-Za-z0-9\n \?\\'\|\(\)\{\}\[\]\"\*\.\+]+)<\/#{this_numbered_word}>/
109
+ # ================================================================= #
110
+ # We must use .gsub!() because the colour-string may occur more
111
+ # than once.
112
+ # ================================================================= #
113
+ i.gsub!(
114
+ use_this_regex,
115
+ ::Colours::AllColourMethods.send(replacement_colour.to_sym, "\\1") { :omit_end }+
116
+ ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
117
+ )
118
+ # i << ::Colours.revert
119
+ end
120
+ }
121
+ end
122
+ i
123
+ end
124
+
125
+ # ========================================================================= #
126
+ # === Colours.does_this_string_include_a_html_colour?
127
+ # ========================================================================= #
128
+ def self.does_this_string_include_a_html_colour?(i)
129
+ result = (i =~ REGEX_FOR_HTML_COLOURS)
130
+ result = false if result.nil?
131
+ result
132
+ end
133
+
134
+ # ========================================================================= #
135
+ # === Colours.does_this_string_include_a_html_number?
136
+ #
137
+ # This method will return true if the string includes tags such as
138
+ # <one> or <two> and so forth.
139
+ # ========================================================================= #
140
+ def self.does_this_string_include_a_html_number?(i)
141
+ i.include?('<one>') or
142
+ i.include?('<two>') or
143
+ i.include?('<three>') or
144
+ i.include?('<four>') or
145
+ i.include?('<five>')
146
+ end
147
+
148
+ # ========================================================================= #
149
+ # === Colours.replace_html_colours_in_this_string
150
+ #
151
+ # This method will replace all HTML colours in a given string, such
152
+ # as "<slateblue>test</slateblue>", with the corresponding RGB colour
153
+ # variant for the commandline.
154
+ #
155
+ # Typically this refers to a terminal such as the KDE Konsole, and a
156
+ # shell such as bash (although other shells are fine too, and many
157
+ # other terminals, such as the gnome-terminal, most likely will work
158
+ # fine as well - but it is optimized for the KDE Konsole).
159
+ #
160
+ # This method should only be called after a prior check was done,
161
+ # to determine whether the given input String at hand does indeed
162
+ # include a valid HTML colour; otherwise it would be a bit pointless
163
+ # to invoke the method, if it is already known that the String at
164
+ # hand does not contain any HTML colour at all. In order to determine
165
+ # whether a String may include a valid HTML colour, the method called
166
+ # line_contains_a_valid_html_colour?() can be used.
167
+ #
168
+ # Usage example:
169
+ #
170
+ # Colours.replace_html_colours_in_this_string
171
+ #
172
+ # ========================================================================= #
173
+ def self.replace_html_colours_in_this_string(
174
+ i,
175
+ use_this_colour_for_the_default_colour = :default, # ← This specifies the default colour.
176
+ shall_we_revert_at_the_end_of_the_line = false
177
+ )
178
+ i = i.dup # We want to work on a copy.
179
+ result = ''.dup # Our result-string.
180
+ case use_this_colour_for_the_default_colour
181
+ when :default
182
+ use_this_colour_for_the_default_colour = USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
183
+ end
184
+ case shall_we_revert_at_the_end_of_the_line
185
+ when :revert
186
+ shall_we_revert_at_the_end_of_the_line = true
187
+ end
188
+ result << ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
189
+ # ======================================================================= #
190
+ # This method will make use of two different regexes.
191
+ # ======================================================================= #
192
+ scanned_results = i.scan(
193
+ REGEX_FOR_HTML_COLOURS
194
+ ).flatten
195
+ add_on_string = i.dup
196
+ scanned_results.uniq.each {|this_colour|
197
+ if is_this_a_valid_html_colour?(this_colour)
198
+ # =================================================================== #
199
+ # === Defining the Regex in use
200
+ #
201
+ # Regex see:
202
+ #
203
+ # https://rubular.com/r/5oYax0SCz7R7I6
204
+ #
205
+ # =================================================================== #
206
+ use_this_regex =
207
+ /<#{this_colour}>([\[\]\\{}\(\)\/!\-#*~:;≡=+a-zA-Z0-9₁₂₃₄₅₆äöüÄÖÜαβß&%°"',_\|\n\. ]+)<\/#{this_colour}>/
208
+ # =================================================================== #
209
+ # We must use .gsub!() because the colour-string may occur more
210
+ # than once. Unfortunately for longer Strings this becomes a bit
211
+ # fragile.
212
+ # =================================================================== #
213
+ part1 = ::Colours::AllColourMethods.send(this_colour.to_sym, "\\1") { :omit_end }
214
+ part2 = ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
215
+ add_on_string.gsub!(use_this_regex, part1+part2).dup
216
+ end
217
+ }
218
+ result << add_on_string
219
+ if shall_we_revert_at_the_end_of_the_line
220
+ result << ::Colours.revert
221
+ end
222
+ return result
223
+ end; self.instance_eval { alias replace_html_colours replace_html_colours_in_this_string } # === Colours.replace_html_colours
224
+ self.instance_eval { alias replace_all_raw_html_colours_in_this_line replace_html_colours_in_this_string } # === Colours.replace_all_raw_html_colours_in_this_line
225
+ self.instance_eval { alias replace_all_html_colours_in_this_line replace_html_colours_in_this_string } # === Colours.replace_all_html_colours_in_this_line
226
+
227
+ # ========================================================================= #
228
+ # === Colours.html_colour_to_hex_value
229
+ # ========================================================================= #
230
+ def self.html_colour_to_hex_value(
231
+ this_html_colour,
232
+ return_with_hash_key = true
233
+ )
234
+ if this_html_colour.is_a? Array
235
+ this_html_colour = this_html_colour.first
236
+ end
237
+ _ = file_html_colours_to_rgb?
238
+ if File.exist? _
239
+ dataset = YAML.load_file(_)
240
+ if dataset.has_key? this_html_colour
241
+ _ = dataset[this_html_colour].last
242
+ if return_with_hash_key
243
+ _ = _.dup if _.frozen?
244
+ _ = _.to_s unless _.is_a? String
245
+ _[0,0] = '#' if _.respond_to? :[]=
246
+ end
247
+ return _
248
+ end
249
+ end
250
+ return this_html_colour
251
+ end
252
+
253
+ # ========================================================================= #
254
+ # === Colours.eliminate_html
255
+ #
256
+ # This method simply combines two other methods, without any further
257
+ # checks inside of this method. The method will thus remove entries
258
+ # such as <one> or <steelblue>.
259
+ # ========================================================================= #
260
+ def self.eliminate_html(
261
+ i,
262
+ use_this_colour_for_the_default_colour = :default,
263
+ use_this_as_replacement_hash = :default_hash
264
+ )
265
+ i = Colours.replace_number_words_with_the_corresponding_html_colour(
266
+ i, use_this_colour_for_the_default_colour, use_this_as_replacement_hash
267
+ )
268
+ i = Colours.replace_html_colours_in_this_string(
269
+ i, use_this_colour_for_the_default_colour
270
+ )
271
+ return i
272
+ end; self.instance_eval { alias away_with_html_colours_and_special_numbers eliminate_html } # === Colours.away_with_html_colours_and_special_numbers
273
+
274
+ end
275
+
276
+ if __FILE__ == $PROGRAM_NAME
277
+ alias e puts
278
+ input = ARGV
279
+ if input.empty?
280
+ input << 'steelblue'
281
+ end
282
+ e 'Testing: Colours.html_colour_to_hex_value(ARGV) next'
283
+ e Colours.html_colour_to_hex_value(input)
284
+ e "Testing: Colours.does_this_string_include_a_html_number?('abc <one>def</one>') next"
285
+ puts Colours.does_this_string_include_a_html_number?('abc <one>def</one>')
286
+ # ========================================================================= #
287
+ # Test the behaviour of the method next:
288
+ # ========================================================================= #
289
+ this_line = "- <lightseagreen>hey</lightseagreen> yo <green>there</green>"
290
+ puts Colours.replace_html_colours(
291
+ this_line
292
+ )
293
+ puts Colours.does_this_string_include_a_html_colour?('<steelblue>')
294
+ e
295
+ e Colours.replace_number_words_with_the_corresponding_html_colour(
296
+ "- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
297
+ )
298
+ x = "<one>Methämoglobin</one> ist <two>ungeeignet</two> für <three>den</three> Sauerstofftransport; die <two>roten Blutkörperchen</two>. Welches Enzymsystem ist dies?"
299
+ e Colours.replace_number_words_with_the_corresponding_html_colour(x)
300
+ e Colours.replace_html_colours_in_this_string("<one>Methämoglobin</one> ist <steelblue>ungeeignet</steelblue>.")
301
+ e
302
+ string = "- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
303
+ e string
304
+ e Colours.replace_html_colours_in_this_string(
305
+ string
306
+ )
307
+ e
308
+ result = Colours.replace_all_html_colours_in_this_line(' |<steelblue>E</steelblue>]', :default, :revert)
309
+ e result
310
+ e
311
+ e 'And it looks like this via pp:'
312
+ e
313
+ pp result
314
+ end # html_colour_to_hex_value slateblue
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/misc.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/toplevel_methods/esystem.rb'
10
+ require 'colours/toplevel_methods/open_this_file.rb'
11
+ require 'colours/html_colours/misc.rb'
12
+
13
+ # ========================================================================= #
14
+ # === Colours.sanitize_line
15
+ #
16
+ # This method will replace one line with the proper R,G,B valid entries.
17
+ # ========================================================================= #
18
+ def self.sanitize_line(entry)
19
+ all_potential_matches = entry.scan(/<(\w+)>/).flatten
20
+ all_potential_matches.each {|substring|
21
+ entry.gsub!(/<\/>/, rev)
22
+ entry.gsub!(/<#{substring}>/, rgb_format(substring))
23
+ }
24
+ begin
25
+ require 'roebe/modules/remove_html.rb'
26
+ rescue LoadError; end
27
+ if Object.const_defined?(:Roebe) and
28
+ Roebe.respond_to?(:remove_html)
29
+ entry = Roebe.remove_html[entry]
30
+ end
31
+ return entry
32
+ end
33
+
34
+ # ========================================================================= #
35
+ # === Colours.read_and_display_this_file
36
+ #
37
+ # This method accepts a file path - in other words, the input should be
38
+ # the location of a specific file on your filesystem - and then simply
39
+ # reads in the content of said file via File.readlines().
40
+ #
41
+ # Content such as <slateblue> found in this file will be replaced
42
+ # with the respective R,G,B substring value.
43
+ #
44
+ # In the test/ subdirectory there is an example file for this - have
45
+ # a look there for more information.
46
+ # ========================================================================= #
47
+ def self.read_and_display_this_file(
48
+ i = TEST_FILE
49
+ )
50
+ i = i.to_s
51
+ if File.exist? i
52
+ new_array = []
53
+ data = File.readlines(i)
54
+ data.each {|entry|
55
+ # ======================================================================= #
56
+ # Check whether the entry has a <> tag:
57
+ # ======================================================================= #
58
+ if entry.include?('<') and entry.include?('>') and
59
+ entry.include?('</>')
60
+ # ================================================================= #
61
+ # Ok, we may assume that something like <slateblue> is there.
62
+ # ================================================================= #
63
+ entry = sanitize_line(entry)
64
+ end
65
+ new_array << entry
66
+ }
67
+ e new_array # For now we will simply output that modified Array.
68
+ else
69
+ e "Notice: The file at `#{sfile(i)}` does not exist."
70
+ end
71
+ end; self.instance_eval { alias read_file read_and_display_this_file } # === Colours.read_file
72
+
73
+ # ========================================================================= #
74
+ # === Colours.does_this_line_include_a_html_colour?
75
+ #
76
+ # This method can be used to determine whether the given input-string
77
+ # contains a valid HTML colour or whether it does not.
78
+ #
79
+ # Returns: a boolean.
80
+ #
81
+ # Invocation examples:
82
+ #
83
+ # Colours.does_this_line_include_a_html_colour? "<green>yo there</green> <orange>getline() function</orange>" # => true
84
+ # Colours.does_this_line_include_a_html_colour? "foo bar" # => false
85
+ #
86
+ # ========================================================================= #
87
+ def self.does_this_line_include_a_html_colour?(
88
+ line
89
+ )
90
+ Colours.html_colours?.any? {|entry|
91
+ line.include? entry
92
+ }
93
+ end
94
+
95
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/open_this_file.rb'
6
+ # =========================================================================== #
7
+ require 'colours/toplevel_methods/esystem.rb'
8
+
9
+ module Colours
10
+
11
+ # ========================================================================= #
12
+ # === self.open_this_file
13
+ # ========================================================================= #
14
+ def open_this_file(
15
+ shall_we_exit = false
16
+ )
17
+ case shall_we_exit
18
+ when :then_exit
19
+ shall_we_exit = true
20
+ end
21
+ _ = "bluefish #{__FILE__}"
22
+ esystem(_)
23
+ exit if shall_we_exit
24
+ end
25
+
26
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/prefer_this_colour_schemata.rb'
6
+ # =========================================================================== #
7
+ require 'colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb'
8
+ require 'colours/autogenerated/support_for_html_colours.rb'
9
+
10
+ module Colours
11
+
12
+ # ========================================================================= #
13
+ # === @prefer_this_colour_schemata
14
+ #
15
+ # The following Array ranks which colour schemata we will try to use.
16
+ # More important entries should come on top.
17
+ #
18
+ # Konsole will be the default, normally, followed by the 256 colours; and
19
+ # then the basic colours.
20
+ #
21
+ # Of course you can decide on your own via the .yml file, and other
22
+ # methods that allow us to change this setting, but when it comes
23
+ # to implementations such as for simp() or sfancy() then we will
24
+ # honour the setting in the yaml file (if we use any colours at all,
25
+ # that is). The yaml file is typically called
26
+ # "prefer_this_colour_schemata.yml".
27
+ # ========================================================================= #
28
+ @prefer_this_colour_schemata = YAML.load_file(FILE_PREFER_THIS_COLOUR_SCHEMATA)
29
+
30
+ # ========================================================================= #
31
+ # === @use_html_colours
32
+ #
33
+ # If the following variable is set to true then the HTML colours will
34
+ # be used, if available. These are colours such as 'slateblue' or
35
+ # 'crimson'.
36
+ # ========================================================================= #
37
+ @use_html_colours = false
38
+
39
+ # ========================================================================= #
40
+ # === @use_256_colours
41
+ # ========================================================================= #
42
+ @use_256_colours = false
43
+
44
+ # ========================================================================= #
45
+ # === @use_basic_colours
46
+ # ========================================================================= #
47
+ @use_basic_colours = false
48
+
49
+ # ========================================================================= #
50
+ # Next, we will set some other toplevel instance variables based on
51
+ # the value of this yaml file.
52
+ # ========================================================================= #
53
+ first_entry = @prefer_this_colour_schemata[1]
54
+ _second_entry = @prefer_this_colour_schemata[2]
55
+ _third_entry = @prefer_this_colour_schemata[3]
56
+
57
+ case first_entry
58
+ when :html_colours
59
+ @use_html_colours = true
60
+ when :support_for_256_colours
61
+ @use_256_colours = true
62
+ when :basic_colours
63
+ @use_basic_colours = true
64
+ end
65
+
66
+ # ========================================================================= #
67
+ # === Colours.prefer_which_colour_schemata?
68
+ # ========================================================================= #
69
+ def self.prefer_which_colour_schemata?
70
+ @prefer_this_colour_schemata[1]
71
+ end; self.instance_eval { alias prefer_which_colour_scheme? prefer_which_colour_schemata? } # === Colours.prefer_which_colour_scheme
72
+
73
+ # ========================================================================= #
74
+ # Designate @use_256_colours to true:
75
+ # ========================================================================= #
76
+ if prefer_which_colour_schemata? == :support_for_256_colours
77
+ @use_256_colours = true
78
+ end
79
+
80
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/random_html_colour.rb'
6
+ # =========================================================================== #
7
+ require 'colours/html_colours/misc.rb'
8
+
9
+ module Colours
10
+
11
+ # =========================================================================== #
12
+ # === Colours.random_html_colour
13
+ #
14
+ # This method will simply return a (one) random HTML colour, in long
15
+ # format, e. g. "teal" or "slateblue".
16
+ #
17
+ # If you wish to have it colourized properly, you need to use another
18
+ # method.
19
+ #
20
+ # Usage examples:
21
+ # Colours.random_colour? # => "teal"
22
+ # Colours.random_colour? # => "blueviolet"
23
+ # =========================================================================== #
24
+ def self.random_html_colour
25
+ ::Colours::HtmlColours.random_colour?
26
+ end; self.instance_eval { alias random_colour? random_html_colour } # === Colours.random_colour?
27
+ self.instance_eval { alias return_random_html_colour random_html_colour } # === Colours.return_random_html_colour
28
+
29
+ # =========================================================================== #
30
+ # === random_colour?
31
+ # =========================================================================== #
32
+ def random_colour?
33
+ ::Colours::HtmlColours.random_colour?
34
+ end; alias random_colour random_colour? # === random_colour
35
+ alias random random_colour? # === random
36
+ alias sample random_colour? # === sample
37
+ alias random_html_colour random_colour? # === random_html_colour
38
+ alias return_random_html_colour random_colour? # === return_random_html_colour
39
+
40
+ end
41
+
42
+ if __FILE__ == $PROGRAM_NAME
43
+ puts Colours.random_colour? # => "teal"
44
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/random_value.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours.random_value?
11
+ #
12
+ # We will obtain a random value between 0 and 255, hence why we will
13
+ # use rand(256).
14
+ # ========================================================================= #
15
+ def self.random_value?
16
+ rand(256)
17
+ end; self.instance_eval { alias random_value random_value? } # === Colours.random_value
18
+ self.instance_eval { alias rvalue random_value? } # === Colours.rvalue
19
+ self.instance_eval { alias r? random_value? } # === Colours.r?
20
+ self.instance_eval { alias g? random_value? } # === Colours.g?
21
+ self.instance_eval { alias b? random_value? } # === Colours.b?
22
+
23
+ # ========================================================================= #
24
+ # === random_value
25
+ #
26
+ # We will obtain a random value between 0 and 255, hence why we will
27
+ # use rand(256).
28
+ # ========================================================================= #
29
+ def random_value?
30
+ Colours.random_value?
31
+ end; alias rvalue random_value? # === rvalue
32
+ alias random_value random_value? # === random_value
33
+ alias r? random_value? # === r?
34
+ alias g? random_value? # === g?
35
+ alias b? random_value? # === b?
36
+
37
+ end