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
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/html_colours/random_html_colour.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ module HtmlColours # === Colours::HtmlColours
10
+
11
+ require 'colours/html_colours/hash_html_colours.rb'
12
+
13
+ # ========================================================================= #
14
+ # === Colours::HtmlColours.random_colour?
15
+ #
16
+ # Obtain a random sample, aka a random colour, from all the registered
17
+ # html colours.
18
+ # ========================================================================= #
19
+ def self.random_colour?
20
+ available_html_colours?.sample
21
+ end; self.instance_eval { alias random_colour random_colour? } # === Colours::HtmlColours.random_colour
22
+ self.instance_eval { alias random random_colour? } # === Colours::HtmlColours.random
23
+ self.instance_eval { alias sample random_colour? } # === Colours::HtmlColours.sample
24
+ self.instance_eval { alias random_html_colour random_colour? } # === Colours::HtmlColours.random_html_colour
25
+ self.instance_eval { alias return_random_html_colour random_colour? } # === Colours::HtmlColours.return_random_html_colour
26
+ self.instance_eval { alias return_random_colour random_colour? } # === Colours::HtmlColours.return_random_colour
27
+
28
+ end
29
+
30
+ # =========================================================================== #
31
+ # === Colours.random_html_colour
32
+ #
33
+ # This method will simply return a (one) random HTML colour, in long
34
+ # format, e. g. "teal" or "slateblue".
35
+ #
36
+ # If you wish to have it colourized properly, you need to use another
37
+ # method.
38
+ #
39
+ # Usage examples:
40
+ #
41
+ # Colours.random_colour? # => "teal"
42
+ # Colours.random_colour? # => "blueviolet"
43
+ #
44
+ # =========================================================================== #
45
+ def self.random_html_colour
46
+ ::Colours::HtmlColours.random_colour?
47
+ end; self.instance_eval { alias random_html_colour? random_html_colour } # === Colours.random_html_colour?
48
+ self.instance_eval { alias random_colour? random_html_colour } # === Colours.random_colour?
49
+ self.instance_eval { alias return_random_html_colour random_html_colour } # === Colours.return_random_html_colour
50
+ self.instance_eval { alias return_html_colour? random_html_colour } # === Colours.return_html_colour?
51
+ self.instance_eval { alias random_colour random_html_colour } # === Colours.random_colour
52
+ self.instance_eval { alias random random_html_colour } # === Colours.random
53
+ self.instance_eval { alias sample random_html_colour } # === Colours.sample
54
+ self.instance_eval { alias return_random_html_colour random_html_colour } # === Colours.return_random_html_colour
55
+ self.instance_eval { alias return_random_colour random_html_colour } # === Colours.return_random_colour
56
+ self.instance_eval { alias random_colour? random_html_colour } # === Colours.return_random_colour
57
+
58
+ end
59
+
60
+ if __FILE__ == $PROGRAM_NAME
61
+ alias e puts
62
+ e 'Random HTML colour: '+Colours.random_html_colour.to_s
63
+ e
64
+ e Colours.random_colour? # => "teal"
65
+ e Colours.random_colour? # => "steelblue"
66
+ e
67
+ end
@@ -2,6 +2,8 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- # require 'colours/requires/require_the_basic_colours.rb'
5
+ # require 'colours/html_colours'
6
6
  # =========================================================================== #
7
- require 'colours/basic_colours/basic_colours.rb'
7
+ require 'colours'
8
+
9
+ Colours.push_the_html_colours_methods_onto_the_toplevel_namespace
@@ -6,8 +6,8 @@
6
6
  # =========================================================================== #
7
7
  module Colours
8
8
 
9
- require 'colours/constants/hash_simple_colours.rb'
10
- require 'colours/constants/misc.rb'
9
+ require 'colours/constants/constants.rb'
10
+ require 'colours/toplevel_methods/rev.rb'
11
11
 
12
12
  # ========================================================================= #
13
13
  # === Colours.map_symbol_to_corresponding_colour (menu tag)
