colours 0.8.12 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +331 -200
  3. data/bin/colours +2 -2
  4. data/bin/show_basic_colour_palette +7 -0
  5. data/colours.gemspec +1 -2
  6. data/doc/README.gen +294 -178
  7. data/doc/how_to_pick_your_own_colours/how_to_pick_your_own_colours.md +33 -0
  8. data/lib/colours/autoalias_e.rb +4 -1
  9. data/lib/colours/autogenerated/256_colours_instance_methods.rb +1429 -0
  10. data/lib/colours/autogenerated/256_colours_methods.rb +1429 -0
  11. data/lib/colours/autogenerated/html_colours_instance_methods.rb +1191 -0
  12. data/lib/colours/autogenerated/html_colours_methods.rb +1191 -0
  13. data/lib/colours/base/base.rb +61 -13
  14. data/lib/colours/class/colours.rb +8 -6
  15. data/lib/colours/{toplevel_methods/use_colours.rb → colour/colour.rb} +4 -125
  16. data/lib/colours/commandline/README.md +2 -1
  17. data/lib/colours/commandline/commandline.rb +177 -34
  18. data/lib/colours/constants/constants.rb +752 -6
  19. data/lib/colours/e/README.md +6 -6
  20. data/lib/colours/eparse/eparse.rb +2 -1
  21. data/lib/colours/essentials/README.md +5 -0
  22. data/lib/colours/{basic_colours/basic_colours.rb → essentials/essentials.rb} +87 -85
  23. data/lib/colours/html_colours/README.md +2 -1
  24. data/lib/colours/html_colours/hash_html_colours.rb +168 -0
  25. data/lib/colours/html_colours/html_colours.rb +226 -244
  26. data/lib/colours/html_colours/push_the_html_colours_methods_onto_the_toplevel_namespace.rb +30 -0
  27. data/lib/colours/html_colours/random_html_colour.rb +67 -0
  28. data/lib/colours/{requires/require_the_basic_colours.rb → html_colours.rb} +4 -2
  29. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +12 -10
  30. data/lib/colours/module_256_colours/module_256_colours.rb +465 -0
  31. data/lib/colours/project/project.rb +3 -1
  32. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +4 -0
  33. data/lib/colours/rainbow_colours/constants.rb +3 -3
  34. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +9 -10
  35. data/lib/colours/rainbow_colours/print_rainbow_line.rb +4 -4
  36. data/lib/colours/rainbow_colours/println_ani.rb +7 -7
  37. data/lib/colours/rainbow_colours/println_plain.rb +2 -2
  38. data/lib/colours/rainbow_colours/rainbow.rb +31 -1
  39. data/lib/colours/rainbow_colours/report_errors.rb +7 -7
  40. data/lib/colours/rainbow_colours/returnln_plain.rb +3 -3
  41. data/lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb +409 -0
  42. data/lib/colours/requires/require_autogenerated_colour_methods.rb +4 -1
  43. data/lib/colours/requires/{require_the_colour_table.rb → require_essentials.rb} +2 -2
  44. data/lib/colours/requires/require_save_file.rb +11 -0
  45. data/lib/colours/requires/require_the_256_colours_module.rb +1 -3
  46. data/lib/colours/requires/require_the_colour_methods.rb +1 -22
  47. data/lib/colours/requires/require_the_project.rb +31 -29
  48. data/lib/colours/requires/require_the_toplevel_methods.rb +2 -20
  49. data/lib/colours/rgb/rgb.rb +107 -89
  50. data/lib/colours/{colour_methods/colour_methods.rb → sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb} +467 -405
  51. data/lib/colours/testing/testing.rb +1 -3
  52. data/lib/colours/toplevel_methods/e.rb +9 -13
  53. data/lib/colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb +57 -0
  54. data/lib/colours/toplevel_methods/{revert.rb → rev.rb} +5 -48
  55. data/lib/colours/toplevel_methods/toplevel_methods.rb +1204 -0
  56. data/lib/colours/version/version.rb +2 -2
  57. data/lib/colours/yaml/256_colours.yml +776 -257
  58. data/lib/colours/yaml/html_colours.yml +1 -1
  59. data/lib/colours/yaml/prefer_this_colour_schemata.yml +1 -1
  60. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +5 -1
  61. data/lib/colours.rb +1 -1
  62. data/test/testing_256_colours_support.rb +10 -1
  63. data/test/testing_replace_number_words_with_the_corresponding_html_colour.rb +15 -9
  64. data/test/testing_the_colour_methods_such_as_simp_sdir_sfile_swarn_sfancy_sargument_and_ssymlink.rb +53 -0
  65. metadata +30 -57
  66. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +0 -28
  67. data/lib/colours/256_colours/support_for_256_colours.rb +0 -196
  68. data/lib/colours/autogenerated/support_for_256_colours.rb +0 -2235
  69. data/lib/colours/autogenerated/support_for_html_colours.rb +0 -1778
  70. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +0 -7001
  71. data/lib/colours/basic_colours/README.md +0 -4
  72. data/lib/colours/colour_methods/README.md +0 -11
  73. data/lib/colours/colour_table/README.md +0 -2
  74. data/lib/colours/colour_table/colour_table.rb +0 -282
  75. data/lib/colours/commandline/menu.rb +0 -122
  76. data/lib/colours/constants/escape.rb +0 -22
  77. data/lib/colours/constants/file_constants.rb +0 -73
  78. data/lib/colours/constants/hash_ansi_colours.rb +0 -39
  79. data/lib/colours/constants/hash_simple_colours.rb +0 -148
  80. data/lib/colours/constants/misc.rb +0 -361
  81. data/lib/colours/constants/newline.rb +0 -14
  82. data/lib/colours/constants/registered_colour_methods.rb +0 -53
  83. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +0 -22
  84. data/lib/colours/toplevel_methods/autogenerate.rb +0 -310
  85. data/lib/colours/toplevel_methods/bold.rb +0 -41
  86. data/lib/colours/toplevel_methods/bold_and_italic.rb +0 -38
  87. data/lib/colours/toplevel_methods/cat.rb +0 -39
  88. data/lib/colours/toplevel_methods/clear_screen.rb +0 -18
  89. data/lib/colours/toplevel_methods/cliner.rb +0 -17
  90. data/lib/colours/toplevel_methods/col.rb +0 -54
  91. data/lib/colours/toplevel_methods/esystem.rb +0 -19
  92. data/lib/colours/toplevel_methods/html_colour_to_hex_value.rb +0 -41
  93. data/lib/colours/toplevel_methods/html_colourize.rb +0 -69
  94. data/lib/colours/toplevel_methods/is_on_roebe.rb +0 -16
  95. data/lib/colours/toplevel_methods/italic.rb +0 -110
  96. data/lib/colours/toplevel_methods/make_colour.rb +0 -28
  97. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +0 -336
  98. data/lib/colours/toplevel_methods/misc.rb +0 -226
  99. data/lib/colours/toplevel_methods/open_this_file.rb +0 -26
  100. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +0 -88
  101. data/lib/colours/toplevel_methods/random_value.rb +0 -37
  102. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +0 -112
  103. data/lib/colours/toplevel_methods/set_last_colour_used.rb +0 -32
  104. data/lib/colours/toplevel_methods/shell_file_containing_the_html_colours.sh +0 -148
  105. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +0 -36
  106. data/lib/colours/toplevel_methods/underline.rb +0 -130
  107. data/test/testing_the_colour_methods.rb +0 -36
  108. /data/doc/{COLOUR_CODES_CHART.md → colour_codes_chart/colour_codes_chart.md} +0 -0
