colours 0.5.52

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

Potentially problematic release.


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

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