@@ -37,6 +37,7 @@ module Colours
37
37
  # Usage example for this method:
38
38
  #
39
39
  # Colours.beautiful(:bold_blue)
40
+ # Colours.beautiful(:brown)
40
41
  #
41
42
  # ========================================================================= #
42
43
  def self.map_symbol_to_corresponding_colour(i)
@@ -51,6 +52,13 @@ module Colours
51
52
  end
52
53
  case i # case tag
53
54
  # ======================================================================= #
55
+ # === :bright_cyan
56
+ # ======================================================================= #
57
+ when :bright_cyan,
58
+ :cyanb,
59
+ :cyan
60
+ return BOLD_CYAN
61
+ # ======================================================================= #
54
62
  # === :default
55
63
  # ======================================================================= #
56
64
  when :default,
@@ -101,13 +109,6 @@ module Colours
101
109
  :bright_magenta
102
110
  return BRIGHT_MAGENTA
103
111
  # ======================================================================= #
104
- # === :bright_cyan
105
- # ======================================================================= #
106
- when :bright_cyan,
107
- :cyanb,
108
- :cyan
109
- return BOLD_CYAN
110
- # ======================================================================= #
111
112
  # === :brown
112
113
  # ======================================================================= #
113
114
  when :brown
@@ -220,5 +221,6 @@ end
220
221
 
221
222
  if __FILE__ == $PROGRAM_NAME
222
223
  alias e puts
223
- e Colours.beautiful(:bold_blue)+'OK!'+Colours.rev
224
+ e Colours.beautiful(:bold_blue)+'OK! Bold blue colour.'+Colours.rev
225
+ e Colours.beautiful(:bold_brown)+'OK! Bold brown colour.'+Colours.rev
224
226
  end