@@ -4,14 +4,14 @@
4
4
  # =========================================================================== #
5
5
  # require 'colours/rainbow_colours/print_rainbow_line.rb'
6
6
  # =========================================================================== #
7
- require 'colours/toplevel_methods/e.rb'
8
- require 'colours/rainbow_colours/constants.rb'
9
- require 'colours/rainbow_colours/println_plain.rb'
10
-
11
7
  module Colours
12
8
 
13
9
  module RainbowColours
14
10
 
11
+ require 'colours/toplevel_methods/e.rb'
12
+ require 'colours/rainbow_colours/constants.rb'
13
+ require 'colours/rainbow_colours/println_plain.rb'
14
+
15
15
  # ========================================================================= #
16
16
  # === Colours::RainbowColours.e
17
17
  # ========================================================================= #
@@ -2,12 +2,12 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- require 'colours/rainbow_colours/println_plain.rb'
6
-
7
5
  module Colours
8
6
 
9
7
  module RainbowColours
10
8
 
9
+ require 'colours/rainbow_colours/println_plain.rb'
10
+
11
11
  # ========================================================================= #
12
12
  # === Colours::RainbowColours.println_ani
13
13
  #
@@ -15,17 +15,17 @@ module RainbowColours
15
15
  # that is, set to true.
