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