@@ -0,0 +1,465 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Colours::Module256Colours
6
+ # =========================================================================== #
7
+ # require 'colours/module_256_colours/module_256_colours.rb'
8
+ # include ::Colours::Module256Colours
9
+ # =========================================================================== #
10
+ module Colours
11
+
12
+ module Module256Colours # === Colours::Module256Colours
13
+
14
+ require 'yaml'
15
+ require 'colours/constants/constants.rb'
16
+ # require 'colours/autogenerated/256_colours_methods.rb'
17
+ # require 'colours/autogenerated/256_colours_instance_methods.rb'
18
+
19
+ # ========================================================================= #
20
+ # === Colours::Module256Colours::BLOCK_START
21
+ # ========================================================================= #
22
+ BLOCK_START = "\x1b[48;5;"
23
+
24
+ # ========================================================================= #
25
+ # === Colours::Module256Colours::BLOCK_END
26
+ # ========================================================================= #
27
+ BLOCK_END = "\x1b[0m"
28
+
29
+ # ========================================================================= #
30
+ # === Colours::Module256Colours.autogenerate_256_colours_methods (autogenerate tag)
31
+ #
32
+ # This method will autogenerate all methods that can be used via
33
+ # Colours::Module256Colours.
34
+ #
35
+ # Commandline invocation example:
36
+ #
37
+ # colours --autogenerate_256_colours_methods
38
+ #
39
+ # ========================================================================= #
40
+ def self.autogenerate_256_colours_methods(
41
+ into = HOME_DIRECTORY_OF_USER_X+
42
+ 'programming/ruby/src/'\
43
+ 'colours/lib/colours/autogenerated/'\
44
+ '256_colours_methods.rb'
45
+ )
46
+ require 'save_file'
47
+ dataset_from_the_yaml_file = YAML.load_file(::Colours.file_256_colours)
48
+ _ = "#{RUBY_HEADER}\n".dup
49
+ _ << "# require 'colours/autogenerated/#{File.basename(into)}'\n"
50
+ _ << "# =========================================================================== #\n"
51
+ _ << "# include ::Colours::Module256Colours\n"
52
+ _ << "# =========================================================================== #\n"
53
+ _ << "module Colours\n\n"
54
+ _ << "module Module256Colours # === ::Colours::Module256Colours\n\n"
55
+ dataset_from_the_yaml_file.keys.each {|this_html_colour|
56
+ this_html_colour = this_html_colour.dup if this_html_colour.frozen?
57
+ pointer = dataset_from_the_yaml_file[this_html_colour.to_s] # Pointer must come first.
58
+ this_html_colour.downcase! # To turn 'LightGoldenrod1' into 'lightgoldenrod1'.
59
+ # ===================================================================== #
60
+ # We must obtain the proper entry from the .yml file next:
61
+ # ===================================================================== #
62
+ _ << " # ========================================================================= #\n"
63
+ _ << " # === Colours::Module256Colours.#{this_html_colour}\n"
64
+ _ << " # ========================================================================= #\n"
65
+ _ << " def self.#{this_html_colour}(i = '', &block)\n"
66
+ _ << ' return_this_256_colour('+pointer.first.to_s+', i)'+"\n"
67
+ _ << " end\n\n"
68
+ }
69
+ _ << "end\n\n"
70
+ _ << "end\n"
71
+ puts "Storing into the file `#{into}` next."
72
+ SaveFile.write_what_into(_, into)
73
+ autogenerate_256_colours_methods_for_instance_methods
74
+ end
75
+
76
+ # ========================================================================= #
77
+ # === Colours::Module256Colours.autogenerate_256_colours_methods_for_instance_methods
78
+ #
79
+ # This method will generate all instance-methods for the 256-colours
80
+ # part.
81
+ # ========================================================================= #
82
+ def self.autogenerate_256_colours_methods_for_instance_methods(
83
+ into = HOME_DIRECTORY_OF_USER_X+
84
+ 'programming/ruby/src/'\
85
+ 'colours/lib/colours/autogenerated/'\
86
+ '256_colours_instance_methods.rb'
87
+ )
88
+ require 'save_file'
89
+ dataset_from_the_yaml_file = YAML.load_file(::Colours.file_256_colours)
90
+ _ = "#{RUBY_HEADER}\n".dup
91
+ _ << "# require 'colours/autogenerated/#{File.basename(into)}'\n"
92
+ _ << "# =========================================================================== #\n"
93
+ _ << "# include ::Colours::Module256Colours\n"
94
+ _ << "# =========================================================================== #\n"
95
+ _ << "module Colours\n\n"
96
+ _ << "module Module256Colours # === ::Colours::Module256Colours\n\n"
97
+ dataset_from_the_yaml_file.keys.each {|this_html_colour|
98
+ this_html_colour = this_html_colour.dup if this_html_colour.frozen?
99
+ this_html_colour.downcase! # To turn 'LightGoldenrod1' into 'lightgoldenrod1'.
100
+ # ===================================================================== #
101
+ # We must obtain the proper entry from the .yml file next:
102
+ # ===================================================================== #
103
+ _ << " # ========================================================================= #\n"
104
+ _ << " # === #{this_html_colour}\n"
105
+ _ << " # ========================================================================= #\n"
106
+ _ << " def #{this_html_colour}(i = '', &block)\n"
107
+ _ << ' ::Colours::Module256Colours.'+this_html_colour.to_s+'(i)'+"\n"
108
+ _ << " end\n\n"
109
+ }
110
+ _ << "end\n\n"
111
+ _ << "end\n"
112
+ puts "Storing into the file `#{into}` next."
113
+ SaveFile.write_what_into(_, into)
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === Colours::Module256Colours.load_the_default_dataset
118
+ # ========================================================================= #
119
+ def self.load_the_default_dataset(
120
+ i = FILE_256_COLOURS
121
+ )
122
+ # ======================================================================= #
123
+ # === @dataset
124
+ #
125
+ # This is the dataset that holds the content of the .yml file specifying
126
+ # the (xterm) 256 colours.
127
+ #
128
+ # We will keep the keys in a downcased variant, as this will make it
129
+ # easier to use them as method-names.
130
+ # ======================================================================= #
131
+ if File.exist?(i) # Must safeguard.
132
+ @dataset = YAML.load_file(i).
133
+ transform_keys(&:downcase)
134
+ else
135
+ @dataset = nil
136
+ end
137
+ end
138
+
139
+ # ========================================================================= #
140
+ # === Colours::Module256Colours.return_this_256_colour (return tag)
141
+ #
142
+ # The first argument to this method should be a number from 0 to 255.
143
+ #
144
+ # For example, 255 is also known as "Grey93" - a variant of grey.
145
+ #
146
+ # It appears to work better if you use print() rather than puts() for
147
+ # whatever is returned here - perhaps due to the leading \u001b part.
148
+ #
149
+ # You can also input the colour variant, such as 'Grey93'.
150
+ #
151
+ # Invocation examples:
152
+ #
153
+ # Colours::Module256Colours.return_this_256_colour(255, "Hello world in grey!\n")
154
+ # print Colours::Module256Colours.return_this_256_colour(255, (Roebe.block_character*5)+" Hello world in grey! "+(Roebe.block_character*5)+" \n")
155
+ # print Colours::Module256Colours.return_this_256_colour('DarkTurquoise', (Roebe.block_character*5)+" Hello world in DarkTurquoise! "+(Roebe.block_character*5)+" \n")
156
+ #
157
+ # ========================================================================= #
158
+ def self.return_this_256_colour(
159
+ id = 9,
160
+ use_this_text = "Hello world!",
161
+ dataset = @dataset
162
+ )
163
+ id = id.to_s.downcase
164
+ if (id !~ /^\d+/) and
165
+ dataset and
166
+ dataset.has_key?(id)
167
+ id = dataset[id] # Query the real value from the dataset.
168
+ end
169
+ "\u001b[38;5;#{id}m#{use_this_text}#{REVERT}"
170
+ end
171
+
172
+ # ========================================================================= #
173
+ # === Colours::Module256Colours.dataset?
174
+ # ========================================================================= #
175
+ def self.dataset?
176
+ @dataset
177
+ end
178
+
179
+ # ========================================================================= #
180
+ # === Colours::Module256Colours.is_this_a_256_colour?
181
+ #
182
+ # Invocation example:
183
+ #
184
+ # Colours::Module256Colours.is_this_a_256_colour? 'LightSteelBlue3'
185
+ #
186
+ # ========================================================================= #
187
+ def self.is_this_a_256_colour?(
188
+ i,
189
+ dataset = dataset?
190
+ )
191
+ if dataset
192
+ dataset.keys.map(&:downcase).include?(i.to_s.downcase) # The input argument will be downcased as well.
193
+ else
194
+ false
195
+ end
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === Colours::Module256Colours.display_this_256_colour
200
+ #
201
+ # The first argument should be a number from 0 to 255.
202
+ #
203
+ # You can also batch-output all colours, by using something like:
204
+ #
205
+ # Colours.display_this_256_colour('0-255',"Hello world, in a batch!\n")
206
+ #
207
+ # Generic usage examples:
208
+ #
209
+ # Colours::Module256Colours.display_this_256_colour(33, 'yo there') { :newline }
210
+ # Colours::Module256Colours.display_this_256_colour(55, 'yo there') { :newline }
211
+ # Colours::Module256Colours.display_this_256_colour(77, 'yo there') { :newline }
212
+ #
213
+ # ========================================================================= #
214
+ def self.display_this_256_colour(
215
+ id = 9,
216
+ use_this_text = "Hello world!\n",
217
+ &block
218
+ )
219
+ # ======================================================================= #
220
+ # === Handle blocks given to this method next
221
+ # ======================================================================= #
222
+ if block_given?
223
+ yielded = yield
224
+ case yielded
225
+ # ===================================================================== #
226
+ # === :newline
227
+ # ===================================================================== #
228
+ when :newline
229
+ use_this_text = use_this_text.dup if use_this_text.frozen?
230
+ use_this_text << "\n"
231
+ end
232
+ end
233
+ if id.is_a?(String) and id.include?('-')
234
+ # ===================================================================== #
235
+ # Assume pseudo-range input.
236
+ # ===================================================================== #
237
+ splitted = id.split('-')
238
+ range = (splitted.first.to_i .. splitted.last.to_i).to_a
239
+ range.each {|this_range_id|
240
+ display_this_256_colour(this_range_id, use_this_text, &block)
241
+ }
242
+ else # else print the 256-colour
243
+ print ::Colours::Module256Colours.return_this_256_colour(id, use_this_text)
244
+ end
245
+ end; self.instance_eval { alias display_this_in_256_colour display_this_256_colour } # === Colours::Module256Colours.display_this_in_256_colour
246
+
247
+ # ========================================================================= #
248
+ # === is_this_a_256_colour?
249
+ # ========================================================================= #
250
+ def is_this_a_256_colour?(i)
251
+ ::Colours::Module256Colours.is_this_a_256_colour?(i)
252
+ end
253
+
254
+ # ========================================================================= #
255
+ # === Colours::Module256Colours.write_this_in_256_colours
256
+ #
257
+ # Similar to the other write method, but has the arguments reversed.
258
+ # ========================================================================= #
259
+ def self.write_this_in_256_colours(
260
+ this_text = "Hello world!\n",
261
+ id = rand(256),
262
+ &block
263
+ )
264
+ display_this_256_colour(id, this_text, &block)
265
+ end; self.instance_eval { alias write_in_256_colour write_this_in_256_colours } # === Colours::Module256Colours.write_in_256_colour
266
+
267
+ # ========================================================================= #
268
+ # === write_in_256_colour
269
+ #
270
+ # Include-able method to the above module-level instance.
271
+ # ========================================================================= #
272
+ def write_in_256_colour(
273
+ i = 'hi there',
274
+ id = 33
275
+ )
276
+ write_this_in_256_colours(i, id)
277
+ end
278
+
279
+ # ========================================================================= #
280
+ # === Colours::Module256Colours.show_256_colour_cube
281
+ #
282
+ # This will show the 256-colours cube. Colours 16-231 are a
283
+ # 6x6x6 color cube.
284
+ # ========================================================================= #
285
+ def self.show_256_colour_cube
286
+ e
287
+ e 'Color cube, 6x6x6 blocks:'
288
+ e
289
+ 0.upto(5) {|green|
290
+ 0.upto(5) {|red|
291
+ 0.upto(5) {|blue|
292
+ colour = 16 + (red * 36) + (green * 6) + blue
293
+ print "#{BLOCK_START}#{colour}m " # This creates a block.
294
+ }
295
+ print "#{BLOCK_END} "
296
+ }
297
+ e
298
+ }
299
+ end
300
+
301
+ # ========================================================================= #
302
+ # === Colours::Module256Colours.show_all_256_colours
303
+ # ========================================================================= #
304
+ def self.show_all_256_colours(&block)
305
+ yielded = nil
306
+ if block_given?
307
+ yielded = yield
308
+ end
309
+ 0.upto(255).each {|this_number|
310
+ result = this_number.to_s.rjust(4)+' '+
311
+ return_this_256_colour(this_number).to_s.dup
312
+ if yielded and yielded == :newline
313
+ result << "\n"
314
+ end
315
+ print result
316
+ }
317
+ end
318
+
319
+ end
320
+
321
+ # =========================================================================== #
322
+ # === Colours.show_256_colour_cube
323
+ # =========================================================================== #
324
+ def self.show_256_colour_cube
325
+ ::Colours::Module256Colours.show_256_colour_cube
326
+ end
327
+
328
+ # ========================================================================= #
329
+ # === Colours.display_this_256_colour
330
+ # ========================================================================= #
331
+ def self.display_this_256_colour(
332
+ id = 9,
333
+ use_this_text = "Hello world!\n",
334
+ &block
335
+ )
336
+ Colours::Module256Colours.display_this_256_colour(
337
+ id,
338
+ use_this_text,
339
+ &block
340
+ )
341
+ end
342
+
343
+ # =========================================================================== #
344
+ # === Colours.is_this_a_256_colour?
345
+ #
346
+ # Invocation example:
347
+ #
348
+ # Colours.is_this_a_256_colour? 'LightSteelBlue3'
349
+ #
350
+ # =========================================================================== #
351
+ def self.is_this_a_256_colour?(
352
+ i,
353
+ dataset = ::Colours::Module256Colours.dataset?
354
+ )
355
+ ::Colours::Module256Colours.is_this_a_256_colour?(i, dataset)
356
+ end
357
+
358
+ # =========================================================================== #
359
+ # === Colours.show_all_256_colours
360
+ # =========================================================================== #
361
+ def self.show_all_256_colours(&block)
362
+ ::Colours::Module256Colours.show_all_256_colours(&block)
363
+ end
364
+
365
+ # =========================================================================== #
366
+ # === Colours.map_this_symbol_to_that_256_colour
367
+ #
368
+ # This method will take input such as :bold_green and associate it with
369
+ # a corresponding 256-colour. Thus, the resulting Symbol that is
370
+ # found here should correspond to a method on the module
371
+ # Module256Colours.
372
+ # =========================================================================== #
373
+ def self.map_this_symbol_to_that_256_colour(i)
374
+ case i
375
+ # ========================================================================= #
376
+ # === :boldgreen
377
+ # ========================================================================= #
378
+ when :boldgreen,
379
+ :bold_green
380
+ :chartreuse2
381
+ # ========================================================================= #
382
+ # === :teal
383
+ # ========================================================================= #
384
+ when :teal
385
+ :teal
386
+ # ========================================================================= #
387
+ # === :bold_yellow
388
+ # ========================================================================= #
389
+ when :bold_yellow
390
+ :yellow2
391
+ # ========================================================================= #
392
+ # === :gold
393
+ # ========================================================================= #
394
+ when :gold
395
+ :gold3
396
+ # ========================================================================= #
397
+ # === :bold_blue
398
+ # ========================================================================= #
399
+ when :bold_blue
400
+ :lightslateblue
401
+ when :bold_brown
402
+ :darkred
403
+ when :brown
404
+ :maroon
405
+ when :pink
406
+ :hotpink3
407
+ when :lightgrey,
408
+ :light_grey
409
+ :grey66
410
+ when :bold_red
411
+ :red1
412
+ when :lightblue,
413
+ :light_blue
414
+ :deepskyblue3
415
+ when :grey
416
+ :grey53
417
+ when :green
418
+ :chartreuse4
419
+ else
420
+ e "Not known input to method #{__method__.to_s}: #{i}"
421
+ end
422
+ end
423
+
424
+ # =========================================================================== #
425
+ # === Colours.write_this_in_256_colours
426
+ #
427
+ # Similar to the other write method, but has the arguments reversed.
428
+ # =========================================================================== #
429
+ def self.write_this_in_256_colours(
430
+ this_text = "Hello world!\n",
431
+ id = rand(256),
432
+ &block
433
+ )
434
+ ::Colours::Module256Colours.display_this_256_colour(id, this_text, &block)
435
+ end; self.instance_eval { alias write_in_256_colour write_this_in_256_colours } # === Colours.write_in_256_colour
436
+
437
+ # =========================================================================== #
438
+ # === Colours.autogenerate_256_colours_methods
439
+ # =========================================================================== #
440
+ def self.autogenerate_256_colours_methods
441
+ Colours::Module256Colours.autogenerate_256_colours_methods
442
+ end; self.instance_eval { alias autogenerate_the_module_for_the_256_colours autogenerate_256_colours_methods } # === Colours.autogenerate_the_module_for_the_256_colours
443
+
444
+ end
445
+
446
+ if __FILE__ == $PROGRAM_NAME
447
+ alias e puts
448
+ Colours::Module256Colours.load_the_default_dataset
449
+ dataset = Colours::Module256Colours.dataset?
450
+ e 'We have '+dataset.keys.size.to_s+' entries.'
451
+ Colours.display_this_256_colour(55, 'yo there') { :newline }
452
+ Colours.display_this_256_colour(75, 'yo there') { :newline }
453
+ Colours.display_this_256_colour(125, 'yo there') { :newline }
454
+ e 'Ok - the above three lines tested the method Colours.display_this_256_colour().'
455
+ e
456
+ e 'Next we will call Colours.show_256_colour_cube() and other related methods.'
457
+ Colours.show_256_colour_cube
458
+ # The next line can be found in: colours/test/testing_256_colours_support.rb
459
+ # Colours.test_256_colours_support
460
+ e
461
+ Colours.display_this_256_colour('0-255',"Hello world, in a batch!\n")
462
+ e
463
+ print "\x1b[48;5;15000m TESTING \x1b[0m" # This creates a block.
464
+ e
465
+ end # supportfor256colours
@@ -14,9 +14,11 @@ module Colours
14
14
 
