colours 0.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +862 -0
  4. data/bin/colours +7 -0
  5. data/bin/html_colour_to_hex_value +7 -0
  6. data/bin/html_colourize +7 -0
  7. data/bin/print_rainbow_line +7 -0
  8. data/bin/rainbow_colours +7 -0
  9. data/colours.gemspec +75 -0
  10. data/doc/COLOUR_CODES_CHART.md +28 -0
  11. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
  12. data/doc/README.gen +845 -0
  13. data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
  14. data/lib/colours/autoalias_e.rb +10 -0
  15. data/lib/colours/autogenerated/README.md +2 -0
  16. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  17. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  18. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
  19. data/lib/colours/autoinclude.rb +14 -0
  20. data/lib/colours/base/base.rb +23 -0
  21. data/lib/colours/basic_colours/README.md +4 -0
  22. data/lib/colours/basic_colours/basic_colours.rb +279 -0
  23. data/lib/colours/colour_methods/README.md +11 -0
  24. data/lib/colours/colour_methods/default_colour.rb +66 -0
  25. data/lib/colours/colour_methods/sargument.rb +70 -0
  26. data/lib/colours/colour_methods/scomments.rb +105 -0
  27. data/lib/colours/colour_methods/sdir.rb +66 -0
  28. data/lib/colours/colour_methods/sfancy.rb +84 -0
  29. data/lib/colours/colour_methods/sfile.rb +71 -0
  30. data/lib/colours/colour_methods/simportant.rb +92 -0
  31. data/lib/colours/colour_methods/snormal.rb +66 -0
  32. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  33. data/lib/colours/colour_methods/swarn.rb +76 -0
  34. data/lib/colours/colour_table/README.md +3 -0
  35. data/lib/colours/colour_table/colour_table.rb +275 -0
  36. data/lib/colours/colours_e_autoinclude.rb +9 -0
  37. data/lib/colours/commandline/README.md +2 -0
  38. data/lib/colours/commandline/commandline.rb +44 -0
  39. data/lib/colours/commandline/menu.rb +111 -0
  40. data/lib/colours/constants/colour_constants.rb +299 -0
  41. data/lib/colours/constants/file_constants.rb +72 -0
  42. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  43. data/lib/colours/constants/misc.rb +59 -0
  44. data/lib/colours/constants/newline.rb +14 -0
  45. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  46. data/lib/colours/e/README.md +13 -0
  47. data/lib/colours/e/autoinclude.rb +11 -0
  48. data/lib/colours/e/e.rb +35 -0
  49. data/lib/colours/e.rb +5 -0
  50. data/lib/colours/eparse/eparse.rb +77 -0
  51. data/lib/colours/everything/autoinclude.rb +11 -0
  52. data/lib/colours/html_colours/README.md +1 -0
  53. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  54. data/lib/colours/html_colours/hash_html_colours.rb +63 -0
  55. data/lib/colours/html_colours/html_colourize.rb +48 -0
  56. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  57. data/lib/colours/html_colours/misc.rb +186 -0
  58. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  59. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  60. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  61. data/lib/colours/module.rb +11 -0
  62. data/lib/colours/project/project_base_directory.rb +22 -0
  63. data/lib/colours/rainbow_colours/README.md +2 -0
  64. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  65. data/lib/colours/rainbow_colours/constants.rb +30 -0
  66. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  67. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  68. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  69. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  70. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  71. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  72. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  73. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  74. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  75. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  76. data/lib/colours/requires/require_commandline.rb +7 -0
  77. data/lib/colours/requires/require_eparse.rb +11 -0
  78. data/lib/colours/requires/require_rgb.rb +5 -0
  79. data/lib/colours/requires/require_sdir.rb +5 -0
  80. data/lib/colours/requires/require_sfile.rb +5 -0
  81. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  82. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  83. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  84. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  85. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  86. data/lib/colours/requires/require_the_constants.rb +11 -0
  87. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  88. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  89. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  90. data/lib/colours/revert/revert.rb +106 -0
  91. data/lib/colours/rgb/rgb.rb +538 -0
  92. data/lib/colours/testing/README.md +2 -0
  93. data/lib/colours/testing/testing.rb +157 -0
  94. data/lib/colours/toplevel_methods/bold.rb +35 -0
  95. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  96. data/lib/colours/toplevel_methods/cat.rb +39 -0
  97. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  98. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  99. data/lib/colours/toplevel_methods/col.rb +56 -0
  100. data/lib/colours/toplevel_methods/e.rb +63 -0
  101. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  102. data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
  103. data/lib/colours/toplevel_methods/html_colourize.rb +65 -0
  104. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  105. data/lib/colours/toplevel_methods/italic.rb +104 -0
  106. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  107. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +314 -0
  108. data/lib/colours/toplevel_methods/misc.rb +95 -0
  109. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  110. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
  111. data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
  112. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  113. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +107 -0
  114. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  115. data/lib/colours/toplevel_methods/underline.rb +114 -0
  116. data/lib/colours/toplevel_methods/use_colours.rb +311 -0
  117. data/lib/colours/utility_scripts/README.md +2 -0
  118. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  119. data/lib/colours/version/version.rb +25 -0
  120. data/lib/colours/yaml/256_colours.yml +277 -0
  121. data/lib/colours/yaml/basic_colours.yml +23 -0
  122. data/lib/colours/yaml/html_colours.yml +835 -0
  123. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  124. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  125. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
  126. data/lib/colours.rb +5 -0
  127. data/test/test.html +18 -0
  128. data/test/testing_256_colours_support.rb +29 -0
  129. data/test/testing_col.rb +10 -0
  130. data/test/testing_colours.rb +95 -0
  131. data/test/testing_colours_e.rb +13 -0
  132. data/test/testing_eparse.rb +13 -0
  133. data/test/testing_kde_colour_palette.rb +30 -0
  134. data/test/testing_konsole_submodule.rb +226 -0
  135. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  136. data/test/testing_rgb_to_hex.rb +32 -0
  137. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  138. data/test/testing_the_colour_methods.rb +36 -0
  139. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  140. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  141. data/test/testing_whether_colours_will_be_used.rb +7 -0
  142. metadata +224 -0
