colours 0.5.48

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 (143) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +867 -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 +850 -0
  13. data/lib/colours.rb +5 -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.rb +5 -0
  48. data/lib/colours/e/README.md +13 -0
  49. data/lib/colours/e/autoinclude.rb +11 -0
  50. data/lib/colours/e/e.rb +35 -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 +95 -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 +107 -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/test/test.html +18 -0
  129. data/test/testing_256_colours_support.rb +29 -0
  130. data/test/testing_col.rb +10 -0
  131. data/test/testing_colours.rb +95 -0
  132. data/test/testing_colours_e.rb +13 -0
  133. data/test/testing_eparse.rb +13 -0
  134. data/test/testing_kde_colour_palette.rb +30 -0
  135. data/test/testing_konsole_submodule.rb +226 -0
  136. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  137. data/test/testing_rgb_to_hex.rb +32 -0
  138. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  139. data/test/testing_the_colour_methods.rb +36 -0
  140. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  141. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  142. data/test/testing_whether_colours_will_be_used.rb +7 -0
  143. metadata +224 -0
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/fancy_parse.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/toplevel_methods/bold.rb'
10
+ require 'colours/toplevel_methods/italic.rb'
11
+ require 'colours/toplevel_methods/methods_related_to_html_colours.rb'
12
+ require 'colours/toplevel_methods/underline.rb'
13
+
14
+ # ========================================================================= #
15
+ # === Colours.fancy_parse
16
+ #
17
+ # This method can be used to parse a line containing special tags,
18
+ # such as <i> or <teal>, and replace them with the corresponding
19
+ # ASCII code for the commandline. The second example, e. g. <teal>,
20
+ # is known as a HTML colour tag (htmlcolour).
21
+ #
22
+ # The idea for this method is to simply use it to quickly colourize
23
+ # some arbitrary text.
24
+ #
25
+ # The method will only return the resulting, sanitizing String; if
26
+ # you wish to display this on the terminal/commandline then you
27
+ # will have to use puts or print on your own.
28
+ #
29
+ # Usage example:
30
+ #
31
+ # Colours.fancy_parse '<i>hey</i> <teal>there</teal>'
32
+ #
33
+ # ========================================================================= #
34
+ def self.fancy_parse(i = '')
35
+ if i.is_a? Array
36
+ i = i.join
37
+ end
38
+ i = i.dup # Work on a copy.
39
+ # ======================================================================= #
40
+ # === Handle italic tags, aka <i>
41
+ # ======================================================================= #
42
+ if i.include?('<i>') and
43
+ i.include?('</i>')
44
+ use_this_regex = /<i>(.+)<\/i>/
45
+ i.gsub!(
46
+ use_this_regex,
47
+ return_italic('\1')
48
+ )
49
+ end
50
+ # ======================================================================= #
51
+ # === Handle bold tags, aka <b>
52
+ # ======================================================================= #
53
+ if i.include?('<b>') and
54
+ i.include?('</b>')
55
+ use_this_regex = /<b>(.+)<\/b>/
56
+ i.gsub!(
57
+ use_this_regex,
58
+ return_bold('\1')
59
+ )
60
+ end
61
+ # ======================================================================= #
62
+ # Finally, handle all HTML colours in the given line.
63
+ # ======================================================================= #
64
+ i = replace_all_html_colours_in_this_line(i)
65
+ i
66
+ end
67
+
68
+ end
69
+
70
+ if __FILE__ == $PROGRAM_NAME
71
+ result = Colours.fancy_parse(ARGV)
72
+ puts result
73
+ # pp result # <- This line is just for simple debugging.
74
+ end # fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
75
+ # fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
76
+ # fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
77
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal>"
78
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal> <b>how do you do</b>"
79
+ # fancy_parse "<tomato><b>Hello world.</b></tomato>"
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/html_colourize.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/rgb/rgb.rb'
10
+ require 'colours/revert/revert.rb'
11
+
12
+ # ========================================================================= #
13
+ # === Colours.html_colourize
14
+ #
15
+ # This method will simply return the colour-code + text.
16
+ #
17
+ # The third argument, called `append_revert`, can be used to determine
18
+ # whether we will append the revert code to the generated output String
19
+ # or whether we will not. By default we will, but there are examples
20
+ # where we may wish to assemble our own colour string, and in these
21
+ # cases we do not yet know which text is to be shown - hence, this
22
+ # must become an optional argument.
23
+ #
24
+ # A block can be passed to this method. If the block has, as content,
25
+ # the Symbol :omit_end then the end-part of the ANSI code will not
26
+ # be used.
27
+ #
28
+ # Usage examples:
29
+ #
30
+ # x = Colours.colourize('slateblue', 'Hello world!'); pp x
31
+ # y = Colours.colourize('slateblue', 'Hello world!') { :omit_end }; pp y
32
+ #
33
+ # ========================================================================= #
34
+ def self.html_colourize(
35
+ colour_to_use = return_random_html_colour,
36
+ this_text = nil,
37
+ append_revert = true,
38
+ &block
39
+ )
40
+ if block_given?
41
+ yielded = yield
42
+ case yielded
43
+ when :omit_end
44
+ append_revert = false
45
+ end
46
+ end
47
+ if this_text.nil?
48
+ this_text = colour_to_use.to_s.dup
49
+ end
50
+ if append_revert
51
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}#{revert}"
52
+ else
53
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}"
54
+ end
55
+ end; self.instance_eval { alias colourize html_colourize } # === Colours.colourize
56
+ self.instance_eval { alias kde_colour html_colourize } # === Colours.kde_colour
57
+ self.instance_eval { alias konsole_colours html_colourize } # === Colours.konsole_colours
58
+
59
+ end
60
+
61
+ if __FILE__ == $PROGRAM_NAME
62
+ puts Colours.html_colourize('slateblue', 'Hello world 1!')
63
+ puts Colours.html_colourize(:crimson, 'Hello world 2!')
64
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/is_on_roebe.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours.is_on_roebe?
11
+ # ========================================================================= #
12
+ def self.is_on_roebe?
13
+ ENV['IS_ROEBE'].to_s == '1'
14
+ end
15
+
16
+ end
@@ -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/lNUo2JvuN2GrYg
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/5oYax0SCz7R7I6
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