colours 0.8.12 → 0.9.8
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.
- checksums.yaml +4 -4
- data/README.md +331 -200
- data/bin/colours +2 -2
- data/bin/show_basic_colour_palette +7 -0
- data/colours.gemspec +1 -2
- data/doc/README.gen +294 -178
- data/doc/how_to_pick_your_own_colours/how_to_pick_your_own_colours.md +33 -0
- data/lib/colours/autoalias_e.rb +4 -1
- data/lib/colours/autogenerated/256_colours_instance_methods.rb +1429 -0
- data/lib/colours/autogenerated/256_colours_methods.rb +1429 -0
- data/lib/colours/autogenerated/html_colours_instance_methods.rb +1191 -0
- data/lib/colours/autogenerated/html_colours_methods.rb +1191 -0
- data/lib/colours/base/base.rb +61 -13
- data/lib/colours/class/colours.rb +8 -6
- data/lib/colours/{toplevel_methods/use_colours.rb → colour/colour.rb} +4 -125
- data/lib/colours/commandline/README.md +2 -1
- data/lib/colours/commandline/commandline.rb +177 -34
- data/lib/colours/constants/constants.rb +752 -6
- data/lib/colours/e/README.md +6 -6
- data/lib/colours/eparse/eparse.rb +2 -1
- data/lib/colours/essentials/README.md +5 -0
- data/lib/colours/{basic_colours/basic_colours.rb → essentials/essentials.rb} +87 -85
- data/lib/colours/html_colours/README.md +2 -1
- data/lib/colours/html_colours/hash_html_colours.rb +168 -0
- data/lib/colours/html_colours/html_colours.rb +226 -244
- data/lib/colours/html_colours/push_the_html_colours_methods_onto_the_toplevel_namespace.rb +30 -0
- data/lib/colours/html_colours/random_html_colour.rb +67 -0
- data/lib/colours/{requires/require_the_basic_colours.rb → html_colours.rb} +4 -2
- data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +12 -10
- data/lib/colours/module_256_colours/module_256_colours.rb +465 -0
- data/lib/colours/project/project.rb +3 -1
- data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +4 -0
- data/lib/colours/rainbow_colours/constants.rb +3 -3
- data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +9 -10
- data/lib/colours/rainbow_colours/print_rainbow_line.rb +4 -4
- data/lib/colours/rainbow_colours/println_ani.rb +7 -7
- data/lib/colours/rainbow_colours/println_plain.rb +2 -2
- data/lib/colours/rainbow_colours/rainbow.rb +31 -1
- data/lib/colours/rainbow_colours/report_errors.rb +7 -7
- data/lib/colours/rainbow_colours/returnln_plain.rb +3 -3
- data/lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb +409 -0
- data/lib/colours/requires/require_autogenerated_colour_methods.rb +4 -1
- data/lib/colours/requires/{require_the_colour_table.rb → require_essentials.rb} +2 -2
- data/lib/colours/requires/require_save_file.rb +11 -0
- data/lib/colours/requires/require_the_256_colours_module.rb +1 -3
- data/lib/colours/requires/require_the_colour_methods.rb +1 -22
- data/lib/colours/requires/require_the_project.rb +31 -29
- data/lib/colours/requires/require_the_toplevel_methods.rb +2 -20
- data/lib/colours/rgb/rgb.rb +107 -89
- data/lib/colours/{colour_methods/colour_methods.rb → sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb} +467 -405
- data/lib/colours/testing/testing.rb +1 -3
- data/lib/colours/toplevel_methods/e.rb +9 -13
- data/lib/colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb +57 -0
- data/lib/colours/toplevel_methods/{revert.rb → rev.rb} +5 -48
- data/lib/colours/toplevel_methods/toplevel_methods.rb +1204 -0
- data/lib/colours/version/version.rb +2 -2
- data/lib/colours/yaml/256_colours.yml +776 -257
- data/lib/colours/yaml/html_colours.yml +1 -1
- data/lib/colours/yaml/prefer_this_colour_schemata.yml +1 -1
- data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +5 -1
- data/lib/colours.rb +1 -1
- data/test/testing_256_colours_support.rb +10 -1
- data/test/testing_replace_number_words_with_the_corresponding_html_colour.rb +15 -9
- data/test/testing_the_colour_methods_such_as_simp_sdir_sfile_swarn_sfancy_sargument_and_ssymlink.rb +53 -0
- metadata +30 -57
- data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +0 -28
- data/lib/colours/256_colours/support_for_256_colours.rb +0 -196
- data/lib/colours/autogenerated/support_for_256_colours.rb +0 -2235
- data/lib/colours/autogenerated/support_for_html_colours.rb +0 -1778
- data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +0 -7001
- data/lib/colours/basic_colours/README.md +0 -4
- data/lib/colours/colour_methods/README.md +0 -11
- data/lib/colours/colour_table/README.md +0 -2
- data/lib/colours/colour_table/colour_table.rb +0 -282
- data/lib/colours/commandline/menu.rb +0 -122
- data/lib/colours/constants/escape.rb +0 -22
- data/lib/colours/constants/file_constants.rb +0 -73
- data/lib/colours/constants/hash_ansi_colours.rb +0 -39
- data/lib/colours/constants/hash_simple_colours.rb +0 -148
- data/lib/colours/constants/misc.rb +0 -361
- data/lib/colours/constants/newline.rb +0 -14
- data/lib/colours/constants/registered_colour_methods.rb +0 -53
- data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +0 -22
- data/lib/colours/toplevel_methods/autogenerate.rb +0 -310
- data/lib/colours/toplevel_methods/bold.rb +0 -41
- data/lib/colours/toplevel_methods/bold_and_italic.rb +0 -38
- data/lib/colours/toplevel_methods/cat.rb +0 -39
- data/lib/colours/toplevel_methods/clear_screen.rb +0 -18
- data/lib/colours/toplevel_methods/cliner.rb +0 -17
- data/lib/colours/toplevel_methods/col.rb +0 -54
- data/lib/colours/toplevel_methods/esystem.rb +0 -19
- data/lib/colours/toplevel_methods/html_colour_to_hex_value.rb +0 -41
- data/lib/colours/toplevel_methods/html_colourize.rb +0 -69
- data/lib/colours/toplevel_methods/is_on_roebe.rb +0 -16
- data/lib/colours/toplevel_methods/italic.rb +0 -110
- data/lib/colours/toplevel_methods/make_colour.rb +0 -28
- data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +0 -336
- data/lib/colours/toplevel_methods/misc.rb +0 -226
- data/lib/colours/toplevel_methods/open_this_file.rb +0 -26
- data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +0 -88
- data/lib/colours/toplevel_methods/random_value.rb +0 -37
- data/lib/colours/toplevel_methods/remove_escape_sequence.rb +0 -112
- data/lib/colours/toplevel_methods/set_last_colour_used.rb +0 -32
- data/lib/colours/toplevel_methods/shell_file_containing_the_html_colours.sh +0 -148
- data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +0 -36
- data/lib/colours/toplevel_methods/underline.rb +0 -130
- data/test/testing_the_colour_methods.rb +0 -36
- /data/doc/{COLOUR_CODES_CHART.md → colour_codes_chart/colour_codes_chart.md} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35cc5fe7d897ad1c870955b796a339e75827c322ecee636ed2f65a4b4c8c3711
|
|
4
|
+
data.tar.gz: 96552f6ac64de2c238009d96097381da0b37604b0a8cc69272b6fc283edd9548
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a8a4ee2eb2464e3a5da09656c73ba2194db8ddcd7f2d92681edd5426113446a1f23d73d6356dcf89ebfd58d671b9891c7e4073585995e9c7fa87b92890d9495
|
|
7
|
+
data.tar.gz: 69103940a21be3b6ff40f46e1ad07f0a110ab7c512b0552a734c036b2b3ffedde4624696aeb032ca615ff2442d8cf2088151ffd75779b80e54e399ecb6771e12
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://www.ruby-lang.org/en/)
|
|
3
3
|
[](https://badge.fury.io/rb/colours)
|
|
4
4
|
|
|
5
|
-
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">
|
|
5
|
+
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">04.12.2023</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">03:39:43</span> o'clock.
|
|
6
6
|
|
|
7
7
|
# The Colours project
|
|
8
8
|
|
|
@@ -10,52 +10,69 @@ Making colours great again! \o/
|
|
|
10
10
|
|
|
11
11
|
## Goals, Scope and the History of the colours project
|
|
12
12
|
|
|
13
|
-
The Colours project originated from a requirement to have to support
|
|
14
|
-
on the commandline
|
|
15
|
-
|
|
16
|
-
colours - just look at any random webpage; you may find lots of
|
|
17
|
-
different colours in use there.
|
|
13
|
+
The Colours project originated from a distinct requirement to have to support
|
|
14
|
+
<b>colours</b> on the commandline, such as for commandline-oriented
|
|
15
|
+
scripts.
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
Colours can be immensely helpful for use in computer programs, so it appears
|
|
18
|
+
to be a logical conclusion to make use of them on the commandline as well.
|
|
19
|
+
The modern www also makes use of colours - just look at any random webpage;
|
|
20
|
+
you may find lots of different colours in use there, for various reasons
|
|
21
|
+
and purposes.
|
|
22
|
+
|
|
23
|
+
If you do happen to take a look on different projects offered on <b>rubygems.org</b>
|
|
24
|
+
then you may be able to find **lots** of different colour-related projects, written
|
|
21
25
|
in ruby. The primary reason as to why I created a new colour-centric project
|
|
22
|
-
was because I needed certain functionality that was not provided by
|
|
23
|
-
the other projects; at the least not in a way as I thought it should be
|
|
24
|
-
available (and used in downstream projects).
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
was because I needed certain functionality made available that was not provided by
|
|
27
|
+
any of the other projects; at the least not in a way as I thought it should be
|
|
28
|
+
available (and used in downstream projects).
|
|
29
|
+
|
|
30
|
+
For example, some terminals support **RGB values** and other terminals do not.
|
|
31
|
+
I did not want to have to spend time thinking about this much at all, so I wanted
|
|
32
|
+
to have a <b>colours-related project</b> that could abstract this away for me.
|
|
33
|
+
That way I can focus on other problems, and delegate the colour-specific issues
|
|
34
|
+
to this gem here.
|
|
35
|
+
|
|
36
|
+
Let's next show how this may then look on the commandline:
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
[screenshot1]: https://i.imgur.com/F6kac8W.png
|
|
38
|
+
<img src="https://i.imgur.com/F6kac8W.png" style="margin: 1em">
|
|
31
39
|
|
|
32
|
-
The
|
|
40
|
+
The <b>main goal</b> of the **colours project** is to collect colour-related
|
|
33
41
|
code and make this code available to other projects, so that these projects
|
|
34
|
-
can benefit from colour support
|
|
42
|
+
can benefit from colour support via one project: the <b>colours gem</b>.
|
|
43
|
+
|
|
44
|
+
The primary goal herein lies on **commandline applications**, but there
|
|
45
|
+
are some <b>HTML components</b> as part of this project that could be used
|
|
46
|
+
as well, such as for when you wish to make use of **HTML colours** (slateblue,
|
|
47
|
+
royalblue, teal, tomato, steelblue and names such as these) in a webpage.
|
|
48
|
+
|
|
49
|
+
Elements such as:
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
are some HTML components as part of this project that could be used,
|
|
38
|
-
such as for when you wish to make use of **HTML colours** (slateblue,
|
|
39
|
-
royalblue, teal, tomato, steelblue and names such as these). The
|
|
40
|
-
partial screenshot above indicates this, on a black **KDE konsole**
|
|
41
|
-
background. (I tend to prefer dark backgrounds for my terminals.)
|
|
51
|
+
<span class="dodgerblue">This is in dodgerblue.</span>
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
The partial screenshot that was shown above indicates this situation, on a
|
|
54
|
+
black <b>KDE konsole</b> background. (I tend to prefer dark backgrounds
|
|
55
|
+
for my terminals.)
|
|
56
|
+
|
|
57
|
+
Note that many **terminals** support the <b>display of HTML colours</b>, via
|
|
44
58
|
their **corresponding RGB values**. Since I wanted to use good terminals,
|
|
45
59
|
such as the **KDE konsole**, the colours project also had to support
|
|
46
|
-
these names
|
|
47
|
-
why method calls such as
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
these names directly, as method calls as well - names such as <b>slateblue</b>
|
|
61
|
+
or <b>royalblue</b>). This is the reason why method calls such as
|
|
62
|
+
<b>Colours.royalblue()</b> or <b>Colours.darkgreen</b> will also work - see
|
|
63
|
+
for a later subsection how to customize (and control) this behaviour.
|
|
64
|
+
|
|
65
|
+
Historically the **Colours gem** was inspired by other, older projects, such
|
|
66
|
+
as <b>AnsiColours</b>, ColourE, AliasE and several other smaller sub-projects
|
|
67
|
+
that I have used over the years. These projects were eventually integrated
|
|
68
|
+
into one namespace - <b>module Colours</b>. This gem is thus a <b>bundled
|
|
69
|
+
project</b>. This is specifically mentioned in the event that you may wish
|
|
70
|
+
to peek at the code, and wonder a little why it is structured the way it
|
|
71
|
+
is.
|
|
55
72
|
|
|
56
73
|
## Requiring the colours project
|
|
57
74
|
|
|
58
|
-
To require the colours project, do:
|
|
75
|
+
To require the colours project, simply do:
|
|
59
76
|
|
|
60
77
|
require 'colours'
|
|
61
78
|
|
|
@@ -66,13 +83,144 @@ You can also **autoinclude** this module into your project, at
|
|
|
66
83
|
|
|
67
84
|
This will make the **Colours namespace** and the
|
|
68
85
|
**Colours::HtmlColours namespace** available, via
|
|
69
|
-
|
|
86
|
+
<b>include Colours</b> ultimately.
|
|
70
87
|
|
|
71
88
|
If you need more control over the include-action then you should
|
|
72
89
|
just use the first variant, require 'colours', and then do the
|
|
73
90
|
include action specifically onto whatever class/module you need
|
|
74
91
|
that functionality.
|
|
75
92
|
|
|
93
|
+
The project was partially rewritten in November 2023. If you
|
|
94
|
+
want to autoinclude the project still then I recommend you
|
|
95
|
+
use this:
|
|
96
|
+
|
|
97
|
+
require 'colours/html_colours'
|
|
98
|
+
|
|
99
|
+
After that methods such as <b>Colours.steelblue()</b> will
|
|
100
|
+
work.
|
|
101
|
+
|
|
102
|
+
## ASCII Escape Characters
|
|
103
|
+
|
|
104
|
+
The code in the colours gem makes use of elements such as \033 or
|
|
105
|
+
\x1b. These are basically the same ASCII escape characters, as the
|
|
106
|
+
following table shows:
|
|
107
|
+
|
|
108
|
+
|-------------|------------|
|
|
109
|
+
| octal | \033 |
|
|
110
|
+
|-------------|------------|
|
|
111
|
+
| hexadecimal | \x1b |
|
|
112
|
+
|-------------|------------|
|
|
113
|
+
| Unicode | \u1b, \U1b |
|
|
114
|
+
|-------------|------------|
|
|
115
|
+
| literal | \e, \E |
|
|
116
|
+
|-------------|------------|
|
|
117
|
+
|
|
118
|
+
The last variant can often be found in <b>Bash scripts</b>.
|
|
119
|
+
|
|
120
|
+
The semicolon <b>;</b> serves as the delimiter if multiple instructions
|
|
121
|
+
are given.
|
|
122
|
+
|
|
123
|
+
The 8 actual colours defined by the ANSI standard are as follows:
|
|
124
|
+
|
|
125
|
+
0 black
|
|
126
|
+
1 red
|
|
127
|
+
2 green
|
|
128
|
+
3 yellow
|
|
129
|
+
4 blue
|
|
130
|
+
5 magenta
|
|
131
|
+
6 cyan
|
|
132
|
+
7 white
|
|
133
|
+
|
|
134
|
+
## Linux terminals and colour support
|
|
135
|
+
|
|
136
|
+
The general syntax rules for colours is in the form of <b>fg_bg</b> values,
|
|
137
|
+
where a value of <b>38</b> stands for the foreground, and <b>48</b> stands
|
|
138
|
+
for the background.
|
|
139
|
+
|
|
140
|
+
For instance, the ANSI colour for red is 196 and the ANSI colour for
|
|
141
|
+
black is 0.
|
|
142
|
+
|
|
143
|
+
To use the colour red, you could issue this command in Bash:
|
|
144
|
+
|
|
145
|
+
printf "\e[38;5;196m Hello world in red\n"
|
|
146
|
+
|
|
147
|
+
To use the colour black as background, you could issue this command:
|
|
148
|
+
|
|
149
|
+
printf "\e[48;5;0m Hello world in black\n"
|
|
150
|
+
|
|
151
|
+
Do note that the same can be accomplished via RGB values rather than
|
|
152
|
+
ANSI color codes, as long as the terminal supports this (KDE Konsole
|
|
153
|
+
does).
|
|
154
|
+
|
|
155
|
+
Depending on whether you want to apply the colour to the foreground
|
|
156
|
+
or to the background, use an **fg_bg** value of <b>38</b> or <b>48</b>
|
|
157
|
+
(respectively).
|
|
158
|
+
|
|
159
|
+
Examples for this:
|
|
160
|
+
|
|
161
|
+
# printf "\e[<fg_bg>;2;<R>;<G>;<B>m" # General syntax example.
|
|
162
|
+
printf "\e[38;2;255;0;0m Foreground color: red\n"
|
|
163
|
+
printf "\e[48;2;0;0;0m Background color: black\n"
|
|
164
|
+
printf "\033[91m\033[107mThis is red text on a white background\033[0m" # As this example shows, \e is the same as \033.
|
|
165
|
+
|
|
166
|
+
This may be the better variant altogether, as it is quite easy to convert
|
|
167
|
+
into (and from) **RGB values**, but your mileage may vary.
|
|
168
|
+
|
|
169
|
+
Of course you can use this in plain ruby just as well - let's show this
|
|
170
|
+
via puts:
|
|
171
|
+
|
|
172
|
+
puts "\e[38;2;#{222};#{131};#{141}m Hello world!"
|
|
173
|
+
puts "\e[38;2;#{122};#{56};#{141}m Hello world!"
|
|
174
|
+
puts "\e[38;2;122;156;141m Hello world!"
|
|
175
|
+
puts "\x1b[3mHello world!\x1b[0m"
|
|
176
|
+
puts "\e[38;3mHello world!\x1b[0m"
|
|
177
|
+
|
|
178
|
+
In bash the ESC code can be either of the following:
|
|
179
|
+
|
|
180
|
+
\e
|
|
181
|
+
\033 (octal)
|
|
182
|
+
\x1B (hexadecimal)
|
|
183
|
+
|
|
184
|
+
The "\e[0m" sequence removes all attributes, including formatting and colors.
|
|
185
|
+
It may be useful to add it to the end of each colour text - and this is
|
|
186
|
+
what the **Colours** project is essentially doing.
|
|
187
|
+
|
|
188
|
+
To see which colours are supported/supportable, for each terminal,
|
|
189
|
+
have a look at the following **link**:
|
|
190
|
+
|
|
191
|
+
https://misc.flogisoft.com/bash/tip_colors_and_formatting#terminals_compatibility
|
|
192
|
+
|
|
193
|
+
To set both the foreground and background colours at once, you can use:
|
|
194
|
+
|
|
195
|
+
printf "\e[S;FG;BGm"
|
|
196
|
+
echo -e "\e[S;FG;BGm"
|
|
197
|
+
|
|
198
|
+
For example, bold white foreground on a red background:
|
|
199
|
+
|
|
200
|
+
printf "\e[1;97;41mHello world!"
|
|
201
|
+
printf "\e[1;97;41mHello world!\n"
|
|
202
|
+
|
|
203
|
+
Thus, if you would like to use red colour on black background,
|
|
204
|
+
you could do this:
|
|
205
|
+
|
|
206
|
+
printf '\e[38;5;196m;\e[48;5;0m Hello world!\n'
|
|
207
|
+
|
|
208
|
+
Specifically, the background colours are:
|
|
209
|
+
|
|
210
|
+
40 black
|
|
211
|
+
41 red
|
|
212
|
+
42 green
|
|
213
|
+
43 yellow
|
|
214
|
+
44 blue
|
|
215
|
+
45 magenta
|
|
216
|
+
46 cyan
|
|
217
|
+
47 white
|
|
218
|
+
|
|
219
|
+
The following command will use red background:
|
|
220
|
+
|
|
221
|
+
echo -e '\e[0;41m'
|
|
222
|
+
echo -e '\e[0;41m hello world\n\n ok\e[0;m'
|
|
223
|
+
|
|
76
224
|
## Introduction and Overview
|
|
77
225
|
|
|
78
226
|
The toplevel module name is **Colours** and you can include
|
|
@@ -165,93 +313,17 @@ my opinion.
|
|
|
165
313
|
In general, the html component can be used to convert the trivial
|
|
166
314
|
<b>html colours</b> into <b>corresponding R,G,B values</b>.
|
|
167
315
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
The general syntax rules for colours is in the form of **fg_bg** values,
|
|
171
|
-
where a value of 38 stands for the foreground, and 48 stands for
|
|
172
|
-
the background.
|
|
173
|
-
|
|
174
|
-
The ANSI colour for red is 196 and the ANSI colour for black is
|
|
175
|
-
0.
|
|
176
|
-
|
|
177
|
-
To use the colour red, you could issue this command:
|
|
178
|
-
|
|
179
|
-
printf "\e[38;5;196m Hello world in red\n"
|
|
180
|
-
|
|
181
|
-
To use the colour black as background, you could issue this command:
|
|
182
|
-
|
|
183
|
-
printf "\e[48;5;0m Hello world in black\n"
|
|
184
|
-
|
|
185
|
-
Do note that the same can be accomplished via RGB values rather than
|
|
186
|
-
ANSI color codes, as long as the terminal supports this (KDE Konsole
|
|
187
|
-
does).
|
|
188
|
-
|
|
189
|
-
Depending on whether you want to apply the color to the foreground or
|
|
190
|
-
to the background, use an **fg_bg** value of 38 or 48 (respectively).
|
|
191
|
-
|
|
192
|
-
Example:
|
|
193
|
-
|
|
194
|
-
printf "\e[<fg_bg>;2;<R>;<G>;<B>m"
|
|
195
|
-
printf "\e[38;2;255;0;0m Foreground color: red\n"
|
|
196
|
-
printf "\e[48;2;0;0;0m Background color: black\n"
|
|
197
|
-
|
|
198
|
-
This may be the better variant altogether, as it is quite easy to convert
|
|
199
|
-
into (and from) **RGB values**, but your mileage may vary.
|
|
200
|
-
|
|
201
|
-
Of course you can use this in plain ruby just as well - let's show this
|
|
202
|
-
via puts:
|
|
203
|
-
|
|
204
|
-
puts "\e[38;2;#{222};#{131};#{141}m Hello world!"
|
|
205
|
-
puts "\e[38;2;#{122};#{56};#{141}m Hello world!"
|
|
206
|
-
puts "\e[38;2;122;156;141m Hello world!"
|
|
207
|
-
puts "\x1b[3mHello world!\x1b[0m"
|
|
208
|
-
puts "\e[38;3mHello world!\x1b[0m"
|
|
209
|
-
|
|
210
|
-
In bash the ESC code can be either of the following:
|
|
211
|
-
|
|
212
|
-
\e
|
|
213
|
-
\033 (octal)
|
|
214
|
-
\x1B (hexadecimal)
|
|
316
|
+
Note that in November 2023 I rewrote parts of the gem. This also
|
|
317
|
+
led to a re-evaluation of methods such as sdir() or sfancy().
|
|
215
318
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
To set both the foreground and background colours at once, you can use:
|
|
226
|
-
|
|
227
|
-
printf "\e[S;FG;BGm"
|
|
228
|
-
echo -e "\e[S;FG;BGm"
|
|
229
|
-
|
|
230
|
-
For example, bold white foreground on a red background:
|
|
231
|
-
|
|
232
|
-
printf "\e[1;97;41mHello world!"
|
|
233
|
-
printf "\e[1;97;41mHello world!\n"
|
|
234
|
-
|
|
235
|
-
Thus, if you would like to use red colour on black background,
|
|
236
|
-
you could do this:
|
|
237
|
-
|
|
238
|
-
printf '\e[38;5;196m;\e[48;5;0m Hello world!\n'
|
|
239
|
-
|
|
240
|
-
Specifically, the background colours are:
|
|
241
|
-
|
|
242
|
-
40 black
|
|
243
|
-
41 red
|
|
244
|
-
42 green
|
|
245
|
-
43 yellow
|
|
246
|
-
44 blue
|
|
247
|
-
45 magenta
|
|
248
|
-
46 cyan
|
|
249
|
-
47 white
|
|
250
|
-
|
|
251
|
-
The following command will use red background:
|
|
252
|
-
|
|
253
|
-
echo -e '\e[0;41m'
|
|
254
|
-
echo -e '\e[0;41m hello world\n\n ok\e[0;m'
|
|
319
|
+
I use sfile(), sdir() and sfancy() a lot. I also use simp(),
|
|
320
|
+
as abbreviation for simportant(), sometimes. However had, other
|
|
321
|
+
methods, such as ssymlink(), I rarely use; and I never used
|
|
322
|
+
sarguments(), yet the project still carried code that supported
|
|
323
|
+
such a use case. During the partial rewrite in November 2023
|
|
324
|
+
I decided to deprecate and remove sarguments() aka Colours.sarguments().
|
|
325
|
+
I also deprecated snormal(), aka Colours.snormal(), as I also have
|
|
326
|
+
not ever used that method actually.
|
|
255
327
|
|
|
256
328
|
## Obtain all available HTML colours
|
|
257
329
|
|
|
@@ -351,45 +423,6 @@ Use code similar to the following variant for this:
|
|
|
351
423
|
class Foobar < Colours::Base # Or whatever the name of your class is
|
|
352
424
|
end
|
|
353
425
|
|
|
354
|
-
## KDE Konsole support
|
|
355
|
-
|
|
356
|
-
The **Colours gem** used to have a submodule called **Konsole**,
|
|
357
|
-
in particular the <b>KDE Konsole</b>. In May 2019 this submodule
|
|
358
|
-
was removed; the functionality is now available in the form of
|
|
359
|
-
an autogenerated .rb file instead.
|
|
360
|
-
|
|
361
|
-
You can **use RGB colours** in the KDE konsole (but also in
|
|
362
|
-
other terminal-types such as vte-based ones, like
|
|
363
|
-
**mate-terminal**).
|
|
364
|
-
|
|
365
|
-
For an example, have a look at the file **bin/colours**
|
|
366
|
-
that is distributed with this gem here (the colours gem). That file
|
|
367
|
-
will output all the HTML colour variants (via their RGB values).
|
|
368
|
-
Best shown on a black background in your terminal.
|
|
369
|
-
|
|
370
|
-
To **view all RGB colours** based on their HTML names, such
|
|
371
|
-
as <b>palegreen</b> or <b>slateblue</b>, do this:
|
|
372
|
-
|
|
373
|
-
colours
|
|
374
|
-
|
|
375
|
-
Also note that since as of **May 2018**, you can invoke the
|
|
376
|
-
HTML colours on the Konsole namespace directly, including
|
|
377
|
-
text-output, via code like this:
|
|
378
|
-
|
|
379
|
-
Colours.edarkgreen 'yo there'
|
|
380
|
-
Colours.eslateblue 'yo there'
|
|
381
|
-
Colours.eroyalblue 'yo there'
|
|
382
|
-
Colours.edarkgreen 'Hello world!'
|
|
383
|
-
|
|
384
|
-
The leading 'e' of these methods stands for "echo", aka
|
|
385
|
-
puts-related output. In other words, to print the text
|
|
386
|
-
that comes afterwards.
|
|
387
|
-
|
|
388
|
-
To print something in bold, you can use **Colours.bold()**
|
|
389
|
-
like in this way:
|
|
390
|
-
|
|
391
|
-
Colours.bold
|
|
392
|
-
|
|
393
426
|
## Showing the colour palette on the commandline
|
|
394
427
|
|
|
395
428
|
You can show the "classical" ASCII colours on the commandline by
|
|
@@ -605,11 +638,11 @@ then you can require the module, and include it into your class.
|
|
|
605
638
|
|
|
606
639
|
Example for this:
|
|
607
640
|
|
|
608
|
-
require '
|
|
641
|
+
require 'colours/autogenerated/support_for_256_colours.rb'
|
|
609
642
|
|
|
610
643
|
class Foobar
|
|
611
644
|
|
|
612
|
-
include
|
|
645
|
+
include Colours::SupportFor256Colours
|
|
613
646
|
|
|
614
647
|
def initialize
|
|
615
648
|
puts darkturquoise('HELLO ')+
|
|
@@ -1037,28 +1070,28 @@ Here is example code that shows this functionality:
|
|
|
1037
1070
|
|
|
1038
1071
|
## Colours.new
|
|
1039
1072
|
|
|
1040
|
-
Since as of November 2022 <b>Colours.new</b> can be used
|
|
1041
|
-
build up a String that should be colourized.
|
|
1073
|
+
Since as of <b>November 2022</b>, <b>Colours.new</b> can be used
|
|
1074
|
+
to build up a String that should be colourized.
|
|
1042
1075
|
|
|
1043
1076
|
This will internally delegate towards:
|
|
1044
1077
|
|
|
1045
1078
|
::Colours::Colours.new(i)
|
|
1046
1079
|
|
|
1047
|
-
This may need some modifications in the future; the code is
|
|
1048
|
-
|
|
1080
|
+
This may need some modifications in the future; the code is also
|
|
1081
|
+
a bit confusing right now.
|
|
1049
1082
|
|
|
1050
1083
|
## Licence
|
|
1051
1084
|
|
|
1052
1085
|
The colours project used to be under the **GPL-2.0 licence** (no later clause),
|
|
1053
|
-
until **August 2019** (**26.08.2019**, in dd.mm.yyyy notation).
|
|
1086
|
+
until **August 2019** (**26.08.2019**, in <b>dd.mm.yyyy notation</b>).
|
|
1054
1087
|
|
|
1055
1088
|
However had, I have changed my mind for various reasons (including the
|
|
1056
1089
|
situation that different projects, with different licenses, may make
|
|
1057
1090
|
use of the **colours gem**) and thus re-published the colours
|
|
1058
1091
|
project under the less stringent **MIT licence**. Both licences, GPL and
|
|
1059
|
-
MIT, are perfectly fine licences, but I feel that for the basic building
|
|
1060
|
-
blocks
|
|
1061
|
-
more sense.
|
|
1092
|
+
MIT, are perfectly fine licences, but I feel that for the <b>basic building
|
|
1093
|
+
blocks</b>, such as the colours gem, a less stringent licence makes a
|
|
1094
|
+
lot more sense.
|
|
1062
1095
|
|
|
1063
1096
|
See the file **LICENCE.md** for this licence, or just have look at
|
|
1064
1097
|
the following URL here:
|
|
@@ -1085,12 +1118,14 @@ on something IF the no-warranty clause would not be mentioned).
|
|
|
1085
1118
|
https://ss64.com/nt/syntax-ansi.html
|
|
1086
1119
|
|
|
1087
1120
|
https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
|
|
1088
|
-
|
|
1089
|
-
|
|
1121
|
+
|
|
1122
|
+
^^^ This webpage one shows how to build a progress-indicator in python. The
|
|
1123
|
+
equivalent ruby code is very similar.
|
|
1090
1124
|
|
|
1091
1125
|
## Commandline executables for individual colours
|
|
1092
1126
|
|
|
1093
|
-
In March 2023 I decided to add files such as
|
|
1127
|
+
In <b>March 2023</b> I decided to add files such as
|
|
1128
|
+
<b>bin/orange</b>.
|
|
1094
1129
|
|
|
1095
1130
|
The idea here is that you can chain this via a pipe, such as:
|
|
1096
1131
|
|
|
@@ -1101,13 +1136,94 @@ Or simply:
|
|
|
1101
1136
|
orange Hello world!
|
|
1102
1137
|
orange foobar.md # This variant should read the file, and read its content.
|
|
1103
1138
|
|
|
1104
|
-
|
|
1105
|
-
certain whether this should be done
|
|
1106
|
-
|
|
1107
|
-
|
|
1139
|
+
The idea here is to add this for each HTML colour. However had, I am not yet
|
|
1140
|
+
certain whether this should be done, as it would lead to many more files
|
|
1141
|
+
added to the colours gem. So for now, I may add single individual files
|
|
1142
|
+
but probably not all HTML colours, as executables. Perhaps in the future
|
|
1143
|
+
all HTML colours will have a corresponding bin/ executable file or I may
|
|
1144
|
+
add the option to autogenerate these files - we'll see.
|
|
1108
1145
|
|
|
1146
|
+
## KDE Konsole support
|
|
1109
1147
|
|
|
1110
|
-
|
|
1148
|
+
The **Colours gem** used to have a submodule called **Konsole**,
|
|
1149
|
+
in particular the <b>KDE Konsole</b>. In <b>May 2019</b> this submodule
|
|
1150
|
+
was removed; the functionality is now available in the form of
|
|
1151
|
+
an autogenerated .rb file instead.
|
|
1152
|
+
|
|
1153
|
+
You can **use RGB colours** in the KDE konsole (but also in
|
|
1154
|
+
other terminal-types such as vte-based ones, like
|
|
1155
|
+
<b>mate-terminal</b>). gnome-terminal also supports true
|
|
1156
|
+
24 bit colours, which means that 16 millions colours are supported.
|
|
1157
|
+
|
|
1158
|
+
For an example, have a look at the file **bin/colours**
|
|
1159
|
+
that is distributed with this gem here (the colours gem). That file
|
|
1160
|
+
will output all the HTML colour variants (via their RGB values).
|
|
1161
|
+
Best shown on a black background in your terminal though.
|
|
1162
|
+
|
|
1163
|
+
To **view all RGB colours** based on their HTML names, such
|
|
1164
|
+
as <b>palegreen</b> or <b>slateblue</b>, do this:
|
|
1165
|
+
|
|
1166
|
+
colours
|
|
1167
|
+
|
|
1168
|
+
Also note that since as of **May 2018**, you can invoke the
|
|
1169
|
+
HTML colours on the Konsole namespace directly, including
|
|
1170
|
+
text-output, via <b>code like this</b>:
|
|
1171
|
+
|
|
1172
|
+
Colours.edarkgreen 'yo there'
|
|
1173
|
+
Colours.eslateblue 'yo there'
|
|
1174
|
+
Colours.eroyalblue 'yo there'
|
|
1175
|
+
Colours.edarkgreen 'Hello world!'
|
|
1176
|
+
|
|
1177
|
+
The leading 'e' of these methods stands for "echo", aka
|
|
1178
|
+
<b>puts-related output</b> (display onto the commandline).
|
|
1179
|
+
In other words, <b>to print the text that comes afterwards</b>.
|
|
1180
|
+
|
|
1181
|
+
To print something in bold, you can use **Colours.bold()**
|
|
1182
|
+
like in this way:
|
|
1183
|
+
|
|
1184
|
+
Colours.bold
|
|
1185
|
+
|
|
1186
|
+
How to use this in raw KDE konsole, if ruby is not available?
|
|
1187
|
+
|
|
1188
|
+
You need to make use of the corresponding R, G and B
|
|
1189
|
+
values.
|
|
1190
|
+
|
|
1191
|
+
Example for this:
|
|
1192
|
+
|
|
1193
|
+
printf "\e[38;2;100;200;200mTesting this output\e[0m\n"
|
|
1194
|
+
|
|
1195
|
+
## class Colours::ReplaceTokensWithColourCode
|
|
1196
|
+
|
|
1197
|
+
class Colours::ReplaceTokensWithColourCode can be used to
|
|
1198
|
+
replace HTML-like tokens, such as <one>, in a given String.
|
|
1199
|
+
|
|
1200
|
+
The use case for this is to be able to easily colourize
|
|
1201
|
+
words on the commandline, as well as sentences, in different
|
|
1202
|
+
colours. The studium-gem makes use of this, for instance,
|
|
1203
|
+
where exam-questions are colourized based on the more important
|
|
1204
|
+
parts of the question at hand.
|
|
1205
|
+
|
|
1206
|
+
## Colours::HtmlColoursMethods
|
|
1207
|
+
|
|
1208
|
+
class Colours::HtmlColoursMethods will hold code for making
|
|
1209
|
+
use of HTML-colours as method names, such as:
|
|
1210
|
+
|
|
1211
|
+
Colours.royalblue()
|
|
1212
|
+
Colours.royalblue('Hello World!')
|
|
1213
|
+
|
|
1214
|
+
To require this file do:
|
|
1215
|
+
|
|
1216
|
+
require 'colours/autogenerated/html_colours_methods.rb'
|
|
1217
|
+
|
|
1218
|
+
Note that depending on how you require the colours gem,
|
|
1219
|
+
this may also be automatically pulled in if you do:
|
|
1220
|
+
|
|
1221
|
+
include Colours
|
|
1222
|
+
|
|
1223
|
+
And then use methods such as Colours.sfancy().
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
## Contact information and mandatory 2FA (no longer) coming up in 2022 / 2023
|
|
1111
1227
|
|
|
1112
1228
|
If your creative mind has ideas and specific suggestions to make this gem
|
|
1113
1229
|
more useful in general, feel free to drop me an email at any time, via:
|
|
@@ -1117,36 +1233,51 @@ more useful in general, feel free to drop me an email at any time, via:
|
|
|
1117
1233
|
Before that email I used an email account at Google gmail, but in **2021** I
|
|
1118
1234
|
decided to slowly abandon gmail, for various reasons. In order to limit the
|
|
1119
1235
|
explanation here, allow me to just briefly state that I do not feel as if I
|
|
1120
|
-
want to promote any Google service anymore when the user becomes the
|
|
1121
|
-
product (such as via data collection by upstream services
|
|
1122
|
-
a hugely flawed business model
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
In
|
|
1128
|
-
|
|
1129
|
-
|
|
1236
|
+
want to promote any Google service anymore when the user becomes the end
|
|
1237
|
+
product (such as via data collection by upstream services, including other
|
|
1238
|
+
proxy-services). My feeling is that this is a hugely flawed business model
|
|
1239
|
+
to begin with, and I no longer wish to support this in any way, even if
|
|
1240
|
+
only indirectly so, such as by using services of companies that try to
|
|
1241
|
+
promote this flawed model.
|
|
1242
|
+
|
|
1243
|
+
In regards to responding to emails: please keep in mind that responding
|
|
1244
|
+
may take some time, depending on the amount of work I may have at that
|
|
1245
|
+
moment. So it is not that emails are ignored; it is more that I have not
|
|
1246
|
+
(yet) found the time to read and reply. This means there may be a delay
|
|
1247
|
+
of days, weeks and in some instances also months. There is, unfortunately,
|
|
1248
|
+
not much I can do when I need to prioritise my time investment, but I try
|
|
1249
|
+
to consider <b>all</b> feedback as an opportunity to improve my projects
|
|
1250
|
+
nonetheless.
|
|
1251
|
+
|
|
1252
|
+
In <b>2022</b> rubygems.org decided to make 2FA mandatory for every
|
|
1253
|
+
gem owner eventually:
|
|
1254
|
+
|
|
1255
|
+
see
|
|
1130
1256
|
https://blog.rubygems.org/2022/06/13/making-packages-more-secure.html
|
|
1131
1257
|
|
|
1132
1258
|
Mandatory 2FA will eventually be extended to all rubygems.org developers and
|
|
1133
1259
|
maintainers. As I can not use 2FA, for reasons I will skip explaining here,
|
|
1134
|
-
this means that my projects will eventually be
|
|
1135
|
-
|
|
1260
|
+
this means that my projects will eventually be removed, as I no longer
|
|
1261
|
+
have any control over my projects hosted on rubygems.org (because I
|
|
1262
|
+
can not use 2FA).
|
|
1263
|
+
|
|
1136
1264
|
At that point, I no longer have any control what is done to my projects
|
|
1137
|
-
since
|
|
1138
|
-
|
|
1139
|
-
that was not the case several years ago
|
|
1265
|
+
since whoever is controlling the gems ecosystem took away our control
|
|
1266
|
+
here. I am not sure at which point ruby became corporate-controlled -
|
|
1267
|
+
that was not the case several years ago, so something has
|
|
1268
|
+
changed.
|
|
1140
1269
|
|
|
1141
1270
|
Ruby also only allows 2FA users to participate on the issue tracker these
|
|
1142
1271
|
days:
|
|
1143
1272
|
|
|
1144
1273
|
https://bugs.ruby-lang.org/issues/18800
|
|
1145
1274
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1275
|
+
But this has been reverted some months ago, so it is no longer applicable.
|
|
1276
|
+
Suffice to say that I do not think that we should only be allowed to
|
|
1277
|
+
interact on the world wide web when some 'authority' authenticated us,
|
|
1278
|
+
such as via mandatory 2FA, so I hope this won't come back again.
|
|
1279
|
+
|
|
1280
|
+
Fighting spam is a noble goal, but when it also means you lock out
|
|
1281
|
+
real human people then this is definitely NOT a good situation
|
|
1282
|
+
to be had.
|
|
1152
1283
|
|