15
15
  # ========================================================================= #
16
16
  # === Colours.project_base_dir?
17
+ #
18
+ # This method should be used to query the project's base directory.
17
19
  # ========================================================================= #
18
20
  def self.project_base_dir?
19
21
  PROJECT_BASE_DIRECTORY
20
- end
22
+ end; self.instance_eval { alias project_base_directory? project_base_dir? } # === Colours.project_base_directory?
21
23
 
22
24
  end
@@ -2,10 +2,14 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
+ # require 'check_for_trollop_being_available_or_exit.rb'
6
+ # =========================================================================== #
5
7
  module Colours
6
8
 
7
9
  module RainbowColours
8
10
 
11
+ require 'colours/rainbow_colours/print_rainbow_line.rb'
12
+
9
13
  # ========================================================================= #
10
14
  # === Colours::RainbowColours.check_for_trollop_being_available_or_exit
11
15
  # ========================================================================= #
@@ -4,14 +4,14 @@
4
4
  # =========================================================================== #
5
5
  # require 'colours/rainbow_colours/constants.rb'
6
6
  # =========================================================================== #
7
- require 'colours/constants/newline.rb'
8
-
9
7
  module Colours
10
8
 
11
9
  module RainbowColours # === Colours::RainbowColours
12
10
 
11
+ require 'colours/constants/constants.rb'
12
+
13
13
  # ========================================================================= #
