colours 0.5.55

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +890 -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/bin/remove_ansii_escape_sequences +7 -0
  10. data/colours.gemspec +76 -0
  11. data/doc/COLOUR_CODES_CHART.md +28 -0
  12. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
  13. data/doc/README.gen +862 -0
  14. data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
  15. data/lib/colours/autoalias_e.rb +10 -0
  16. data/lib/colours/autogenerated/README.md +2 -0
  17. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  18. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  19. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
  20. data/lib/colours/autoinclude.rb +14 -0
  21. data/lib/colours/base/base.rb +23 -0
  22. data/lib/colours/basic_colours/README.md +4 -0
  23. data/lib/colours/basic_colours/basic_colours.rb +279 -0
  24. data/lib/colours/colour_methods/README.md +11 -0
  25. data/lib/colours/colour_methods/default_colour.rb +66 -0
  26. data/lib/colours/colour_methods/sargument.rb +70 -0
  27. data/lib/colours/colour_methods/scomments.rb +105 -0
  28. data/lib/colours/colour_methods/sdir.rb +66 -0
  29. data/lib/colours/colour_methods/sfancy.rb +84 -0
  30. data/lib/colours/colour_methods/sfile.rb +71 -0
  31. data/lib/colours/colour_methods/simportant.rb +92 -0
  32. data/lib/colours/colour_methods/snormal.rb +66 -0
  33. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  34. data/lib/colours/colour_methods/swarn.rb +76 -0
  35. data/lib/colours/colour_table/README.md +3 -0
  36. data/lib/colours/colour_table/colour_table.rb +275 -0
  37. data/lib/colours/colours_e_autoinclude.rb +9 -0
  38. data/lib/colours/commandline/README.md +2 -0
  39. data/lib/colours/commandline/commandline.rb +44 -0
  40. data/lib/colours/commandline/menu.rb +111 -0
  41. data/lib/colours/constants/colour_constants.rb +299 -0
  42. data/lib/colours/constants/file_constants.rb +72 -0
  43. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  44. data/lib/colours/constants/misc.rb +59 -0
  45. data/lib/colours/constants/newline.rb +14 -0
  46. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  47. data/lib/colours/e/README.md +13 -0
  48. data/lib/colours/e/autoinclude.rb +11 -0
  49. data/lib/colours/e/e.rb +35 -0
  50. data/lib/colours/e.rb +5 -0
  51. data/lib/colours/eparse/eparse.rb +77 -0
  52. data/lib/colours/everything/autoinclude.rb +11 -0
  53. data/lib/colours/html_colours/README.md +1 -0
  54. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  55. data/lib/colours/html_colours/hash_html_colours.rb +63 -0
  56. data/lib/colours/html_colours/html_colourize.rb +48 -0
  57. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  58. data/lib/colours/html_colours/misc.rb +186 -0
  59. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  60. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  61. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  62. data/lib/colours/module.rb +11 -0
  63. data/lib/colours/project/project_base_directory.rb +22 -0
  64. data/lib/colours/rainbow_colours/README.md +2 -0
  65. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  66. data/lib/colours/rainbow_colours/constants.rb +30 -0
  67. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  68. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  69. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  70. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  71. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  72. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  73. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  74. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  75. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  76. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  77. data/lib/colours/requires/require_commandline.rb +7 -0
  78. data/lib/colours/requires/require_eparse.rb +11 -0
  79. data/lib/colours/requires/require_rgb.rb +5 -0
  80. data/lib/colours/requires/require_sdir.rb +5 -0
  81. data/lib/colours/requires/require_sfile.rb +5 -0
  82. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  83. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  84. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  85. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  86. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  87. data/lib/colours/requires/require_the_constants.rb +11 -0
  88. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  89. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  90. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  91. data/lib/colours/revert/revert.rb +106 -0
  92. data/lib/colours/rgb/rgb.rb +547 -0
  93. data/lib/colours/testing/README.md +2 -0
  94. data/lib/colours/testing/testing.rb +157 -0
  95. data/lib/colours/toplevel_methods/bold.rb +35 -0
  96. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  97. data/lib/colours/toplevel_methods/cat.rb +39 -0
  98. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  99. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  100. data/lib/colours/toplevel_methods/col.rb +56 -0
  101. data/lib/colours/toplevel_methods/e.rb +63 -0
  102. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  103. data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
  104. data/lib/colours/toplevel_methods/html_colourize.rb +64 -0
  105. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  106. data/lib/colours/toplevel_methods/italic.rb +104 -0
  107. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  108. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +325 -0
  109. data/lib/colours/toplevel_methods/misc.rb +129 -0
  110. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  111. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
  112. data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
  113. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  114. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +112 -0
  115. data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
  116. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  117. data/lib/colours/toplevel_methods/underline.rb +114 -0
  118. data/lib/colours/toplevel_methods/use_colours.rb +290 -0
  119. data/lib/colours/utility_scripts/README.md +2 -0
  120. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  121. data/lib/colours/version/version.rb +25 -0
  122. data/lib/colours/yaml/256_colours.yml +277 -0
  123. data/lib/colours/yaml/basic_colours.yml +23 -0
  124. data/lib/colours/yaml/html_colours.yml +835 -0
  125. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  126. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  127. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
  128. data/lib/colours.rb +5 -0
  129. data/test/test.html +18 -0
  130. data/test/testing_256_colours_support.rb +29 -0
  131. data/test/testing_col.rb +10 -0
  132. data/test/testing_colours.rb +95 -0
  133. data/test/testing_colours_e.rb +13 -0
  134. data/test/testing_eparse.rb +13 -0
  135. data/test/testing_kde_colour_palette.rb +30 -0
  136. data/test/testing_konsole_submodule.rb +226 -0
  137. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  138. data/test/testing_rgb_to_hex.rb +32 -0
  139. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  140. data/test/testing_the_colour_methods.rb +36 -0
  141. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  142. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  143. data/test/testing_whether_colours_will_be_used.rb +7 -0
  144. metadata +226 -0
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/italic.rb'
6
+ # =========================================================================== #
7
+ require 'colours/revert/revert.rb'
8
+ require 'colours/toplevel_methods/e.rb'
9
+ require 'colours/rgb/rgb.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === ITALIC_CODE
15
+ #
16
+ # If you wish to test italic output quickly on the terminal, then you
17
+ # can use something like this:
18
+ #
19
+ # echo -e "\e[3mone two three\e[23m"
20
+ #
21
+ # ========================================================================= #
22
+ ITALIC_CODE = '3'
23
+
24
+ # ========================================================================= #
25
+ # === Colours.return_italic
26
+ #
27
+ # To test this, try:
28
+ # Colours.italic('Hello world!')
29
+ # ========================================================================= #
30
+ def self.return_italic(
31
+ show_this_text = 'This must be italic.',
32
+ make_newline = false
33
+ )
34
+ result = "\x1b".dup
35
+ result << '['
36
+ result << ITALIC_CODE
37
+ if block_given?
38
+ # ===================================================================== #
39
+ # Right now we assume that this must be a colour.
40
+ # ===================================================================== #
41
+ result << ";38;2;"
42
+ result << html_colour_to_stringified_rgb_values(yield)
43
+ end
44
+ result << 'm'
45
+ if make_newline
46
+ show_this_text = "#{show_this_text}\n"
47
+ end
48
+ result << show_this_text
49
+ result << REVERT
50
+ result
51
+ end; self.instance_eval { alias string_italic return_italic } # === Colours.string_italic
52
+
53
+ # ========================================================================= #
54
+ # === Colours.italic
55
+ #
56
+ # This method will "puts" the result of applying italic to a string,
57
+ # on the console/terminal. If you wish to do the output on your own
58
+ # then you have to use the method Colours.return_italic or its
59
+ # alias called Colours.string_italic.
60
+ #
61
+ # To test this, try:
62
+ # Colours.italic('Hello world!')
63
+ # ========================================================================= #
64
+ def self.italic(
65
+ i = '',
66
+ make_newline = false,
67
+ &block
68
+ )
69
+ e return_italic(i, make_newline, &block)
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === italic
74
+ # ========================================================================= #
75
+ def italic(
76
+ i = '',
77
+ make_newline = false
78
+ )
79
+ ::Colours.italic(i, make_newline)
80
+ end
81
+
82
+ end
83
+
84
+ if __FILE__ == $PROGRAM_NAME
85
+ alias e puts
86
+ txt = 'Hello world!'
87
+ if ARGV.empty?
88
+ require 'colours/requires/require_all_colour_methods.rb'
89
+ COLOURS = Colours::AllColourMethods
90
+ system 'clear'
91
+ Colours.italic(txt)
92
+ e COLOURS.palegreen('italic in palegreen:')
93
+ print ' '; puts Colours.string_italic(txt) { :palegreen }
94
+ e COLOURS.slateblue('italic in slateblue:')
95
+ print ' '; puts Colours.string_italic(txt) { :slateblue }
96
+ e COLOURS.orange('italic in orange:')
97
+ print ' '; puts Colours.string_italic(txt) { :orange }
98
+ e COLOURS.crimson('italic in crimson:')
99
+ print ' '; puts Colours.string_italic(txt) { :crimson }
100
+ else
101
+ print ' '; puts Colours.string_italic(ARGV.join(' ').strip)
102
+ print ' '; puts Colours.string_italic(ARGV.join(' ').strip) { :crimson }
103
+ end
104
+ end # italic
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/make_colour.rb'
6
+ # =========================================================================== #
7
+ require 'colours/constants/colour_constants.rb'
8
+ require 'colours/constants/misc.rb'
9
+ require 'colours/toplevel_methods/e.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours.make_colour
15
+ #
16
+ # This is used primarily for testing.
17
+ # ========================================================================= #
18
+ def self.make_colour(
19
+ what_colour_to_use
20
+ )
21
+ i = what_colour_to_use # Copy.
22
+ constant = i.to_s.upcase
23
+ name_of_colour = const_get(constant)
24
+ string = '%-34s' % ("#{name_of_colour} Test with #{constant}.")
25
+ string << IS_A_TEST+'('+name_of_colour.inspect.delete('"')+')'
26
+ e(string)
27
+ end
28
+
29
+ end
@@ -0,0 +1,325 @@
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
+ # ===================================================================== #
79
+ # The following hash can be used as a default "replacement" Hash.
80
+ # ===================================================================== #
81
+ use_this_as_replacement_hash = {
82
+ 'one' => :teal,
83
+ 'two' => :lightseagreen,
84
+ 'three' => :mediumseagreen, # ← Used to be 'peru' up until 23.11.2019.
85
+ 'four' => :olivedrab,
86
+ 'five' => :lightgreen
87
+ }
88
+ end
89
+ # ======================================================================= #
90
+ # === Enable support for <one>, <two>, <three>, <four> and <five> next.
91
+ # ======================================================================= #
92
+ if i.include?('<one>') or
93
+ i.include?('<two>') or
94
+ i.include?('<three>') or
95
+ i.include?('<four>') or
96
+ i.include?('<five>')
97
+ scanned_results = i.scan(
98
+ REGEX_FOR_HTML_COLOURS
99
+ ).flatten.uniq
100
+ scanned_results.each {|this_numbered_word|
101
+ if use_this_as_replacement_hash.has_key? this_numbered_word
102
+ i = i.dup if i.frozen?
103
+ replacement_colour = use_this_as_replacement_hash[this_numbered_word]
104
+ use_this_regex =
105
+ # =============================================================== #
106
+ # See:
107
+ #
108
+ # https://rubular.com/r/sDNQd81MtciMJL
109
+ #
110
+ # =============================================================== #
111
+ /<#{this_numbered_word}>([-#~≥!\e=><;,→⁻⁺@^„“γαµ_₀₁₂₃₄₅₆₇₈₉²³⁴⁵⁶⁷⁸⁹äöüÄÖÜβß%&:≡°$A-Za-z0-9\n \?\\'\|\(\)\{\}\[\]\"\*\.\+]+)<\/#{this_numbered_word}>/
112
+ # ================================================================= #
113
+ # We must use .gsub!() because the colour-string may occur more
114
+ # than once.
115
+ # ================================================================= #
116
+ i.gsub!(
117
+ use_this_regex,
118
+ ::Colours::AllColourMethods.send(replacement_colour.to_sym, "\\1") { :omit_end }+
119
+ ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
120
+ )
121
+ # i << ::Colours.revert
122
+ end
123
+ }
124
+ end
125
+ i
126
+ end
127
+
128
+ # ========================================================================= #
129
+ # === Colours.does_this_string_include_a_html_colour?
130
+ # ========================================================================= #
131
+ def self.does_this_string_include_a_html_colour?(i)
132
+ result = (i =~ REGEX_FOR_HTML_COLOURS)
133
+ result = false if result.nil?
134
+ result
135
+ end
136
+
137
+ # ========================================================================= #
138
+ # === Colours.does_this_string_include_a_html_number?
139
+ #
140
+ # This method will return true if the string includes tags such as
141
+ # <one> or <two> and so forth.
142
+ # ========================================================================= #
143
+ def self.does_this_string_include_a_html_number?(i)
144
+ i.include?('<one>') or
145
+ i.include?('<two>') or
146
+ i.include?('<three>') or
147
+ i.include?('<four>') or
148
+ i.include?('<five>')
149
+ end
150
+
151
+ # ========================================================================= #
152
+ # === Colours.html_colour_to_hex_value
153
+ # ========================================================================= #
154
+ def self.html_colour_to_hex_value(
155
+ this_html_colour,
156
+ return_with_hash_key = true
157
+ )
158
+ if this_html_colour.is_a? Array
159
+ this_html_colour = this_html_colour.first
160
+ end
161
+ _ = file_html_colours_to_rgb?
162
+ if File.exist? _
163
+ dataset = YAML.load_file(_)
164
+ if dataset.has_key? this_html_colour
165
+ _ = dataset[this_html_colour].last
166
+ if return_with_hash_key
167
+ _ = _.dup if _.frozen?
168
+ _ = _.to_s unless _.is_a? String
169
+ _[0,0] = '#' if _.respond_to? :[]=
170
+ end
171
+ return _
172
+ end
173
+ end
174
+ return this_html_colour
175
+ end
176
+
177
+ # ========================================================================= #
178
+ # === Colours.replace_html_colours_in_this_string
179
+ #
180
+ # This method will replace all HTML colours in a given string, such as
181
+ # "<slateblue>test</slateblue>", with the corresponding RGB colour
182
+ # variant for the commandline.
183
+ #
184
+ # Typically this refers to a terminal such as the KDE Konsole, and a
185
+ # shell such as bash (although other shells are fine too, and many
186
+ # other terminals, such as the gnome-terminal, most likely will work
187
+ # fine as well - but it is optimized for the KDE Konsole).
188
+ #
189
+ # This method should only be called after a prior check was done,
190
+ # to determine whether the given input String at hand does indeed
191
+ # include a valid HTML colour; otherwise it would be a bit pointless
192
+ # to invoke the method, if it is already known that the String at
193
+ # hand does not contain any HTML colour at all. In order to determine
194
+ # whether a String may include a valid HTML colour, the method called
195
+ # line_contains_a_valid_html_colour?() can be used.
196
+ #
197
+ # Usage example:
198
+ #
199
+ # Colours.replace_html_colours_in_this_string
200
+ #
201
+ # ========================================================================= #
202
+ def self.replace_html_colours_in_this_string(
203
+ i,
204
+ use_this_colour_for_the_default_colour = :default, # ← This specifies the default colour.
205
+ shall_we_revert_at_the_end_of_the_line = false
206
+ )
207
+ i = i.dup # We want to work on a copy.
208
+ result = ''.dup # Our result-string.
209
+ case use_this_colour_for_the_default_colour
210
+ when :default
211
+ use_this_colour_for_the_default_colour = USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
212
+ end
213
+ case shall_we_revert_at_the_end_of_the_line
214
+ when :revert
215
+ shall_we_revert_at_the_end_of_the_line = true
216
+ end
217
+ result << ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
218
+ result = result.dup
219
+ # ======================================================================= #
220
+ # This method will make use of two different regexes.
221
+ # ======================================================================= #
222
+ scanned_results = i.scan(
223
+ REGEX_FOR_HTML_COLOURS
224
+ ).flatten
225
+ add_on_string = i.dup
226
+ scanned_results.uniq.each {|this_colour|
227
+ if is_this_a_valid_html_colour?(this_colour)
228
+ # =================================================================== #
229
+ # === Defining the Regex in use
230
+ #
231
+ # Regex see:
232
+ #
233
+ # https://rubular.com/r/W1zdB0NNoTyTd7
234
+ #
235
+ # =================================================================== #
236
+ use_this_regex =
237
+ /<#{this_colour}>([\[\]\\{}\(\)\/!\-#*~:;≡=+a-zA-Z0-9₁₂₃₄₅₆₇₈₉ÅäöüÄÖÜαβß&%°"',_\|\n\. ]+)<\/#{this_colour}>/
238
+ # =================================================================== #
239
+ # We must use .gsub!() because the colour-string may occur more
240
+ # than once. Unfortunately for longer Strings this becomes a bit
241
+ # fragile.
242
+ # =================================================================== #
243
+ part1 = ::Colours::AllColourMethods.send(this_colour.to_sym, "\\1") { :omit_end }
244
+ part2 = ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
245
+ add_on_string.gsub!(use_this_regex, part1+part2).dup
246
+ end
247
+ }
248
+ result << add_on_string
249
+ if shall_we_revert_at_the_end_of_the_line
250
+ result << ::Colours.revert
251
+ end
252
+ return result
253
+ end; self.instance_eval { alias replace_html_colours replace_html_colours_in_this_string } # === Colours.replace_html_colours
254
+ 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
255
+ 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
256
+
257
+ # ========================================================================= #
258
+ # === Colours.eliminate_html
259
+ #
260
+ # This method simply combines two other methods, without any further
261
+ # checks inside of this method. The method will thus remove entries
262
+ # such as <one> or <steelblue>.
263
+ # ========================================================================= #
264
+ def self.eliminate_html(
265
+ i,
266
+ use_this_colour_for_the_default_colour = :default,
267
+ use_this_as_replacement_hash = :default_hash
268
+ )
269
+ i = i.dup
270
+ i = Colours.replace_number_words_with_the_corresponding_html_colour(
271
+ i,
272
+ use_this_colour_for_the_default_colour,
273
+ use_this_as_replacement_hash
274
+ )
275
+ i = i.dup
276
+ i = Colours.replace_html_colours_in_this_string(
277
+ i,
278
+ use_this_colour_for_the_default_colour
279
+ )
280
+ return i.dup
281
+ end; self.instance_eval { alias away_with_html_colours_and_special_numbers eliminate_html } # === Colours.away_with_html_colours_and_special_numbers
282
+ self.instance_eval { alias remove_html_tags_and_special_words eliminate_html } # === Colours.remove_html_tags_and_special_words
283
+ self.instance_eval { alias remove_crap eliminate_html } # === Colours.remove_crap
284
+
285
+ end
286
+
287
+ if __FILE__ == $PROGRAM_NAME
288
+ alias e puts
289
+ input = ARGV
290
+ if input.empty?
291
+ input << 'steelblue'
292
+ end
293
+ e 'Testing: Colours.html_colour_to_hex_value(ARGV) next'
294
+ e Colours.html_colour_to_hex_value(input)
295
+ e "Testing: Colours.does_this_string_include_a_html_number?('abc <one>def</one>') next"
296
+ puts Colours.does_this_string_include_a_html_number?('abc <one>def</one>')
297
+ # ========================================================================= #
298
+ # Test the behaviour of the method next:
299
+ # ========================================================================= #
300
+ this_line = "- <lightseagreen>hey</lightseagreen> yo <green>there</green>"
301
+ puts Colours.replace_html_colours(
302
+ this_line
303
+ )
304
+ puts Colours.does_this_string_include_a_html_colour?('<steelblue>')
305
+ e
306
+ e Colours.replace_number_words_with_the_corresponding_html_colour(
307
+ "- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
308
+ )
309
+ 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?"
310
+ e Colours.replace_number_words_with_the_corresponding_html_colour(x)
311
+ e Colours.replace_html_colours_in_this_string("<one>Methämoglobin</one> ist <steelblue>ungeeignet</steelblue>.")
312
+ e
313
+ string = "- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
314
+ e string
315
+ e Colours.replace_html_colours_in_this_string(
316
+ string
317
+ )
318
+ e
319
+ result = Colours.replace_all_html_colours_in_this_line(' |<steelblue>E</steelblue>]', :default, :revert)
320
+ e result
321
+ e
322
+ e 'And it looks like this via pp:'
323
+ e
324
+ pp result
325
+ end # html_colour_to_hex_value slateblue
@@ -0,0 +1,129 @@
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
+ # ========================================================================= #
96
+ # === Colours.convert_hex_to_rgb
97
+ #
98
+ # This method will convert e. g. #baf185 to [186, 241, 133]. Thus it
99
+ # will return an Array, denoting the R, G, B values.
100
+ #
101
+ # How to do this conversion on your own?
102
+ #
103
+ # (1) Get the 2 left digits of the hex color code and convert
104
+ # to decimal value to get the red color level.
105
+ # (2) Get the 2 middle digits of the hex color code and
106
+ # convert to decimal value to get the green color level.
107
+ # (3) Get the 2 right digits of the hex color code and
108
+ # convert to decimal value to get the blue color level.
109
+ #
110
+ # Usage example:
111
+ #
112
+ # Colours.convert_hex_to_rgb('#baf185') # => [186, 241, 133]
113
+ #
114
+ # ========================================================================= #
115
+ def self.convert_hex_to_rgb(hex)
116
+ if hex.is_a? Array
117
+ hex = hex.first
118
+ end
119
+ hex = hex.to_s.dup
120
+ hex.delete!('#') if hex.include? '#'
121
+ array = [] # We will return this Array.
122
+ r = hex[0,2].to_i(16)
123
+ g = hex[2,2].to_i(16)
124
+ b = hex[4,2].to_i(16)
125
+ array << r << g << b
126
+ return array
127
+ end; self.instance_eval { alias hex_to_rgb convert_hex_to_rgb } # === Colours.hex_to_rgb
128
+
129
+ 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