data/doc/README.gen ADDED
@@ -0,0 +1,845 @@
1
+ ADD_RUBY_HEADER
2
+
3
+ # The Colours project
4
+
5
+ ## Goals, Scope and the History of the colours project
6
+
7
+ The Colours project originated from a requirement to have to support **colours**
8
+ on the commandline. Colours can be immensely helpful, so it makes sense
9
+ to make use of them on the commandline. The modern www also makes use of
10
+ colours - just look at any random webpage; you may find lots of
11
+ different colours in use there.
12
+
13
+ If you look on rubygems.org then you will be able to find **lots** of
14
+ different colour-related projects, written in ruby. The primary reason as
15
+ to why I created a new colour-centric project was because I needed certain
16
+ functionality that was not provided by any of the other projects;
17
+ at the least not in a way as I thought it should be available
18
+ (and used in downstream projects). For example, some terminals support
19
+ **RGB values** and others do not. I did not want to have to spend time
20
+ thinking about this much at all, so I wanted to have a colours-related
21
+ project that could abstract this away for me.
22
+
23
+ ![alt text][screenshot1]
24
+ [screenshot1]: https://i.imgur.com/F6kac8W.png
25
+
26
+ The **main goal** of the **colours project** is to collect colour-related
27
+ code and make this code available to other projects, so that these projects
28
+ can benefit from colour support.
29
+
30
+ The primary goal herein is for **commandline applications**, but there
31
+ are some HTML components as part of this project that could be used,
32
+ such as for when you wish to make use of **HTML colours** (slateblue,
33
+ royalblue, teal, tomato, steelblue and names such as these).
34
+
35
+ Note that many **terminals** support the **display of HTML colours**, via
36
+ their **corresponding RGB values**. Since I wanted to use good terminals,
37
+ such as the **KDE konsole**, the colours project also had to support
38
+ these names (such as **slateblue** or **royalblue**) directly. This is
39
+ why method calls such as **Colours.royalblue()** will also work - see
40
+ for a later subsection how to customize (and control) this.
41
+
42
+ The **Colours gem** has other, older projects, such as AnsiColours,
43
+ ColourE, AliasE and several other smaller sub-projects that I have
44
+ used over the years, integrated. It is thus a **bundled project**. This
45
+ is specifically mentioned in the event that you may wish to look at
46
+ the code, and wonder a little why it is structured the way it is.
47
+
48
+ ## Requiring the colours project
49
+
50
+ To require the colours project, do:
51
+
52
+ require 'colours'
53
+
54
+ You can also **autoinclude** this module into your project, at
55
+ <b>require-time</b>, via:
56
+
57
+ require 'colours/autoinclude'
58
+
59
+ This will make the **Colours namespace** and the
60
+ **Colours::HtmlColours namespace** available, via
61
+ **include Colours** ultimately.
62
+
63
+ If you need more control over the include-action then you should
64
+ just use the first variant, require 'colours', and then do the
65
+ include action specifically onto whatever class/module you need
66
+ that functionality.
67
+
68
+ ## Introduction and Overview
69
+
70
+ The toplevel module name is **Colours** and you can include
71
+ this module in any of your classes, via:
72
+
73
+ require 'colours'
74
+
75
+ include Colours
76
+
77
+ If you include Colours into main (toplevel), then you can simply
78
+ use the colour-constants directly:
79
+
80
+ puts RED+'This is a red text.'
81
+ puts BLUE+'This will be in blue.'
82
+
83
+ Keep in mind when you use something like the above, with the
84
+ leading escape-code for RED or BLUE, then this is missing the
85
+ proper escape-code for **end** (**revert**). This value is
86
+ usually **\e[0;37m**, or simpler, use **Colours.rev()** such
87
+ as in:
88
+
89
+ puts RED+'This is a red text.'+Colours.rev
90
+ puts BLUE+'This will be in blue.'+Colours.rev
91
+
92
+ The corresponding colour-methods can also be used:
93
+
94
+ red 'This is a red text.'
95
+ blue 'This is a blue text.'
96
+
97
+ This has the advantage that you do not have to use
98
+ Colours.rev anymore. So in some ways the colour-named
99
+ methods are better. (Of course it is a bit complicated
100
+ if you want to use RGB colours, so always make sure to
101
+ specifically **include** what you really need.)
102
+
103
+ Colour-related constants are simply **hardcoded**, such as
104
+ in this way:
105
+
106
+ GREEN = "\e[0;32m"
107
+
108
+ To test all colours, after requiring the project such as
109
+ described above, do:
110
+
111
+ Colours.test
112
+
113
+ Several methods exist as well, such as sfancy(), swarn(),
114
+ simp(), sdir() and sfile(), among others.
115
+
116
+ These methods can be used to colourize certain Strings,
117
+ such as:
118
+
119
+ a file -> use sfile()
120
+ a directory -> use sdir()
121
+ a warning -> use swarn()
122
+
123
+ The methods sfancy() and simp() are there to denote
124
+ more important output, usually in the middle of a String.
125
+ Think of this as a way to emphasis what you wish to
126
+ display to the user at hand. (The important parts of
127
+ the sentence should be colourized and emphasized.)
128
+
129
+ To make use of the **html-colours component**, such as converting
130
+ a "HTML Colour" to its RGB values, you can do this:
131
+
132
+ puts Colours::HtmlColours.colour_to_rgb(:sienna)
133
+ puts Colours.html_colours.colour_to_rgb(:sienna)
134
+
135
+ If you want to return a random HTML colour, you can use this
136
+ method call:
137
+
138
+ Colours::HtmlColours.random
139
+
140
+ or
141
+
142
+ Colours.html_colours.sample # => "darksalmon"
143
+ Colours.html_colours.sample # => "turquoise"
144
+ Colours.html_colours.sample # => "lightblue"
145
+
146
+ Or just:
147
+
148
+ Colours.sample # => "khaki"
149
+ Colours.random_html_colour # => "slateblue"
150
+
151
+ Use whichever variant you prefer. The shorter names are more elegant in
152
+ my opinion.
153
+
154
+ In general, the html component can be used to convert the trivial
155
+ <b>html colours</b> into <b>corresponding R,G,B values</b>.
156
+
157
+ ## Linux terminals and colour support
158
+
159
+ The general syntax rules for colours is in the form of **fg_bg** values,
160
+ where a value of 38 stands for the foreground, and 48 stands for
161
+ the background.
162
+
163
+ The ANSI colour for red is 196 and the ANSI colour for black is
164
+ 0.
165
+
166
+ To use the colour red, you could issue this command:
167
+
168
+ printf "\e[38;5;196m Hello world in red\n"
169
+
170
+ To use the colour black as background, you could issue this command:
171
+
172
+ printf "\e[48;5;0m Hello world in black\n"
173
+
174
+ Do note that the same can be accomplished via RGB values rather than
175
+ ANSI color codes, as long as the terminal supports this (KDE Konsole
176
+ does).
177
+
178
+ Depending on whether you want to apply the color to the foreground or
179
+ to the background, use an **fg_bg** value of 38 or 48 (respectively).
180
+
181
+ Example:
182
+
183
+ printf "\e[<fg_bg>;2;<R>;<G>;<B>m"
184
+ printf "\e[38;2;255;0;0m Foreground color: red\n"
185
+ printf "\e[48;2;0;0;0m Background color: black\n"
186
+
187
+ This may be the better variant altogether, as it is quite easy to convert
188
+ into (and from) **RGB values**, but your mileage may vary.
189
+
190
+ Of course you can use this in plain ruby just as well - let's show this
191
+ via puts:
192
+
193
+ puts "\e[38;2;#{222};#{131};#{141}m Hello world!"
194
+ puts "\e[38;2;#{122};#{56};#{141}m Hello world!"
195
+ puts "\e[38;2;122;156;141m Hello world!"
196
+ puts "\x1b[3mHello world!\x1b[0m"
197
+ puts "\e[38;3mHello world!\x1b[0m"
198
+
199
+ In bash the ESC code can be either of the following:
200
+
201
+ \e
202
+ \033 (octal)
203
+ \x1B (hexadecimal)
204
+
205
+ The "\e[0m" sequence removes all attributes, including formatting and colors.
206
+ It may be useful to add it to the end of each colour text - and this is
207
+ what the **Colours** project is essentially doing.
208
+
209
+ To see which colours are supported/supportable, for each terminal,
210
+ have a look at the following **link**:
211
+
212
+ https://misc.flogisoft.com/bash/tip_colors_and_formatting#terminals_compatibility
213
+
214
+ To set both the foreground and background colours at once, you can use:
215
+
216
+ printf "\e[S;FG;BGm"
217
+ echo -e "\e[S;FG;BGm"
218
+
219
+ For example, bold white foreground on a red background:
220
+
221
+ printf "\e[1;97;41mHello world!"
222
+ printf "\e[1;97;41mHello world!\n"
223
+
224
+ Thus, if you would like to use red colour on black background,
225
+ you could do this:
226
+
227
+ printf '\e[38;5;196m;\e[48;5;0m Hello world!\n'
228
+
229
+ Specifically, the background colours are:
230
+
231
+ 40 black
232
+ 41 red
233
+ 42 green
234
+ 43 yellow
235
+ 44 blue
236
+ 45 magenta
237
+ 46 cyan
238
+ 47 white
239
+
240
+ The following command will use red background:
241
+
242
+ echo -e '\e[0;41m'
243
+ echo -e '\e[0;41m hello world\n\n ok\e[0;m'
244
+
245
+ ## Obtain all available HTML colours
246
+
247
+ To obtain all available html-colours, do this:
248
+
249
+ Colours::HtmlColours.all_colours?
250
+
251
+ Or in a simpler way, without the ::HtmlColours part:
252
+
253
+ Colours.return_all_html_colours
254
+
255
+ There are presently 142 registered HTML colours available:
256
+
257
+ Colours.return_all_html_colours.size # => 142
258
+
259
+ If you need to find out whether a given String (a **word**)
260
+ is registered as part of the HTML-Colours within **module
261
+ Colours**, then you could use the following toplevel-method:
262
+
263
+ Colours.is_this_html_colour_included?
264
+ Colours.is_this_html_colour_included? :slateblue # => true
265
+ Colours.is_this_html_colour_included? 'royalblue' # => true
266
+
267
+ ## eparse()
268
+
269
+ The eparse() method is a convenience method to apply on
270
+ Strings such as 'Foo: bar'. Note the ':' character
271
+ there. That input will be split, and then displayed
272
+ via two different colours.
273
+
274
+ ## Underline / Underlining
275
+
276
+ You can **underline** text, and print it onto the terminal,
277
+ by issuing a command such as the following:
278
+
279
+ txt = 'Hello world!'
280
+
281
+ Colours.underline(txt)
282
+
283
+ You can also add colours to this, via {}:
284
+
285
+ Colours.underline(txt)
286
+ Colours.underline(txt) { :palegreen }
287
+ Colours.underline(txt) { :slateblue }
288
+ Colours.underline(txt) { :orange }
289
+ Colours.underline(txt) { :crimson }
290
+
291
+ Within the {} block you can use HTML colours, as symbol, such as
292
+ :slateblue or :orange and so forth. If you would rather not like
293
+ to use these colours then simply do not pass them into the
294
+ method, as the first variant shows. :)
295
+
296
+ If you only want to get the colour code for that string, without
297
+ displaying it on the terminal it, then you can use .string_underline()
298
+ or .return_underline() method:
299
+
300
+ Colours.string_underline(txt) { :palegreen }
301
+ Colours.string_underline(txt) { :slateblue }
302
+ Colours.string_underline(txt) { :orange }
303
+ Colours.string_underline(txt) { :crimson }
304
+ Colours.return_underline(txt) { :royalblue }
305
+
306
+ ## include Colours::Methods
307
+
308
+ Since as of February 2019 there is a module called **Methods**
309
+ part of the colours gem. This module allows us to include
310
+ the konsole-related colour methods into a subclass.
311
+
312
+ Example:
313
+
314
+ class Foo
315
+ include Colours::Methods
316
+ end
317
+
318
+ e Foo.new.royalblue('hey there')
319
+
320
+ As you can see, this class will have the HTML colours available,
321
+ such as .royalblue() or .slateblue() and so forth.
322
+
323
+ I needed this in some of my other code, so it was added. I like
324
+ full colour support on terminals such as **KDE konsole**.
325
+
326
+ Note that this has to be specifically included, as I am not sure
327
+ everyone wants to have that the moment **include Colours** is
328
+ done. The toplevel Colours module will stay a bit simpler by
329
+ default; for customization, you will have to go the extra
330
+ line through **include Colours::Methods**, which appears to be
331
+ an acceptable trade-off.
332
+
333
+ Note that you can also subclass from a "dummy" class with colour
334
+ support, such as royalblue() or slateblue.
335
+
336
+ Use code similar to the following variant for this:
337
+
338
+ require 'colours/base/base.rb'
339
+
340
+ class Foobar < Colours::Base # Or whatever the name of your class is
341
+ end
342
+
343
+ ## KDE Konsole support
344
+
345
+ The **Colours gem** used to have a submodule called **Konsole**,
346
+ in particular the <b>KDE Konsole</b>. In May 2019 this submodule
347
+ was removed; the functionality is now available in the form of
348
+ an autogenerated .rb file instead.
349
+
350
+ You can **use RGB colours** in the KDE konsole (but also in
351
+ other terminal-types such as vte-based ones, like
352
+ **mate-terminal**).
353
+
354
+ For an example, have a look at the file **bin/colours**
355
+ that is distributed with this gem here (the colours gem). That file
356
+ will output all the HTML colour variants (via their RGB values).
357
+ Best shown on a black background in your terminal.
358
+
359
+ To **view all RGB colours** based on their HTML names, such
360
+ as <b>palegreen</b> or <b>slateblue</b>, do this:
361
+
362
+ colours
363
+
364
+ Also note that since as of **May 2018**, you can invoke the
365
+ HTML colours on the Konsole namespace directly, including
366
+ text-output, via code like this:
367
+
368
+ Colours.edarkgreen 'yo there'
369
+ Colours.eslateblue 'yo there'
370
+ Colours.eroyalblue 'yo there'
371
+ Colours.edarkgreen 'Hello world!'
372
+
373
+ The leading 'e' of these methods stands for "echo", aka
374
+ puts-related output. In other words, to print the text
375
+ that comes afterwards.
376
+
377
+ To print something in bold, you can use **Colours.bold()**
378
+ like in this way:
379
+
380
+ Colours.bold
381
+
382
+ ## Showing the colour palette on the commandline
383
+
384
+ You can show the "classical" ASCII colours on the commandline by
385
+ invoking this method:
386
+
387
+ Colours.show_palette
388
+
389
+ This also works, or should work, from the commandline, like so:
390
+
391
+ colours --show-palette
392
+ colours --palette
393
+
394
+ ## The KDE colour palette
395
+
396
+ The **KDE project** makes use of a special, **named colour palette**.
397
+
398
+ This palette includes the following **20 different colours**, via
399
+ a trivial name:
400
+
401
+ Abyss Blue
402
+ Alternate Grey
403
+ Beware Orange
404
+ Burnt Charcoal
405
+ Cardboard Grey
406
+ Charcoal Grey
407
+ Coastal Fog
408
+ Deco Blue
409
+ Hover Blue
410
+ Hyper Blue
411
+ Icon Blue
412
+ Icon Green
413
+ Icon Grey
414
+ Icon Red
415
+ Icon Yellow
416
+ Lazy Grey
417
+ Noble Fir
418
+ Paper White
419
+ Pimpinella
420
+ Plasma Blue
421
+
422
+ You can find these entries, including their hex-values and their
423
+ RGB values, on websites such as this one here:
424
+
425
+ https://community.kde.org/KDE_Visual_Design_Group/HIG/Color
426
+
427
+ Note that these are also called the "Breeze" colours, which I
428
+ assume is the name of the theme.
429
+
430
+ Since as of July 2018, the colours project also includes these
431
+ colours, via the file <b>colours/constants/kde_colour_palette.rb</b>.
432
+
433
+ The entries are stored in a **.yml file**, so if anyone wants to re-use
434
+ these from a yaml file, feel free to just copy/paste it from there.
435
+ That file is at <b>colours/yaml/kde_colour_palette.yml</b>.
436
+
437
+ Internally, the values are made available via the constant:
438
+
439
+ Colours::KDE_COLOUR_PALETTE
440
+
441
+ Which is a hash. There are also a few methods that may be useful to
442
+ use. For example, if you want to use a random colour, and output
443
+ <b>Hello world!</b>, then you could use the following method:
444
+
445
+ Colours.write_this_via_kde_colour_palette 'Hello world!', :random
446
+
447
+ While random colours may be nice, perhaps you may want to use a
448
+ definite colour from the above list. Say that you may want to
449
+ write via <b>Plasma Blue</b>. In this case, you could use:
450
+
451
+ Colours.write_this_via_kde_colour_palette 'Hello world!', :plasma_blue
452
+
453
+ So using a symbol works too.
454
+
455
+ If you tend to use this regularly, then an even simpler way may exist,
456
+ by simply calling a method that already has that as part of its name.
457
+
458
+ Examples with **Hello World!**:
459
+
460
+ Colours.kde_colour_palette_abyss_blue 'Hello world!'
461
+ Colours.kde_colour_palette_alternate_grey 'Hello world!'
462
+ Colours.kde_colour_palette_beware_orange 'Hello world!'
463
+ Colours.kde_colour_palette_burnt_charcoal 'Hello world!'
464
+ Colours.kde_colour_palette_cardboard_grey 'Hello world!'
465
+ Colours.kde_colour_palette_charcoal_grey 'Hello world!'
466
+ Colours.kde_colour_palette_coastal_fog 'Hello world!'
467
+ Colours.kde_colour_palette_deco_blue 'Hello world!'
468
+ Colours.kde_colour_palette_hover_blue 'Hello world!'
469
+ Colours.kde_colour_palette_hyper_blue 'Hello world!'
470
+ Colours.kde_colour_palette_icon_blue 'Hello world!'
471
+ Colours.kde_colour_palette_icon_green 'Hello world!'
472
+ Colours.kde_colour_palette_icon_grey 'Hello world!'
473
+ Colours.kde_colour_palette_icon_red 'Hello world!'
474
+ Colours.kde_colour_palette_icon_yellow 'Hello world!'
475
+ Colours.kde_colour_palette_lazy_grey 'Hello world!'
476
+ Colours.kde_colour_palette_noble_fir 'Hello world!'
477
+ Colours.kde_colour_palette_paper_white 'Hello world!'
478
+ Colours.kde_colour_palette_pimpinella 'Hello world!'
479
+ Colours.kde_colour_palette_plasma_blue 'Hello world!'
480
+
481
+ The reason as to why this is so long is so that we can avoid any name clashes -
482
+ but in principle, we could also enable a **shorter name**, such as:
483
+
484
+ Colours.pimpinella # much shorter than Colours.kde_colour_palette_pimpinella
485
+
486
+ You can also use the "e" method, **e** which stands for **echo**, such as in:
487
+
488
+ Colours.epimpinella 'Hello cats!'
489
+
490
+ This functionality is available for the Colours project since as of July 2018 -
491
+ but be careful, since this may change one day, in the event that a conflict
492
+ may exist with an already defined name (such as the names in the HTML colour
493
+ charts, e. g. "slateblue", "royalblue" and so forth).
494
+
495
+ Do note that the behaviour may change, too; e. g. **Colours.pimpinella()** may in
496
+ the future only return a String, and a new method called **Colours.epimpinella()**
497
+ would be tasked with outputting the text - but for the time being, things stay
498
+ as described above (in July 2018).
499
+
500
+ ## Generating a shell file with all HTML colours
501
+
502
+ You can generate a shell file that can be sourced, in **bash**, **fish**
503
+ and possibly **zsh**, in order to make use of the HTML colours on the
504
+ commandline.
505
+
506
+ The method that does so is:
507
+
508
+ Colours.generate_shell_file_containing_the_html_colours()
509
+
510
+ This will store in the current working directory; or to another
511
+ directory if you pass an argument to it.
512
+
513
+ The file will have entries such as:
514
+
515
+ export CHARTREUSE="\e[38;2;127;255;0m"
516
+
517
+ This is the RGB variant for the colour at hand. The closing tag
518
+ is missing there, so you may have to use it if you wish to
519
+ output text that is coloured.
520
+
521
+ You can source this .sh file and re-use it in your own scripts.
522
+
523
+ You can also generate this **shell file** from the commandline,
524
+ through **bin/colours**.
525
+
526
+ Issue a command like any of the following variants:
527
+
528
+ colours --generate-shell-file-containing-the-html-colours
529
+ colours --generate_shell_file_containing_the_html_colours
530
+ colours --generateshellfilecontainingthehtmlcolours
531
+ colours --create-shell-file
532
+
533
+ == Using the Konsole submodule
534
+
535
+ In the past there was a Konsole submodule, but in May 2019 during
536
+ a large rewrite, this submodule has been removed.
537
+
538
+ The functionality has been integrated into an autogenerated .rb
539
+ file though. That module can be found in the file called
540
+ **toplevel_basic_colour_methods.rb**.
541
+
542
+ Old invocation examples such as:
543
+
544
+ Colours[:slateblue]
545
+
546
+ Should be possible still.
547
+
548
+ You can also include this new module:
549
+
550
+ include Colours::AllColourMethods
551
+
552
+ Then you can simply call the respective colour output:
553
+
554
+ slateblue('Hello World!')
555
+
556
+ eslateblue()
557
+ eslateblue('Hello World!')
558
+
559
+ eslateblue() works like slateblue() but outputs the
560
+ result.
561
+
562
+ konsole_colour_slateblue('Hello World!')
563
+ ekonsole_colour_slateblue('Hello world!')
564
+
565
+ The above two variants are probably too long, but they
566
+ also exist if you wish to be more specific.
567
+
568
+ Automatic inclusion can be done like so:
569
+
570
+ require 'colours/konsole/autoinclude'
571
+
572
+ Konsole['slateblue']+'Hello World'
573
+ konsole :green, 'hello world'
574
+
575
+ Of course you can also manually include it by yourself:
576
+
577
+ require 'colours'
578
+
579
+ Note that when you include that module, you will have access
580
+ to methods such as e. g. slateblue() or sandybrown().
581
+
582
+ konsole_colours :slateblue, 'hello world!'
583
+
584
+ ## 256 colour support
585
+
586
+ Some terminals allow **support for 256 colours**.
587
+
588
+ The colours gem allows you to test this, via this toplevel-method:
589
+
590
+ Colours.show_all_256_colours
591
+
592
+ If you need to specifically use one of these colours, have a look
593
+ at the following two methods:
594
+
595
+ Colours.return_this_256_colour()
596
+ Colours.display_this_256_colour()
597
+
598
+ The first input argument should be the number, from 0-255, and
599
+ the second argument is the text that is to be displayed (append
600
+ a newline to this if you need one).
601
+
602
+ The first input argument is called <b>id</b>, for the purpose of
603
+ this document here.
604
+
605
+ Let's provide specific examples how to use the latter method.
606
+
607
+ For example, to ouput, in **red**, the sentence "<b>Ruby is awesome!</b>",
608
+ you could use either of the following methods:
609
+
610
+ Colours.display_this_256_colour(88, "Ruby is awesome!\n")
611
+ Colours.display_this_in_256_colour(88, "Ruby is awesome!\n")
612
+
613
+ Note that you can also use several colours, based on the id input,
614
+ via a pseudo-range. A **pseudo-range** is input that is a String and
615
+ includes one '-' character. For example, **33-44** is a pseudo-range
616
+ and so is **0-255**.
617
+
618
+ In ruby code, this could work like so - give it a try:
619
+
620
+ require 'colours'
621
+
622
+ Colours.display_this_256_colour('0-255',"Hello world, in a batch!\n")
623
+
624
+ If you wish to make use of these colour-methods in one of your classes,
625
+ then you can require the module, and include it into your class.
626
+
627
+ Example for this:
628
+
629
+ require 'new_colours/autogenerated/support_for_256_colours.rb'
630
+
631
+ class Foobar
632
+
633
+ include NewColours::SupportFor256Colours
634
+
635
+ def initialize
636
+ puts darkturquoise('HELLO ')+
637
+ maroon('WORLD ')+
638
+ 'This is ok again'
639
+ end
640
+
641
+ end
642
+
643
+ Foobar.new
644
+
645
+ ## revert
646
+
647
+ The toplevel instance variable called **@revert** designates which
648
+ escape code is used for reverting the colours again.
649
+
650
+ By default, this is **\e0m**. However had, for some strange reason
651
+ this does not appear to work very well on the default terminal
652
+ style that I use (KDE konsole, white font on black background).
653
+ It seems to default to white bold text, but I would rather want
654
+ light white text, aka **\e[0;37m**. This is why revert defaults
655
+ to **\e[0;37m**.
656
+
657
+ If you wish to use \e0m instead, then you can do so via:
658
+
659
+ Colours.set_revert('\e0m')
660
+
661
+ Or, via symbol, to the same value:
662
+
663
+ Colours.set_revert(:default)
664
+
665
+ ## Legacy versions of the Colours gem
666
+
667
+ In May 2019, the old **Konsole** submodule has been removed; the
668
+ functionality itself has been retained, though. Still, as the API
669
+ changed this means that not everyone may be able to use the new
670
+ colours gem release.
671
+
672
+ This is the reason why the old version at **0.3.40** will continue
673
+ to be available here. This one still has the old **Colours::Konsole**
674
+ submodule defined, so if you need it in a project, feel free to
675
+ use that older version.
676
+
677
+ Otherwise I recommend to **upgrade** to the latest version of the
678
+ colours gem - the code is, in my opinion, better too.
679
+
680
+ ## Available colour methods
681
+
682
+ If you wish to find out which colour methods will be available by
683
+ default, onto the main Colours namespace, you can use the following
684
+ method to find out:
685
+
686
+ Colours.all_available_colour_methods?
687
+
688
+ This will return an Array containing the names of all these
689
+ toplevel methods. In May 2019 we can find 307 available
690
+ colour methods e. g. such as **Colours.slateblue** or
691
+ **Colours.lightblue** and so forth.
692
+
693
+ ## Remove escaping sequences
694
+
695
+ If you wish to remove all escaping sequences from a given String,
696
+ you can use the following API for this:
697
+
698
+ Colours.remove_escape_sequences()
699
+ Colours.remove_escape_sequences "\e[38;2;41;128;18mHello world!\e[0;37m" # => "Hello world!"
700
+ pp Colours.remove_escape_sequences(Colours.slateblue('Hello world!')) # => "Hello world!"
701
+
702
+ The latter example shows that the escape-sequences are properly removed.
703
+
704
+ If you still find an example where the escape sequences are not
705
+ working properly, e. g. because they are retained, then consider
706
+ this to be a bug; once reported, a test case can be added to allow
707
+ for removing this escape sequence as well.
708
+
709
+ **Sometimes** you may **only wish to remove the trailing escape
710
+ sequence**, aka "\e[0;37m". In this case the following method may
711
+ be useful:
712
+
713
+ Colours.remove_trailing_end_from()
714
+ Colours.remove_trailing_ansii_escape_code()
715
+
716
+ Usage example:
717
+
718
+ x = Colours.remove_trailing_end_from("\e[38;2;70;130;180m\e[0;37m") # => "\e[38;2;70;130;180m"
719
+
720
+ ## Colours.does_this_line_include_a_html_colour?
721
+
722
+ If you need to determine whether a line (a string) includes a valid
723
+ HTML colour, such as slateblue>, then you can use the following method:
724
+
725
+ Colours.does_this_line_include_a_html_colour?
726
+ Colours.does_this_line_include_a_html_colour? "<green>yo there</green> <orange>getline() function</orange>" # => true
727
+ Colours.does_this_line_include_a_html_colour? "foo bar" # => false
728
+
729
+ ## Colours.replace_all_html_colours_in_this_line
730
+
731
+ If you wish to replace all HTML colours in a given line/string,
732
+ then the following **toplevel method** can be used:
733
+
734
+ Colours.replace_all_html_colours_in_this_line
735
+ puts Colours.replace_all_html_colours_in_this_line '<one>hey</one>' # ← This variant works as well.
736
+
737
+ This has been specifically added for commandline-use. It allows us
738
+ to replace HTML colour "tags" with the corresponding RGB value,
739
+ so that a terminal emulator such as the KDE konsole can display
740
+ this.
741
+
742
+ ## Rainbow colours
743
+
744
+ You must install the paint gem first:
745
+
746
+ gem install paint
747
+
748
+ Then you can do the following:
749
+
750
+ Colours::RainbowColours.print_rainbow_line("Hello world \n" * 40)
751
+
752
+ To print a line directly you can also use printl_plain():
753
+
754
+ Colours::RainbowColours.println_plain "one two three four five six seven eight nine ten\n\n\n"
755
+
756
+ ## Colours.fancy_parse
757
+
758
+ The toplevel method **Colours.fancy_parse()** can be used to
759
+ parse a more complicated text/string.
760
+
761
+ For example, say that you have a HTML string with embedded i
762
+ tag and HTML colours.
763
+
764
+ You can display this on the commandline.
765
+
766
+ Example:
767
+
768
+ puts Colours.fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
769
+ puts Colours.fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
770
+ puts Colours.fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
771
+ puts Colours.fancy_parse "<tomato><b>Hello world.</b></tomato>"
772
+ puts Colours.fancy_parse "<tomato>Hello world.</tomato>"
773
+
774
+ I recommend the KDE Konsole for this, but it should work on gnome-terminal as
775
+ well. Currently (September 2019) only HTML colours, such as tomato, steelblue,
776
+ and so forth, are supported, as well as i (italic). This may be extended at
777
+ a later time including bold.
778
+
779
+ Note that this is not working perfectly correctly for longer strings with
780
+ lots of tags. At a later point this will have to be improved, but for now,
781
+ it simply has to suffice. Patches are welcome, though. :)
782
+
783
+ ## Support for italic text
784
+
785
+ In KDE konsole, the escape sequences \e[3m and \e[23m can be used
786
+ to turn italics on and off, respectively. See this commit:
787
+
788
+ https://invent.kde.org/utilities/konsole/commit/68a98ed77063e622985d422b625d7dc5895f10c3
789
+
790
+ Let's have a look at an example for this in ruby (and KDE konsole):
791
+
792
+ puts "\e[3mHello world!\e[23m"
793
+
794
+ I tested this in July 2020 and it works fine.
795
+
796
+ Of course it can also work on the commandline, e. g. via bash/zsh or
797
+ a similar shell:
798
+
799
+ echo -e "\e[3mHello world!\e[23m"
800
+
801
+ ## Converting html-colours to their HEX value
802
+
803
+ If you want to convert a html-colour into the corresponding RGB value
804
+ then try bin/html_colour_to_hex_value like in this way:
805
+
806
+ html_colour_to_hex_value slateblue # Output would be '#6A5ACD', without '' quotes.
807
+
808
+ (You may have to add the bin/ path of that gem to your $PATH.)
809
+
810
+ ## Removing html-colours and other "tags" from a String
811
+
812
+ If you have entries such as <one> or <steelblue> (aka one, and steelblue),
813
+ and wish to replace them with the RGB values, for commandline use,
814
+ you could try to use this method:
815
+
816
+ Colours.eliminate_html(your_string_here)
817
+ Colours.away_with_html_colours_and_special_numbers(your_string_here)
818
+ Colours.away_with_html_colours_and_special_numbers "<royalblue>+</royalblue>" # => "\e[38;2;128;128;128m\e[38;2;65;105;225m+\e[38;2;128;128;128m"
819
+
820
+ This was needed so that other projects can **turn strings into colourized
821
+ strings** - on the commandline. This explains the result, as the \e is
822
+ typically used to specify an escape sequence.
823
+
824
+ ## Licence
825
+
826
+ The project used to be under the **GPL-2.0 licence** (no later clause),
827
+ until **August 2019** (**26.08.2019**, in dd.mm.yyyy notation).
828
+
829
+ However had, I have changed my mind for various reasons (including the
830
+ situation that different projects, with different licenses, may make
831
+ use of the **colours gem**) and thus re-published the colours
832
+ project under the less stringent **MIT licence**. Both licences are
833
+ fine licences, but I feel that for the basic building blocks, such
834
+ as the colours gem, a less stringent licence makes a lot more
835
+ sense.
836
+
837
+ See the file **LICENCE.md** for this licence, or just have look at
838
+ the following URL here:
839
+
840
+ https://opensource.org/licenses/MIT
841
+
842
+ Replace the effective year simply with whatever was the last release
843
+ on the rubygems.org homepage of this gem here.
844
+
845
+ ADD_CONTACT_INFORMATION