colours 0.8.12
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 +7 -0
- data/LICENCE.md +22 -0
- data/README.md +1152 -0
- data/bin/colours +7 -0
- data/bin/egreen +7 -0
- data/bin/fancy_parse +7 -0
- data/bin/html_colour_to_hex_value +7 -0
- data/bin/html_colourize +7 -0
- data/bin/orange +7 -0
- data/bin/print_rainbow_line +7 -0
- data/bin/rainbow_colours +7 -0
- data/bin/remove_ansii_escape_sequences +7 -0
- data/bin/steelblue +7 -0
- data/colours.gemspec +74 -0
- data/doc/COLOUR_CODES_CHART.md +27 -0
- data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +28 -0
- data/doc/README.gen +1105 -0
- data/doc/todo/todo.md +25 -0
- data/lib/colours/256_colours/support_for_256_colours.rb +196 -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 +7001 -0
- data/lib/colours/autoinclude.rb +14 -0
- data/lib/colours/base/base.rb +29 -0
- data/lib/colours/basic_colours/README.md +4 -0
- data/lib/colours/basic_colours/basic_colours.rb +334 -0
- data/lib/colours/class/colours.rb +537 -0
- data/lib/colours/colour_methods/README.md +11 -0
- data/lib/colours/colour_methods/colour_methods.rb +685 -0
- data/lib/colours/colour_table/README.md +2 -0
- data/lib/colours/colour_table/colour_table.rb +282 -0
- data/lib/colours/colours_e_autoinclude.rb +9 -0
- data/lib/colours/commandline/README.md +2 -0
- data/lib/colours/commandline/commandline.rb +58 -0
- data/lib/colours/commandline/menu.rb +122 -0
- data/lib/colours/constants/constants.rb +9 -0
- data/lib/colours/constants/escape.rb +22 -0
- data/lib/colours/constants/file_constants.rb +73 -0
- data/lib/colours/constants/hash_ansi_colours.rb +39 -0
- data/lib/colours/constants/hash_simple_colours.rb +148 -0
- data/lib/colours/constants/misc.rb +361 -0
- data/lib/colours/constants/newline.rb +14 -0
- data/lib/colours/constants/registered_colour_methods.rb +53 -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/e.rb +5 -0
- data/lib/colours/eparse/eparse.rb +114 -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/html_colours.rb +424 -0
- data/lib/colours/kde_colour_palette/kde_colour_palette.rb +132 -0
- data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +224 -0
- data/lib/colours/module.rb +11 -0
- data/lib/colours/project/project.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_autogenerated_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_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_constants.rb +5 -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_project.rb +53 -0
- data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
- data/lib/colours/requires/require_yaml.rb +9 -0
- data/lib/colours/rgb/rgb.rb +550 -0
- data/lib/colours/testing/README.md +2 -0
- data/lib/colours/testing/testing.rb +168 -0
- data/lib/colours/toplevel_methods/autogenerate.rb +310 -0
- data/lib/colours/toplevel_methods/bold.rb +41 -0
- data/lib/colours/toplevel_methods/bold_and_italic.rb +38 -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 +17 -0
- data/lib/colours/toplevel_methods/col.rb +54 -0
- data/lib/colours/toplevel_methods/e.rb +69 -0
- data/lib/colours/toplevel_methods/esystem.rb +19 -0
- data/lib/colours/toplevel_methods/html_colour_to_hex_value.rb +41 -0
- data/lib/colours/toplevel_methods/html_colourize.rb +69 -0
- data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/colours/toplevel_methods/italic.rb +110 -0
- data/lib/colours/toplevel_methods/make_colour.rb +28 -0
- data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +336 -0
- data/lib/colours/toplevel_methods/misc.rb +226 -0
- data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
- data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +88 -0
- data/lib/colours/toplevel_methods/random_value.rb +37 -0
- data/lib/colours/toplevel_methods/remove_escape_sequence.rb +112 -0
- data/lib/colours/toplevel_methods/revert.rb +104 -0
- data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
- data/lib/colours/toplevel_methods/shell_file_containing_the_html_colours.sh +148 -0
- data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
- data/lib/colours/toplevel_methods/underline.rb +130 -0
- data/lib/colours/toplevel_methods/use_colours.rb +290 -0
- data/lib/colours/version/version.rb +25 -0
- data/lib/colours/yaml/256_colours.yml +279 -0
- data/lib/colours/yaml/basic_colours.yml +25 -0
- data/lib/colours/yaml/html_colours.yml +837 -0
- data/lib/colours/yaml/kde_colour_palette.yml +183 -0
- data/lib/colours/yaml/prefer_this_colour_schemata.yml +17 -0
- data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +15 -0
- data/lib/colours.rb +1 -0
- data/test/test.html +18 -0
- data/test/testing_256_colours_support.rb +29 -0
- data/test/testing_bold_italic_underline.rb +26 -0
- data/test/testing_class_colours.rb +46 -0
- data/test/testing_col.rb +10 -0
- data/test/testing_colours.rb +96 -0
- data/test/testing_colours_e.rb +13 -0
- data/test/testing_eparse.rb +13 -0
- data/test/testing_italic.rb +28 -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_replace_number_words_with_the_corresponding_html_colour.rb +39 -0
- data/test/testing_rgb_to_hex.rb +32 -0
- data/test/testing_the_basic_colours_of_the_colours_project.rb +62 -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_ecomment_method.rb +11 -0
- data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
- data/test/testing_the_regex_for_capturing_the_commandline_coloured_content.rb +112 -0
- data/test/testing_whether_colours_will_be_used.rb +7 -0
- metadata +225 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# This file will hold code that relates to the html-colours, such as
|
|
6
|
+
# "steelblue" or "royalblue" and so forth.
|
|
7
|
+
# =========================================================================== #
|
|
8
|
+
# require 'colours/toplevel_methods/methods_related_to_html_colours.rb'
|
|
9
|
+
# Colours.html_colour_to_hex_value(ARGV)
|
|
10
|
+
# =========================================================================== #
|
|
11
|
+
module Colours
|
|
12
|
+
|
|
13
|
+
require 'colours/html_colours/html_colours.rb'
|
|
14
|
+
require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
|
|
15
|
+
|
|
16
|
+
# ========================================================================= #
|
|
17
|
+
# === REGEX_FOR_HTML_COLOURS
|
|
18
|
+
#
|
|
19
|
+
# This regex supports the use case where we can match against HTML
|
|
20
|
+
# colours. (The name is a bit of a misnomer, though.)
|
|
21
|
+
#
|
|
22
|
+
# For the following regex, see this entry at rubular:
|
|
23
|
+
#
|
|
24
|
+
# https://rubular.com/r/o5r4DneMTGOsbX
|
|
25
|
+
#
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
REGEX_FOR_HTML_COLOURS =
|
|
28
|
+
/<([()a-zA-Z0-9²→\n]+?)>/
|
|
29
|
+
|
|
30
|
+
# ========================================================================= #
|
|
31
|
+
# === USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
|
|
32
|
+
#
|
|
33
|
+
# Here we specify the default colour to be used, in order to revert
|
|
34
|
+
# to the prior colour in use. This can be modified by the user,
|
|
35
|
+
# in order to conform to other colours if said user wishes to
|
|
36
|
+
# do so.
|
|
37
|
+
# ========================================================================= #
|
|
38
|
+
USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR = :grey
|
|
39
|
+
|
|
40
|
+
# ========================================================================= #
|
|
41
|
+
# === Colours.return_main_regex_to_use_for_obtaining_the_full_content
|
|
42
|
+
#
|
|
43
|
+
# The first regex that is commented out, in the body of this method,
|
|
44
|
+
# was in use until May 2023. It was then replaced with the new
|
|
45
|
+
# regex, which also has an associated test-case, in the test/
|
|
46
|
+
# subdirectory of the colours gem.
|
|
47
|
+
#
|
|
48
|
+
# For the current regex see here:
|
|
49
|
+
#
|
|
50
|
+
# https://rubular.com/r/1dpSmYqQ9SVvMt
|
|
51
|
+
#
|
|
52
|
+
# I was also using a second regex that was slightly incompatible.
|
|
53
|
+
# For legacy reasons it can be seen here: https://rubular.com/r/sDNQd81MtciMJL
|
|
54
|
+
# ========================================================================= #
|
|
55
|
+
def self.return_main_regex_to_use_for_obtaining_the_full_content(this_colour)
|
|
56
|
+
# /<#{this_colour}>([\-\{\}\[\]\\\(\)\/a-zA-Z0-9’éúÄäÖöÜüÅαβß&%+−=≡πμ°₁₂₃₄₅₆₇₈₉⁰¹²³⁴⁵⁶⁷⁸⁹⁻!#\*~:;∨"',_\|\n\. ]+)<\/#{this_colour}>/
|
|
57
|
+
# /<#{this_numbered_word}>([-#~≥!\e=><;,→⁻⁺@^„“γαµ_₀₁₂₃₄₅₆₇₈₉²³⁴⁵⁶⁷⁸⁹äöüÄÖÜβß%&:≡°$A-Za-z0-9\n \?\\'\|\(\)\{\}\[\]\"\*\.\+]+)<\/#{this_numbered_word}>/
|
|
58
|
+
/<#{this_colour}>([\n₀₁₂₃₄₅₆₇₈₉⁰¹²³⁴⁵⁶⁷⁸⁹°→⁻⁺≥$@σπµμγ∨^αβßÅÄäéúÖöÜüa-zA-Z0-9’'"„“~#&%!,;:_+−=≡<>\*\\\/\.\{\}\(\)\|\[\]\?\- ]*?)<\/#{this_colour}>/
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# ========================================================================= #
|
|
62
|
+
# === Colours.replace_number_words_with_the_corresponding_html_colour
|
|
63
|
+
#
|
|
64
|
+
# The input to this method should be the String that contains HTML
|
|
65
|
+
# numbers such as <one> or <two>.
|
|
66
|
+
#
|
|
67
|
+
# This method can be customized a bit. One way to customize it is
|
|
68
|
+
# to pass the default colour to this method, as second argument.
|
|
69
|
+
# The default colour is (currently, in Oct 2020) grey.
|
|
70
|
+
#
|
|
71
|
+
# The third argument is a Hash. This Hash can be used to denote the
|
|
72
|
+
# default colours for <one>, <two> and so forth. So if you want
|
|
73
|
+
# to change the colours, pass in your own Hash into this method.
|
|
74
|
+
#
|
|
75
|
+
# Usage examples:
|
|
76
|
+
#
|
|
77
|
+
# x = Colours.replace_number_words_with_the_corresponding_html_colour("- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>.")
|
|
78
|
+
# x = "<one>Methämoglobin</one> ist <two>ungeeignet</two> für <three>den</three> Sauerstofftransport; die <two>roten Blutkörperchen</two>. Welches Enzymsystem ist dies?"
|
|
79
|
+
# y = Colours.replace_number_words_with_the_corresponding_html_colour(x)
|
|
80
|
+
#
|
|
81
|
+
# See also:
|
|
82
|
+
#
|
|
83
|
+
# https://rubular.com/r/XUPQJFKlDs2OYP
|
|
84
|
+
#
|
|
85
|
+
# ========================================================================= #
|
|
86
|
+
def self.replace_number_words_with_the_corresponding_html_colour(
|
|
87
|
+
i,
|
|
88
|
+
use_this_as_replacement_hash = :default
|
|
89
|
+
)
|
|
90
|
+
# ======================================================================= #
|
|
91
|
+
# Specify our "replacement-hash", that is colours used for e. g.
|
|
92
|
+
# <one>, <two> or <three>.
|
|
93
|
+
# ======================================================================= #
|
|
94
|
+
case use_this_as_replacement_hash
|
|
95
|
+
# ======================================================================= #
|
|
96
|
+
# === :default
|
|
97
|
+
# ======================================================================= #
|
|
98
|
+
when :default,
|
|
99
|
+
:default_hash
|
|
100
|
+
# ===================================================================== #
|
|
101
|
+
# The following hash can be used as a default "replacement" Hash.
|
|
102
|
+
# ===================================================================== #
|
|
103
|
+
use_this_as_replacement_hash = {
|
|
104
|
+
one: :teal,
|
|
105
|
+
two: :lightseagreen,
|
|
106
|
+
three: :mediumseagreen, # ← Used to be 'peru' up until 23.11.2019.
|
|
107
|
+
four: :mediumorchid, # ← Used to be 'olivedrab' up until 06.12.2022.
|
|
108
|
+
five: :lightgreen,
|
|
109
|
+
default_colour: USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR # Defined on top.
|
|
110
|
+
}
|
|
111
|
+
end
|
|
112
|
+
# ======================================================================= #
|
|
113
|
+
# === :default_colour
|
|
114
|
+
# ======================================================================= #
|
|
115
|
+
if use_this_as_replacement_hash.has_key? :default_colour
|
|
116
|
+
use_this_colour_for_the_default_colour = use_this_as_replacement_hash[:default_colour]
|
|
117
|
+
end
|
|
118
|
+
# ======================================================================= #
|
|
119
|
+
# === Enable support for <one>, <two>, <three>, <four> and <five> next.
|
|
120
|
+
# ======================================================================= #
|
|
121
|
+
if i.include?('<one>') or
|
|
122
|
+
i.include?('<two>') or
|
|
123
|
+
i.include?('<three>') or
|
|
124
|
+
i.include?('<four>') or
|
|
125
|
+
i.include?('<five>')
|
|
126
|
+
scanned_results = i.scan(
|
|
127
|
+
REGEX_FOR_HTML_COLOURS
|
|
128
|
+
).flatten.uniq
|
|
129
|
+
scanned_results.each {|this_numbered_word|
|
|
130
|
+
# =================================================================== #
|
|
131
|
+
# Since as of December 2021 we only accept Symbols here.
|
|
132
|
+
# =================================================================== #
|
|
133
|
+
this_numbered_word = this_numbered_word.to_sym
|
|
134
|
+
if use_this_as_replacement_hash.has_key? this_numbered_word
|
|
135
|
+
i = i.dup if i.frozen?
|
|
136
|
+
replacement_colour = use_this_as_replacement_hash[this_numbered_word]
|
|
137
|
+
use_this_regex =
|
|
138
|
+
# =============================================================== #
|
|
139
|
+
# We will simply re-use the regex-generator near the top of this
|
|
140
|
+
# file here.
|
|
141
|
+
# =============================================================== #
|
|
142
|
+
::Colours.return_main_regex_to_use_for_obtaining_the_full_content(this_numbered_word)
|
|
143
|
+
# ================================================================= #
|
|
144
|
+
# We must use .gsub!() because the colour-string may occur more
|
|
145
|
+
# than once.
|
|
146
|
+
# ================================================================= #
|
|
147
|
+
i.gsub!(
|
|
148
|
+
use_this_regex,
|
|
149
|
+
::Colours::AllColourMethods.send(replacement_colour.to_sym, "\\1") { :omit_end }+
|
|
150
|
+
::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
|
|
151
|
+
)
|
|
152
|
+
# i << ::Colours.revert
|
|
153
|
+
end
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
return i
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# ========================================================================= #
|
|
160
|
+
# === Colours.replace_html_colours_in_this_string
|
|
161
|
+
#
|
|
162
|
+
# This method will replace all HTML colours in a given string, such as
|
|
163
|
+
# "<slateblue>test</slateblue>", with the corresponding RGB colour
|
|
164
|
+
# variant for the commandline.
|
|
165
|
+
#
|
|
166
|
+
# Typically this refers to a terminal such as the KDE Konsole, and a
|
|
167
|
+
# shell such as bash (although other shells are fine too, and many
|
|
168
|
+
# other terminals, such as the gnome-terminal, most likely will work
|
|
169
|
+
# fine as well - but it is optimized for the KDE Konsole).
|
|
170
|
+
#
|
|
171
|
+
# This method should only be called after a prior check was done,
|
|
172
|
+
# to determine whether the given input String at hand does indeed
|
|
173
|
+
# include a valid HTML colour; otherwise it would be fairly pointless
|
|
174
|
+
# to invoke this method, if it is already known that the String at
|
|
175
|
+
# hand does not contain any HTML colour at all. In order to
|
|
176
|
+
# determine whether a String may include a valid HTML colour,
|
|
177
|
+
# the method called line_contains_a_valid_html_colour?() can be
|
|
178
|
+
# used.
|
|
179
|
+
#
|
|
180
|
+
# Usage example:
|
|
181
|
+
#
|
|
182
|
+
# Colours.replace_html_colours_in_this_string
|
|
183
|
+
# Colours.replace_html_colours_in_this_string('- The <one>UID</one> of <royalblue>the</royalblue> user called <two>root</two> is ... ? <one>0</one>.', :lightgreen)
|
|
184
|
+
#
|
|
185
|
+
# ========================================================================= #
|
|
186
|
+
def self.replace_html_colours_in_this_string(
|
|
187
|
+
i,
|
|
188
|
+
use_this_colour_for_the_default_colour = :default, # ← This specifies the default colour.
|
|
189
|
+
shall_we_revert_at_the_end_of_the_line = true
|
|
190
|
+
)
|
|
191
|
+
i = i.dup # We want to work on a copy.
|
|
192
|
+
result = ''.dup # Our result-string.
|
|
193
|
+
case use_this_colour_for_the_default_colour
|
|
194
|
+
# ======================================================================= #
|
|
195
|
+
# === :default
|
|
196
|
+
# ======================================================================= #
|
|
197
|
+
when :default,
|
|
198
|
+
:default_colour
|
|
199
|
+
use_this_colour_for_the_default_colour = USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
|
|
200
|
+
end
|
|
201
|
+
case shall_we_revert_at_the_end_of_the_line
|
|
202
|
+
# ======================================================================= #
|
|
203
|
+
# === :revert
|
|
204
|
+
# ======================================================================= #
|
|
205
|
+
when :revert
|
|
206
|
+
shall_we_revert_at_the_end_of_the_line = true
|
|
207
|
+
end
|
|
208
|
+
result << ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
|
|
209
|
+
# result = result.dup
|
|
210
|
+
# ======================================================================= #
|
|
211
|
+
# This method will make use of two different regexes.
|
|
212
|
+
# ======================================================================= #
|
|
213
|
+
scanned_results = i.scan(
|
|
214
|
+
REGEX_FOR_HTML_COLOURS
|
|
215
|
+
).flatten.uniq
|
|
216
|
+
add_on_string = i.dup
|
|
217
|
+
# ======================================================================= #
|
|
218
|
+
# scanned_results may be an Array such as ['steelblue', 'tomato']
|
|
219
|
+
# ======================================================================= #
|
|
220
|
+
scanned_results.each {|this_colour|
|
|
221
|
+
if is_this_a_valid_html_colour?(this_colour)
|
|
222
|
+
# =================================================================== #
|
|
223
|
+
# We must use .gsub!() because the colour-string may occur more
|
|
224
|
+
# than once. Unfortunately for longer Strings this becomes a bit
|
|
225
|
+
# fragile.
|
|
226
|
+
# =================================================================== #
|
|
227
|
+
part1 = ::Colours::AllColourMethods.send(this_colour.to_sym, "\\1") { :omit_end }
|
|
228
|
+
part2 = ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
|
|
229
|
+
add_on_string.gsub!(
|
|
230
|
+
::Colours.return_main_regex_to_use_for_obtaining_the_full_content(this_colour),
|
|
231
|
+
part1+part2
|
|
232
|
+
).dup
|
|
233
|
+
end
|
|
234
|
+
}
|
|
235
|
+
result << add_on_string
|
|
236
|
+
if shall_we_revert_at_the_end_of_the_line
|
|
237
|
+
result << ::Colours.revert
|
|
238
|
+
end
|
|
239
|
+
return result
|
|
240
|
+
end; self.instance_eval { alias replace_html_colours replace_html_colours_in_this_string } # === Colours.replace_html_colours
|
|
241
|
+
self.instance_eval { alias replace_all_raw_html_colours_in_this_line replace_html_colours_in_this_string } # === Colours.replace_all_raw_html_colours_in_this_line
|
|
242
|
+
self.instance_eval { alias replace_all_html_colours_in_this_line replace_html_colours_in_this_string } # === Colours.replace_all_html_colours_in_this_line
|
|
243
|
+
self.instance_eval { alias parse_html_colour replace_html_colours_in_this_string } # === Colours.parse_html_colour
|
|
244
|
+
|
|
245
|
+
# ========================================================================= #
|
|
246
|
+
# === Colours.does_this_string_include_a_html_colour?
|
|
247
|
+
# ========================================================================= #
|
|
248
|
+
def self.does_this_string_include_a_html_colour?(i)
|
|
249
|
+
result = (i =~ REGEX_FOR_HTML_COLOURS)
|
|
250
|
+
result = false if result.nil?
|
|
251
|
+
result
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# ========================================================================= #
|
|
255
|
+
# === Colours.does_this_string_include_a_html_number?
|
|
256
|
+
#
|
|
257
|
+
# This method will return true if the string includes tags such as
|
|
258
|
+
# <one> or <two> and so forth.
|
|
259
|
+
# ========================================================================= #
|
|
260
|
+
def self.does_this_string_include_a_html_number?(i)
|
|
261
|
+
i.include?('<one>') or
|
|
262
|
+
i.include?('<two>') or
|
|
263
|
+
i.include?('<three>') or
|
|
264
|
+
i.include?('<four>') or
|
|
265
|
+
i.include?('<five>')
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# ========================================================================= #
|
|
269
|
+
# === Colours.eliminate_html
|
|
270
|
+
#
|
|
271
|
+
# This method simply combines two other methods, without any further
|
|
272
|
+
# checks inside of this method. The method will thus remove entries
|
|
273
|
+
# such as <one> or <steelblue>.
|
|
274
|
+
# ========================================================================= #
|
|
275
|
+
def self.eliminate_html(
|
|
276
|
+
i,
|
|
277
|
+
use_this_colour_for_the_default_colour = :default,
|
|
278
|
+
use_this_as_replacement_hash = :default_hash
|
|
279
|
+
)
|
|
280
|
+
i = i.dup
|
|
281
|
+
i = Colours.replace_number_words_with_the_corresponding_html_colour(
|
|
282
|
+
i,
|
|
283
|
+
use_this_colour_for_the_default_colour,
|
|
284
|
+
use_this_as_replacement_hash
|
|
285
|
+
)
|
|
286
|
+
i = i.dup
|
|
287
|
+
i = Colours.replace_html_colours_in_this_string(
|
|
288
|
+
i,
|
|
289
|
+
use_this_colour_for_the_default_colour
|
|
290
|
+
)
|
|
291
|
+
return i.dup
|
|
292
|
+
end; self.instance_eval { alias away_with_html_colours_and_special_numbers eliminate_html } # === Colours.away_with_html_colours_and_special_numbers
|
|
293
|
+
self.instance_eval { alias remove_html_tags_and_special_words eliminate_html } # === Colours.remove_html_tags_and_special_words
|
|
294
|
+
self.instance_eval { alias remove_crap eliminate_html } # === Colours.remove_crap
|
|
295
|
+
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
if __FILE__ == $PROGRAM_NAME
|
|
299
|
+
alias e puts
|
|
300
|
+
input = ARGV
|
|
301
|
+
if input.empty?
|
|
302
|
+
input << 'steelblue'
|
|
303
|
+
end
|
|
304
|
+
e 'Testing: Colours.html_colour_to_hex_value(ARGV) next'
|
|
305
|
+
e Colours.html_colour_to_hex_value(input)
|
|
306
|
+
e "Testing: Colours.does_this_string_include_a_html_number?('abc <one>def</one>') next"
|
|
307
|
+
puts Colours.does_this_string_include_a_html_number?('abc <one>def</one>')
|
|
308
|
+
# ========================================================================= #
|
|
309
|
+
# Test the behaviour of the method next:
|
|
310
|
+
# ========================================================================= #
|
|
311
|
+
this_line = "- <lightseagreen>hey</lightseagreen> yo <green>there</green>"
|
|
312
|
+
puts Colours.replace_html_colours(
|
|
313
|
+
this_line
|
|
314
|
+
)
|
|
315
|
+
puts Colours.does_this_string_include_a_html_colour?('<steelblue>')
|
|
316
|
+
e
|
|
317
|
+
e Colours.replace_number_words_with_the_corresponding_html_colour(
|
|
318
|
+
"- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
|
|
319
|
+
)
|
|
320
|
+
x = "<one>Methämoglobin</one> ist <two>ungeeignet</two> für <three>den</three> Sauerstofftransport; die <two>roten Blutkörperchen</two>. Welches Enzymsystem ist dies?"
|
|
321
|
+
e Colours.replace_number_words_with_the_corresponding_html_colour(x)
|
|
322
|
+
e Colours.replace_html_colours_in_this_string("<one>Methämoglobin</one> ist <steelblue>ungeeignet</steelblue>.")
|
|
323
|
+
e
|
|
324
|
+
string = "- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>."
|
|
325
|
+
e string
|
|
326
|
+
e Colours.replace_html_colours_in_this_string(
|
|
327
|
+
string
|
|
328
|
+
)
|
|
329
|
+
e
|
|
330
|
+
result = Colours.replace_all_html_colours_in_this_line(' |<steelblue>E</steelblue>]', :default, :revert)
|
|
331
|
+
e result
|
|
332
|
+
e
|
|
333
|
+
e 'And it looks like this via pp:'
|
|
334
|
+
e
|
|
335
|
+
pp result
|
|
336
|
+
end # htmlcolourtohexvalue slateblue
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'colours/toplevel_methods/misc.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module Colours
|
|
8
|
+
|
|
9
|
+
require 'colours/html_colours/html_colours.rb'
|
|
10
|
+
require 'colours/toplevel_methods/esystem.rb'
|
|
11
|
+
require 'colours/toplevel_methods/open_this_file.rb'
|
|
12
|
+
require 'colours/toplevel_methods/remove_escape_sequence.rb'
|
|
13
|
+
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
# === Colours.colour_method_or_display_the_content_of_the_file_or_use_via_pipe
|
|
16
|
+
#
|
|
17
|
+
# This method has an awful name, but its core use case is simple.
|
|
18
|
+
#
|
|
19
|
+
# It will handle commandline instructions such as:
|
|
20
|
+
#
|
|
21
|
+
# orange Hey there
|
|
22
|
+
# slateblue how are you doing?
|
|
23
|
+
#
|
|
24
|
+
# Usage example from within ruby:
|
|
25
|
+
#
|
|
26
|
+
# Colours.testing123('abc', :orange)
|
|
27
|
+
#
|
|
28
|
+
# ========================================================================= #
|
|
29
|
+
def self.colour_method_or_display_the_content_of_the_file_or_use_via_pipe(
|
|
30
|
+
i = ARGF,
|
|
31
|
+
name_of_the_colour = $PROGRAM_NAME
|
|
32
|
+
)
|
|
33
|
+
require 'colours/autogenerated/support_for_html_colours.rb'
|
|
34
|
+
# ======================================================================= #
|
|
35
|
+
# === :read
|
|
36
|
+
# ======================================================================= #
|
|
37
|
+
if i.respond_to? :read
|
|
38
|
+
i = i.read
|
|
39
|
+
elsif i and File.exist?(i)
|
|
40
|
+
i = File.read(i)
|
|
41
|
+
end
|
|
42
|
+
i = Colours.remove_trailing_end_from(i)
|
|
43
|
+
if i.is_a? Array
|
|
44
|
+
i = i.join(' ').strip
|
|
45
|
+
end
|
|
46
|
+
if name_of_the_colour
|
|
47
|
+
if name_of_the_colour.respond_to?(:include?) and
|
|
48
|
+
name_of_the_colour.include?('/')
|
|
49
|
+
name_of_the_colour = File.basename(name_of_the_colour)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
name_of_the_colour = name_of_the_colour.to_sym
|
|
53
|
+
return ::Colours::SupportForHTMLColours.send(name_of_the_colour, i)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# ========================================================================= #
|
|
57
|
+
# === Colours.sanitize_line
|
|
58
|
+
#
|
|
59
|
+
# This method will replace one line with the proper R,G,B valid entries.
|
|
60
|
+
# ========================================================================= #
|
|
61
|
+
def self.sanitize_line(entry)
|
|
62
|
+
all_potential_matches = entry.scan(/<(\w+)>/).flatten
|
|
63
|
+
all_potential_matches.each {|substring|
|
|
64
|
+
entry.gsub!(/<\/>/, rev)
|
|
65
|
+
entry.gsub!(/<#{substring}>/, rgb_format(substring))
|
|
66
|
+
}
|
|
67
|
+
begin
|
|
68
|
+
require 'roebe/modules/remove_html.rb'
|
|
69
|
+
rescue LoadError; end
|
|
70
|
+
if Object.const_defined?(:Roebe) and
|
|
71
|
+
Roebe.respond_to?(:remove_html)
|
|
72
|
+
entry = Roebe.remove_html[entry]
|
|
73
|
+
end
|
|
74
|
+
return entry
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# ========================================================================= #
|
|
78
|
+
# === Colours.read_and_display_this_file
|
|
79
|
+
#
|
|
80
|
+
# This method accepts a file path - in other words, the input should be
|
|
81
|
+
# the location of a specific file on your filesystem - and then simply
|
|
82
|
+
# reads in the content of said file via File.readlines().
|
|
83
|
+
#
|
|
84
|
+
# Content such as <slateblue> found in this file will be replaced
|
|
85
|
+
# with the respective R,G,B substring value.
|
|
86
|
+
#
|
|
87
|
+
# In the test/ subdirectory there is an example file for this - have
|
|
88
|
+
# a look there for more information.
|
|
89
|
+
# ========================================================================= #
|
|
90
|
+
def self.read_and_display_this_file(
|
|
91
|
+
i = TEST_FILE
|
|
92
|
+
)
|
|
93
|
+
i = i.to_s
|
|
94
|
+
if File.exist? i
|
|
95
|
+
new_array = []
|
|
96
|
+
data = File.readlines(i)
|
|
97
|
+
data.each {|entry|
|
|
98
|
+
# ======================================================================= #
|
|
99
|
+
# Check whether the entry has a <> tag:
|
|
100
|
+
# ======================================================================= #
|
|
101
|
+
if entry.include?('<') and entry.include?('>') and
|
|
102
|
+
entry.include?('</>')
|
|
103
|
+
# ================================================================= #
|
|
104
|
+
# Ok, we may assume that something like <slateblue> is there.
|
|
105
|
+
# ================================================================= #
|
|
106
|
+
entry = sanitize_line(entry)
|
|
107
|
+
end
|
|
108
|
+
new_array << entry
|
|
109
|
+
}
|
|
110
|
+
e new_array # For now we will simply output that modified Array.
|
|
111
|
+
else
|
|
112
|
+
e "Notice: The file at `#{sfile(i)}` does not exist."
|
|
113
|
+
end
|
|
114
|
+
end; self.instance_eval { alias read_file read_and_display_this_file } # === Colours.read_file
|
|
115
|
+
|
|
116
|
+
# ========================================================================= #
|
|
117
|
+
# === Colours.does_this_line_include_a_html_colour?
|
|
118
|
+
#
|
|
119
|
+
# This method can be used to determine whether the given input-string
|
|
120
|
+
# contains a valid HTML colour or whether it does not.
|
|
121
|
+
#
|
|
122
|
+
# Returns: a boolean.
|
|
123
|
+
#
|
|
124
|
+
# Invocation examples:
|
|
125
|
+
#
|
|
126
|
+
# Colours.does_this_line_include_a_html_colour? "<green>yo there</green> <orange>getline() function</orange>" # => true
|
|
127
|
+
# Colours.does_this_line_include_a_html_colour? "foo bar" # => false
|
|
128
|
+
#
|
|
129
|
+
# ========================================================================= #
|
|
130
|
+
def self.does_this_line_include_a_html_colour?(
|
|
131
|
+
line
|
|
132
|
+
)
|
|
133
|
+
html_colours?.any? {|entry|
|
|
134
|
+
line.include? entry
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# ========================================================================= #
|
|
139
|
+
# === Colours.convert_hex_to_rgb
|
|
140
|
+
#
|
|
141
|
+
# This method will convert e. g. #baf185 to [186, 241, 133]. Thus it
|
|
142
|
+
# will return an Array, denoting the R, G, B values.
|
|
143
|
+
#
|
|
144
|
+
# How to do this conversion on your own?
|
|
145
|
+
#
|
|
146
|
+
# (1) Get the 2 left digits of the hex color code and convert
|
|
147
|
+
# to decimal value to get the red color level.
|
|
148
|
+
# (2) Get the 2 middle digits of the hex color code and
|
|
149
|
+
# convert to decimal value to get the green color level.
|
|
150
|
+
# (3) Get the 2 right digits of the hex color code and
|
|
151
|
+
# convert to decimal value to get the blue color level.
|
|
152
|
+
#
|
|
153
|
+
# Usage example:
|
|
154
|
+
#
|
|
155
|
+
# Colours.convert_hex_to_rgb('#baf185') # => [186, 241, 133]
|
|
156
|
+
#
|
|
157
|
+
# ========================================================================= #
|
|
158
|
+
def self.convert_hex_to_rgb(hex)
|
|
159
|
+
if hex.is_a? Array
|
|
160
|
+
hex = hex.first
|
|
161
|
+
end
|
|
162
|
+
hex = hex.to_s.dup
|
|
163
|
+
hex.delete!('#') if hex.include? '#'
|
|
164
|
+
array = [] # We will return this Array.
|
|
165
|
+
r = hex[0,2].to_i(16)
|
|
166
|
+
g = hex[2,2].to_i(16)
|
|
167
|
+
b = hex[4,2].to_i(16)
|
|
168
|
+
array << r << g << b
|
|
169
|
+
return array
|
|
170
|
+
end; self.instance_eval { alias hex_to_rgb convert_hex_to_rgb } # === Colours.hex_to_rgb
|
|
171
|
+
|
|
172
|
+
# ========================================================================= #
|
|
173
|
+
# === Colours.convert_hex_code_to_RGBA_array
|
|
174
|
+
#
|
|
175
|
+
# RGBA stands for "red, green, blue, alpha". Alpha indicates how
|
|
176
|
+
# opaque each pixel is.
|
|
177
|
+
#
|
|
178
|
+
# The usual values for the alpha parameter, aka the last parameter,
|
|
179
|
+
# is a number between 0.0 (which means "fully transparent") and
|
|
180
|
+
# the number 1.0 (which means "not transparent at all").
|
|
181
|
+
#
|
|
182
|
+
# Note that this method is similar to Colours.convert_hex_to_rgb(hex),
|
|
183
|
+
# but it has a fourth argument, aka A (for Alpha), on top of
|
|
184
|
+
# the RGB values.
|
|
185
|
+
#
|
|
186
|
+
# Usage example:
|
|
187
|
+
#
|
|
188
|
+
# Colours.convert_hex_code_to_RGBA_array('#baf185') # => [186, 241, 133]
|
|
189
|
+
#
|
|
190
|
+
# ========================================================================= #
|
|
191
|
+
def self.convert_hex_code_to_RGBA_array(
|
|
192
|
+
i, default_alpha_value = 1.0
|
|
193
|
+
)
|
|
194
|
+
rgba_array = convert_hex_to_rgb(i)
|
|
195
|
+
rgba_array << default_alpha_value
|
|
196
|
+
return rgba_array
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# ========================================================================= #
|
|
200
|
+
# === Colours.reset_the_line
|
|
201
|
+
#
|
|
202
|
+
# This method will reset the current line. This can then be used in a
|
|
203
|
+
# progress indicator application.
|
|
204
|
+
# ========================================================================= #
|
|
205
|
+
def self.reset_the_line
|
|
206
|
+
STDOUT.write("\u001b[1000D") # Move to the left by 1000 characters. Aka reset.
|
|
207
|
+
STDOUT.flush # This line will force the output to appear immediately,
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
if __FILE__ == $PROGRAM_NAME
|
|
213
|
+
# ========================================================================= #
|
|
214
|
+
# Example code demonstrating the method defined above:
|
|
215
|
+
# ========================================================================= #
|
|
216
|
+
index = 1
|
|
217
|
+
loop {
|
|
218
|
+
Colours.reset_the_line
|
|
219
|
+
print 'OK! '+
|
|
220
|
+
Random.rand(11).to_s
|
|
221
|
+
index += 1
|
|
222
|
+
break if index == 50
|
|
223
|
+
sleep 0.3
|
|
224
|
+
}
|
|
225
|
+
puts
|
|
226
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'colours/toplevel_methods/open_this_file.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module Colours
|
|
8
|
+
|
|
9
|
+
require 'colours/toplevel_methods/esystem.rb'
|
|
10
|
+
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
# === Colours.open_this_file
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def open_this_file(
|
|
15
|
+
shall_we_exit = false
|
|
16
|
+
)
|
|
17
|
+
case shall_we_exit
|
|
18
|
+
when :then_exit
|
|
19
|
+
shall_we_exit = true
|
|
20
|
+
end
|
|
21
|
+
_ = "bluefish #{__FILE__}"
|
|
22
|
+
esystem(_)
|
|
23
|
+
exit if shall_we_exit
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'colours/toplevel_methods/prefer_this_colour_schemata.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module Colours
|
|
8
|
+
|
|
9
|
+
require 'colours/requires/require_yaml.rb'
|
|
10
|
+
require 'colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb'
|
|
11
|
+
require 'colours/autogenerated/support_for_html_colours.rb'
|
|
12
|
+
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
# === @prefer_this_colour_schemata
|
|
15
|
+
#
|
|
16
|
+
# The following Array ranks which colour schemata we will try to use.
|
|
17
|
+
# More important entries should come on top.
|
|
18
|
+
#
|
|
19
|
+
# Konsole will be the default, normally, followed by the 256 colours; and
|
|
20
|
+
# then the basic colours.
|
|
21
|
+
#
|
|
22
|
+
# Of course you can decide on your own via the .yml file, and other
|
|
23
|
+
# methods that allow us to change this setting, but when it comes
|
|
24
|
+
# to implementations such as for simp() or sfancy() then we will
|
|
25
|
+
# honour the setting in the yaml file (if we use any colours at all,
|
|
26
|
+
# that is). The yaml file is typically called
|
|
27
|
+
# "prefer_this_colour_schemata.yml".
|
|
28
|
+
# ========================================================================= #
|
|
29
|
+
if File.exist? FILE_PREFER_THIS_COLOUR_SCHEMATA
|
|
30
|
+
@prefer_this_colour_schemata = YAML.load_file(FILE_PREFER_THIS_COLOUR_SCHEMATA)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
# === @use_html_colours
|
|
35
|
+
#
|
|
36
|
+
# If the following variable is set to true then the HTML colours will
|
|
37
|
+
# be used, if available. These are colours such as 'slateblue' or
|
|
38
|
+
# 'crimson'.
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
@use_html_colours = false
|
|
41
|
+
|
|
42
|
+
# ========================================================================= #
|
|
43
|
+
# === @use_256_colours
|
|
44
|
+
# ========================================================================= #
|
|
45
|
+
@use_256_colours = false
|
|
46
|
+
|
|
47
|
+
# ========================================================================= #
|
|
48
|
+
# === @use_basic_colours
|
|
49
|
+
# ========================================================================= #
|
|
50
|
+
@use_basic_colours = false
|
|
51
|
+
|
|
52
|
+
# ========================================================================= #
|
|
53
|
+
# Next, we will set some other toplevel instance variables based on
|
|
54
|
+
# the value of this yaml file.
|
|
55
|
+
# ========================================================================= #
|
|
56
|
+
if @prefer_this_colour_schemata
|
|
57
|
+
first_entry = @prefer_this_colour_schemata[1]
|
|
58
|
+
_second_entry = @prefer_this_colour_schemata[2]
|
|
59
|
+
_third_entry = @prefer_this_colour_schemata[3]
|
|
60
|
+
|
|
61
|
+
case first_entry
|
|
62
|
+
# === :html_colours
|
|
63
|
+
when :html_colours
|
|
64
|
+
@use_html_colours = true
|
|
65
|
+
# === :support_for_256_colours
|
|
66
|
+
when :support_for_256_colours
|
|
67
|
+
@use_256_colours = true
|
|
68
|
+
# === :basic_colours
|
|
69
|
+
when :basic_colours
|
|
70
|
+
@use_basic_colours = true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# ========================================================================= #
|
|
75
|
+
# === Colours.prefer_which_colour_schemata?
|
|
76
|
+
# ========================================================================= #
|
|
77
|
+
def self.prefer_which_colour_schemata?
|
|
78
|
+
@prefer_this_colour_schemata[1].to_sym if @prefer_this_colour_schemata
|
|
79
|
+
end; self.instance_eval { alias prefer_which_colour_scheme? prefer_which_colour_schemata? } # === Colours.prefer_which_colour_scheme
|
|
80
|
+
|
|
81
|
+
# ========================================================================= #
|
|
82
|
+
# Designate @use_256_colours to true:
|
|
83
|
+
# ========================================================================= #
|
|
84
|
+
if prefer_which_colour_schemata? == :support_for_256_colours
|
|
85
|
+
@use_256_colours = true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|