14
- # === DEFAULT_RAINBOW_SPREAD
14
+ # === Colours::RainbowColours::DEFAULT_RAINBOW_SPREAD
15
15
  # ========================================================================= #
16
16
  DEFAULT_RAINBOW_SPREAD = 3.0
17
17
 
@@ -6,21 +6,20 @@
6
6
  # =========================================================================== #
7
7
  # require 'colours/rainbow_colours/do_parse_via_rainbow_colours.rb'
8
8
  # =========================================================================== #
9
- require 'colours/toplevel_methods/cat.rb'
10
- require 'colours/toplevel_methods/clear_screen.rb'
11
- require 'colours/toplevel_methods/e.rb'
12
- # =========================================================================== #
13
- # Require rainbow_colours specific code next:
14
- # =========================================================================== #
15
- require 'colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb'
16
- require 'colours/rainbow_colours/constants.rb'
17
- require 'colours/rainbow_colours/paint_detected_mode.rb'
18
- require 'colours/rainbow_colours/report_errors.rb'
19
9
 
20
10
  module Colours
21
11
 
22
12
  module RainbowColours
23
13
 
14
+ require 'colours/toplevel_methods/toplevel_methods.rb'
15
+ # ========================================================================= #
16
+ # Require rainbow_colours specific code next:
17
+ # ========================================================================= #
18
+ require 'colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb'
19
+ require 'colours/rainbow_colours/constants.rb'
20
+ require 'colours/rainbow_colours/paint_detected_mode.rb'
21
+ require 'colours/rainbow_colours/report_errors.rb'
22
+
24
23
  begin
25
24
  require 'stringio'
26
25
  rescue LoadError; end