16
16
  # ========================================================================= #
17
17
  def self.println_ani(
18
- str, opts = {}
18
+ str, hash_options = {}
19
19
  )
20
20
  return if str.empty? # Return early in this case.
21
- (1..opts[:duration]).each { |irrelevant_variable|
21
+ (1 .. hash_options[:duration]).each { |irrelevant_variable|
22
22
  print "\e[#{str.length}D"
23
- opts[:os] += opts[:spread]
23
+ hash_options[:os] += hash_options[:spread]
24
24
  # ===================================================================== #
25
25
  # Next, delegate to println_plain():
26
26
  # ===================================================================== #
27
- println_plain(str, opts)
28
- sleep 1.0/opts[:speed]
27
+ println_plain(str, hash_options)
28
+ sleep(1.0/hash_options[:speed])
29
29
  }
30
30
  end
31
31
 
@@ -4,12 +4,12 @@
4
4
  # =========================================================================== #
5
5
  # require 'colours/rainbow_colours/println_plain.rb'
6
6
  # =========================================================================== #
7
- require 'colours/rainbow_colours/returnln_plain.rb'
8
-
9
7
  module Colours
10
8
 
11
9
  module RainbowColours
12
10
 
11
+ require 'colours/rainbow_colours/returnln_plain.rb'
12
+
13
13
  # ========================================================================= #
14
14
  # === Colours::RainbowColours.println_plain
15
15
  #
@@ -35,4 +35,34 @@ module RainbowColours
35
35
  '#%02X%02X%02X' % [ red, green, blue ]
36
36
  end
37
37
 
38
- end; end
38
+ end
39
+
40
+ # =========================================================================== #
41
+ # === Colours.cat
42
+ #
43
+ # The first argument may be ARGF. It ought to respond to .each anyway.
44
+ #
45
+ # Note that .cat() will delegate towards print_line().
46
+ # =========================================================================== #
47
+ def self.cat(
48
+ file_descriptor, hash_options = {}
49
+ )
50
+ print "\e[?25l" if hash_options[:animate] # Print this if we animate (enabling psychedelics).
51
+ # ========================================================================= #
52
+ # Iterate over the file_descriptor passed.
53
+ # ========================================================================= #
54
+ file_descriptor.each { |line|
55
+ hash_options[:os] += 1 # Increase the output-count.
56
+ # ======================================================================= #
57
+ # Next, colourize the line. This depends on the method called
58
+ # print_rainbow_line().
59
+ # ======================================================================= #
60
+ RainbowColours.print_rainbow_line(
61
+ line, hash_options
62
+ ) # Delegate towards print_line.
63
+ }
64
+ ensure
65
+ print "\e[?25h" if hash_options[:animate]
66
+ end
67
+
68
+ end
@@ -6,27 +6,27 @@
6
6
  # =========================================================================== #
7
7
  module Colours
8
8
 
9
- module RainbowColours
9
+ module RainbowColours # === Colours::RainbowColours
10
10
 
11
11
  # ========================================================================= #
12
12
  # === Colours::RainbowColours.report_no_such_file_or_directory
13
13
  # ========================================================================= #
14
- def self.report_no_such_file_or_directory(file)
15
- e "Colours::RainbowColours: #{file}: No such file or directory"
14
+ def self.report_no_such_file_or_directory(i)
15
+ e "Colours::RainbowColours: #{i}: No such file or directory"
16
16
  end
17
17
 
18
18
  # ========================================================================= #
19
19
  # === Colours::RainbowColours.report_is_a_directory
20
20
  # ========================================================================= #
21
- def self.report_is_a_directory(file)
22
- e "Colours::RainbowColours: #{file}: Is a directory"
21
+ def self.report_is_a_directory(i)
22
+ e "Colours::RainbowColours: #{i}: Is a directory"
23
23
  end
24
24
 
25
25
  # ========================================================================= #
26
26
  # === Colours::RainbowColours.report_permission_denied
27
27
  # ========================================================================= #
28
- def self.report_permission_denied(file)
29
- e "Colours::RainbowColours: #{file}: Permission denied"
28
+ def self.report_permission_denied(i)
29
+ e "Colours::RainbowColours: #{i}: Permission denied"
30
30
  end
31
31
 
32
32
  end; end
@@ -4,13 +4,13 @@
4
4
  # =========================================================================== #
5
5
  # require 'colours/rainbow_colours/returnln_plain.rb'
6
6
  # =========================================================================== #
7
- require 'colours/rainbow_colours/rainbow.rb'
8
- require 'colours/rainbow_colours/set_mode.rb'
9
-
10
7
  module Colours
11
8
 
12
9
  module RainbowColours
13
10
 
11
+ require 'colours/rainbow_colours/rainbow.rb'
12
+ require 'colours/rainbow_colours/set_mode.rb'
13
+
14
14
  # ========================================================================= #
15
15
  # === Colours::RainbowColours.returnln_plain
16
16
  #
@@ -0,0 +1,409 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Colours::ReplaceTokensWithColourCode
6
+ #
7
+ # This class can take a String, such as "<one>foo</one>bar" and turn
8
+ # it into another String containing a variant that has ANSI colour
9
+ # codes embedded.
10
+ #
11
+ # The input for this class should be the String that contains HTML-like
12
+ # numbers, such as <one> or <two>.
13
+ #
14
+ # The class has to remain flexible, as downstream code may want to
15
+ # customize it. One way to customize it is to pass the default
16
+ # colour to this method, as second argument.
17
+ #
18
+ # The default colour is (currently, in Oct 2020) grey.
19
+ #
20
+ # Usage example:
21
+ #
22
+ # Colours::ReplaceTokensWithColourCode.new(ARGV)
23
+ #
24
+ # =========================================================================== #
25
+ # require 'colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb'
26
+ # Colours::ReplaceTokensWithColourCode.new(ARGV)
27
+ # =========================================================================== #
28
+ require 'colours/base/base.rb'
29
+
30
+ module Colours
31
+
32
+ class ReplaceTokensWithColourCode < Base # === Colours::ReplaceTokensWithColourCode
33
+
34
+ require 'colours/autogenerated/html_colours_methods.rb'
35
+
36
+ # ========================================================================= #
37
+ # === ARRAY_ALLOWED_HTML_COLOURS
38
+ # ========================================================================= #
39
+ ARRAY_ALLOWED_HTML_COLOURS = ::Colours.array_html_colours?.map {|entry|
40
+ entry.to_sym
41
+ }
42
+
43
+ # ========================================================================= #
44
+ # === ARRAY_ALLOWED_NUMBERED_WORDS
45
+ # ========================================================================= #
46
+ ARRAY_ALLOWED_NUMBERED_WORDS = %w(
47
+ one
48
+ two
49
+ three
50
+ four
51
+ five
52
+ )
53
+
54
+ # ========================================================================= #
55
+ # === HASH_DEFAULT_REPLACEMENT_COLOURS
56
+ # ========================================================================= #
57
+ HASH_DEFAULT_REPLACEMENT_COLOURS = {
58
+ one: :teal, # This could also be :steelblue.
59
+ two: :lightseagreen, # Or :dodgerblue.
60
+ three: :mediumseagreen, # ← Used to be 'peru' up until 23.11.2019.
61
+ four: :mediumorchid, # ← Used to be 'olivedrab' up until 06.12.2022.
62
+ five: :lightgreen, # Or :olivedrab.
63
+ rev: ::Colours.rev, # Or USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR.
64
+ default_colour: ::Colours.rev # This is actually the same as :rev. Could also be USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR.
65
+ }
66
+
67
+ # ========================================================================= #
68
+ # === initialize
69
+ # ========================================================================= #
70
+ def initialize(
71
+ commandline_arguments = nil,
72
+ run_already = true,
73
+ &block
74
+ )
75
+ reset
76
+ set_commandline_arguments(
77
+ commandline_arguments
78
+ )
79
+ # ======================================================================= #
80
+ # === Handle blocks next
81
+ # ======================================================================= #
82
+ if block_given?
83
+ yielded = yield
84
+ # ===================================================================== #
85
+ # === Handle Hashes next
86
+ # ===================================================================== #
87
+ if yielded.is_a? Hash
88
+ do_update_the_main_hash_with_this_dataset(yielded)
89
+ end
90
+ end
91
+ case run_already
92
+ # ======================================================================= #
93
+ # === :do_not_run_yet
94
+ # ======================================================================= #
95
+ when :do_not_run_yet
96
+ run_already = false
97
+ end
98
+ run if run_already
99
+ end
100
+
101
+ # ========================================================================= #
102
+ # === reset (reset tag)
103
+ # ========================================================================= #
104
+ def reset
105
+ # ======================================================================= #
106
+ # === @hash_replacement_colours
107
+ #
108
+ # We need to specify a default replacement-Hash. The user can override
109
+ # it, or individual elements.
110
+ # ======================================================================= #
111
+ @hash_replacement_colours = HASH_DEFAULT_REPLACEMENT_COLOURS
112
+ # ======================================================================= #
113
+ # === @sanitized_line
114
+ # ======================================================================= #
115
+ @sanitized_line = nil
116
+ # ======================================================================= #
117
+ # === @main_regex
118
+ # ======================================================================= #
119
+ @main_regex = main_regex?
120
+ end
121
+
122
+ # ========================================================================= #
123
+ # === rev?
124
+ # ========================================================================= #
125
+ def rev?
126
+ if @hash_replacement_colours.has_key?(:rev)
127
+ return @hash_replacement_colours[:rev]
128
+ else
129
+ ::Colours.rev
130
+ end
131
+ end
132
+
133
+ # ========================================================================= #
134
+ # === is_this_a_HTML_colour?
135
+ # ========================================================================= #
136
+ def is_this_a_HTML_colour?(i)
137
+ ARRAY_ALLOWED_HTML_COLOURS.include?(i)
138
+ end
139
+
140
+ # ========================================================================= #
141
+ # === sanitized_line?
142
+ # ========================================================================= #
143
+ def sanitized_line?
144
+ @sanitized_line
145
+ end; alias result? sanitized_line? # === result?
146
+
147
+ # ========================================================================= #
148
+ # === main_regex?
149
+ # ========================================================================= #
150
+ def main_regex?
151
+ REGEX_FOR_HTML_COLOURS
152
+ end
153
+
154
+ # ========================================================================= #
155
+ # === do_update_the_main_hash_with_this_dataset
156
+ # ========================================================================= #
157
+ def do_update_the_main_hash_with_this_dataset(i)
158
+ @hash_replacement_colours.update(i)
159
+ end
160
+
161
+ # ========================================================================= #
162
+ # === hash_replacement_colours?
163
+ # ========================================================================= #
164
+ def hash_replacement_colours?
165
+ @hash_replacement_colours
166
+ end; alias main_hash? hash_replacement_colours? # == main_hash?
167
+
168
+ # ========================================================================= #
169
+ # === set_hash_replacement_colours
170
+ # ========================================================================= #
171
+ def set_hash_replacement_colours(i)
172
+ @hash_replacement_colours = i
173
+ end; alias set_use_this_hash set_hash_replacement_colours # === set_use_this_hash
174
+
175
+ # ========================================================================= #
176
+ # === parse_this_complex_line (parse tag)
177
+ #
178
+ # This is the method that will parse a complex line. A complex line is
179
+ # a line that may include e. g. <one> as well as <royalblue> and
180
+ # similar such entities.
181
+ #
182
+ # This method will always assign towards @sanitized_line whenever it
183
+ # is called.
184
+ # ========================================================================= #
185
+ def parse_this_complex_line(
186
+ i,
187
+ use_this_as_replacement_hash = :default, # This is, as the name suggests, the replacement Hash.
188
+ rev = nil # This then defaults to ::Colours.revert
189
+ )
190
+ rev = ::Colours.rev if rev.nil? # Add a small safeguard here.
191
+ if i and does_this_string_contain_a_special_token?(i)
192
+ use_this_colour_for_the_default_colour = rev.to_sym # Default.
193
+ # ===================================================================== #
194
+ # === The replacement Hash
195
+ #
196
+ # Specify our "replacement-hash", that is colours used for e. g.
197
+ # <one>, <two> or <three> or HTML colours such as <royalblue>
198
+ # and so forth.
199
+ #
200
+ # This clause only matters if we have a special token in the given
201
+ # String.
202
+ # ===================================================================== #
203
+ case use_this_as_replacement_hash
204
+ # ===================================================================== #
205
+ # === :default
206
+ #
207
+ # The default entry-point.
208
+ # ===================================================================== #
209
+ when :default,
210
+ :default_hash
211
+ # =================================================================== #
212
+ # The following hash can be used as a default "replacement" Hash.
213
+ # =================================================================== #
214
+ use_this_as_replacement_hash = @hash_replacement_colours
215
+ end
216
+ # ===================================================================== #
217
+ # Next we can finally replace the found keyword. We have to make a
218
+ # decision here, though - if it is part of the Array containing
219
+ # all HTML colours, then we'll replace it with the HTML colour at
220
+ # hand; otherwise we'll use the replacement Hash as-is:
221
+ # ===================================================================== #
222
+ scanned_result = i.scan(
223
+ @main_regex
224
+ ).flatten
225
+ # ===================================================================== #
226
+ # We then know that this line contains either a HTML colour or a
227
+ # numbered word, such as one, two, three, four or five.
228
+ # ===================================================================== #
229
+ _ = use_this_as_replacement_hash # Our replacement Hash.
230
+ rev = _[:rev] if _.is_a?(Hash) and _.has_key?(:rev)
231
+ scanned_result.each {|this_numbered_word|
232
+ # =================================================================== #
233
+ # Since as of December 2021 we only accept Symbols here, hence
234
+ # the .to_sym call next.
235
+ # =================================================================== #
236
+ this_numbered_word = this_numbered_word.to_sym
237
+ i = i.dup if i.frozen?
238
+ if is_this_a_HTML_colour?(this_numbered_word)
239
+ use_this_regex =
240
+ # =============================================================== #
241
+ # We will simply re-use the regex-generator near the top of this
242
+ # file here.
243
+ # =============================================================== #
244
+ ::Colours.return_main_regex_to_use_for_obtaining_the_full_content(this_numbered_word)
245
+ # ================================================================= #
246
+ # We must use .gsub!() because the colour-string may occur more
247
+ # than once in the given String.
248
+ # ================================================================= #
249
+ begin
250
+ if use_this_colour_for_the_default_colour == :"\e[0;37m" # Ad-hoc fix.
251
+ i.gsub!(
252
+ use_this_regex,
253
+ ::Colours::HtmlColoursMethods.send(this_numbered_word.to_sym, "\\1") { :omit_end }+
254
+ use_this_colour_for_the_default_colour.to_s
255
+ )
256
+ else
257
+ i.gsub!(
258
+ use_this_regex,
259
+ ::Colours::HtmlColoursMethods.send(this_numbered_word.to_sym, "\\1") { :omit_end }+
260
+ ::Colours::HtmlColoursMethods.send(use_this_colour_for_the_default_colour,'') { :omit_end }
261
+ )
262
+ end
263
+ rescue NoMethodError => exception
264
+ pp 'use_this_colour_for_the_default_colour was:'
265
+ pp use_this_colour_for_the_default_colour
266
+ pp exception
267
+ end
268
+ elsif _.has_key?(this_numbered_word) # This is for a numbered word, such as <one>.
269
+ # ================================================================= #
270
+ # === :default_colour
271
+ # ================================================================= #
272
+ if use_this_as_replacement_hash.has_key? :default_colour
273
+ use_this_colour_for_the_default_colour = use_this_as_replacement_hash[:default_colour]
274
+ end
275
+ if use_this_as_replacement_hash.has_key? :rev
276
+ use_this_colour_for_the_default_colour = use_this_as_replacement_hash[:rev]
277
+ end
278
+ replacement_colour = _[this_numbered_word] # This will become the new main colour.
279
+ use_this_regex =
280
+ # =============================================================== #
281
+ # We will simply re-use the regex-generator near the top of this
282
+ # file here.
283
+ # =============================================================== #
284
+ ::Colours.return_main_regex_to_use_for_obtaining_the_full_content(this_numbered_word)
285
+ # ================================================================= #
286
+ # We must use .gsub!() because the colour-string may occur more
287
+ # than once in the given String.
288
+ # ================================================================= #
289
+ i.gsub!(
290
+ use_this_regex,
291
+ ::Colours.colourize(replacement_colour.to_sym, "\\1")+
292
+ ::Colours::HtmlColoursMethods.send(use_this_colour_for_the_default_colour,'') { :omit_end }
293
+ )
294
+ end
295
+ }
296
+ # else # else we do not have to do anything.
297
+ end
298
+ @sanitized_line = i.dup # And assign it here.
299
+ return @sanitized_line # Always return it here.
300
+ end; alias parse parse_this_complex_line # === parse
301
+
302
+ # ========================================================================= #
303
+ # === run (run tag)
304
+ # ========================================================================= #
305
+ def run
306
+ second_argument = second_argument?
307
+ if second_argument and second_argument.is_a?(Hash)
308
+ set_hash_replacement_colours(second_argument)
309
+ end
310
+ _ = first_argument?
311
+ if _ and !_.nil?
312
+ parse(_)
313
+ end
314
+ end
315
+
316
+ # ========================================================================= #
317
+ # === does_this_string_contain_a_special_token?
318
+ #
319
+ # A special token is either a HTML colour, or something like
320
+ # <one></one>.
321
+ # ========================================================================= #
322
+ def does_this_string_contain_a_special_token?(i)
323
+ scanned_result = i.scan(
324
+ @main_regex
325
+ ).flatten
326
+ does_it_include_a_HTML_colour = scanned_result.any? {|entry|
327
+ ARRAY_ALLOWED_HTML_COLOURS.include?(entry.to_sym)
328
+ }
329
+ does_it_include_a_numbered_word = scanned_result.any? {|entry|
330
+ ARRAY_ALLOWED_NUMBERED_WORDS.include?(entry)
331
+ }
332
+ return (does_it_include_a_HTML_colour or does_it_include_a_numbered_word)
333
+ end
334
+
335
+ # ========================================================================= #
336
+ # === Colours::ReplaceTokensWithColourCode[]
337
+ # ========================================================================= #
338
+ def self.[](i = ARGV)
339
+ new(i)
340
+ end
341
+
342
+ end
343
+
344
+ # =========================================================================== #
345
+ # === Colours.does_this_string_contain_a_special_token?
346
+ # =========================================================================== #
347
+ def self.does_this_string_contain_a_special_token?(i, &block)
348
+ _ = ::Colours::ReplaceTokensWithColourCode.new(i, :do_not_run_yet, &block)
349
+ _.does_this_string_contain_a_special_token?(i)
350
+ end; self.instance_eval { alias is_this_replacement_worthy? does_this_string_contain_a_special_token? } # === Colours.is_this_replacement_worthy?
351
+
352
+ # =========================================================================== #
353
+ # === Colours.replace_html_like_tokens
354
+ #
355
+ # The second argument to this method allows the user to use another Hash
356
+ # for the replacement table.
357
+ #
358
+ # Usage examples:
359
+ #
360
+ # 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>.")
361
+ # 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?"
362
+ # y = Colours.replace_number_words_with_the_corresponding_html_colour(x)
363
+ #
364
+ # See also:
365
+ #
366
+ # https://rubular.com/r/XUPQJFKlDs2OYP
367
+ #
368
+ # =========================================================================== #
369
+ def self.replace_html_like_tokens(
370
+ i,
371
+ optional_use_this_hash = nil,
372
+ &block
373
+ )
374
+ _ = ::Colours::ReplaceTokensWithColourCode.new(i, :do_not_run_yet, &block)
375
+ if optional_use_this_hash
376
+ _.set_use_this_hash(optional_use_this_hash)
377
+ end
378
+ _.run
379
+ _.result?
380
+ end; self.instance_eval { alias replace_number_words_with_the_corresponding_html_colour replace_html_like_tokens } # === Colours.replace_number_words_with_the_corresponding_html_colour
381
+
382
+ end
383
+
384
+ if __FILE__ == $PROGRAM_NAME
385
+ alias e puts
386
+ _ = Colours::ReplaceTokensWithColourCode.new(ARGV, :do_not_run_yet)
387
+ e _.parse(
388
+ "<royalblue>This</royalblue> <tomato>is</tomato> <cyan>test</cyan>."
389
+ )
390
+ e _.parse(
391
+ "<royalblue>Test1</royalblue> <one>test2</one> <two>test3</two> <three>test4</three>"
392
+ )
393
+ e _.parse(
394
+ "<yodel>foobar</yodel>"
395
+ )
396
+ e _.parse(
397
+ "<one>abc</one> hey there"
398
+ )
399
+ _.parse(
400
+ "<one>abc</one> hey there
401
+ <one>how do you do?</one>
402
+ <two>lots of things we should do</two>.
403
+ <royalblue>foobar</royalblue>"
404
+ )
405
+ e _.result?
406
+ _.parse('The system (<royalblue>of awesomeness</royalblue>).
407
+ is coming closer.')
408
+ e _.result?
409
+ end # replacetokenswithcolourcode
@@ -2,4 +2,7 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
5
+ require 'colours/autogenerated/256_colours_instance_methods.rb'
6
+ require 'colours/autogenerated/256_colours_methods.rb'
7
+ require 'colours/autogenerated/html_colours_instance_methods.rb'
8
+ require 'colours/autogenerated/html_colours_methods.rb'
@@ -2,6 +2,6 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- # require 'colours/requires/require_the_colour_table.rb'
5
+ # require 'colours/requires/require_essentials.rb'
6
6
  # =========================================================================== #
7
- require 'colours/colour_table/colour_table.rb'
7
+ require 'colours/essentials/essentials.rb'
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/requires/require_save_file.rb'
6
+ # =========================================================================== #
7
+ begin
8
+ require 'save_file'
9
+ rescue LoadError
10
+ puts 'save_file gem is not available/installed.'
11
+ end
@@ -11,6 +11,4 @@
11
11
  # =========================================================================== #
12
12
  # Add support for the 256-colours:
13
13
  # =========================================================================== #
14
- require 'colours/256_colours/support_for_256_colours.rb'
15
-
16
- require 'colours/autogenerated/support_for_256_colours.rb'
14
+ require 'colours/module_256_colours/module_256_colours.rb'
@@ -10,25 +10,4 @@
10
10
  # =========================================================================== #
11
11
  # require 'colours/requires/require_the_colour_methods.rb'
12
12
  # =========================================================================== #
13
- module Colours
14
-
15
- require 'colours/project/project.rb'
16
-
17
- # ========================================================================= #
18
- # === Colours.require_the_colour_methods
19
- #
20
- # This method will batch-require the .rb files that are found in the
21
- # colour_methods/ subdirectory of the colours gem.
22
- # ========================================================================= #
23
- def self.require_the_colour_methods
24
- target = "#{::Colours::PROJECT_BASE_DIRECTORY}colour_methods/"
25
-
26
- Dir["#{target}*.rb"].each {|this_file|
27
- require target+File.basename(this_file)
28
- }
29
-
30
- end; self.instance_eval { alias default_string_methods require_the_colour_methods } # === Colours.default_string_methods
31
-
32
- ::Colours.require_the_colour_methods # Also trigger the above method at once.
33
-
34
- end
13
+ require 'colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb'