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