colours 0.8.12 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,110 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'colours/toplevel_methods/italic.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module Colours
|
8
|
-
|
9
|
-
require 'colours/toplevel_methods/revert.rb'
|
10
|
-
require 'colours/toplevel_methods/e.rb'
|
11
|
-
require 'colours/rgb/rgb.rb'
|
12
|
-
|
13
|
-
# ========================================================================= #
|
14
|
-
# === ITALIC_CODE
|
15
|
-
#
|
16
|
-
# If you wish to test italic output quickly on the terminal, then you
|
17
|
-
# can use something like this:
|
18
|
-
#
|
19
|
-
# echo -e "\e[3mone two three\e[23m"
|
20
|
-
#
|
21
|
-
# ========================================================================= #
|
22
|
-
ITALIC_CODE = '3'
|
23
|
-
|
24
|
-
# ========================================================================= #
|
25
|
-
# === Colours.return_italic
|
26
|
-
#
|
27
|
-
# To test this method, try:
|
28
|
-
#
|
29
|
-
# Colours.italic('Hello world!')
|
30
|
-
#
|
31
|
-
# ========================================================================= #
|
32
|
-
def self.return_italic(
|
33
|
-
show_this_text = 'This must be italic.',
|
34
|
-
make_newline = false
|
35
|
-
)
|
36
|
-
result = "\x1b".dup
|
37
|
-
result << '['
|
38
|
-
result << ITALIC_CODE
|
39
|
-
if block_given?
|
40
|
-
# ===================================================================== #
|
41
|
-
# Right now we assume that this must be a colour.
|
42
|
-
# ===================================================================== #
|
43
|
-
result << ";38;2;"
|
44
|
-
result << html_colour_to_stringified_rgb_values(yield)
|
45
|
-
end
|
46
|
-
result << 'm'
|
47
|
-
if make_newline
|
48
|
-
show_this_text = "#{show_this_text}\n"
|
49
|
-
end
|
50
|
-
result << show_this_text
|
51
|
-
result << REVERT
|
52
|
-
result
|
53
|
-
end; self.instance_eval { alias string_italic return_italic } # === Colours.string_italic
|
54
|
-
|
55
|
-
# ========================================================================= #
|
56
|
-
# === Colours.italic
|
57
|
-
#
|
58
|
-
# This method will "puts" the result of applying italic to a string,
|
59
|
-
# on the console/terminal. If you wish to do the output on your own
|
60
|
-
# then you have to use the method Colours.return_italic or its
|
61
|
-
# alias called Colours.string_italic.
|
62
|
-
#
|
63
|
-
# To test this, try:
|
64
|
-
# Colours.italic('Hello world!')
|
65
|
-
# ========================================================================= #
|
66
|
-
def self.italic(
|
67
|
-
i = '',
|
68
|
-
make_newline = false,
|
69
|
-
&block
|
70
|
-
)
|
71
|
-
e return_italic(i, make_newline, &block)
|
72
|
-
end
|
73
|
-
|
74
|
-
# ========================================================================= #
|
75
|
-
# === italic
|
76
|
-
# ========================================================================= #
|
77
|
-
def italic(
|
78
|
-
i = '',
|
79
|
-
make_newline = false
|
80
|
-
)
|
81
|
-
::Colours.italic(i, make_newline)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
if __FILE__ == $PROGRAM_NAME
|
87
|
-
alias e puts
|
88
|
-
alias ee print
|
89
|
-
txt = 'Hello world!'
|
90
|
-
if ARGV.empty?
|
91
|
-
require 'colours/requires/require_all_colour_methods.rb'
|
92
|
-
COLOURS = Colours::AllColourMethods
|
93
|
-
system 'clear'
|
94
|
-
Colours.italic(txt)
|
95
|
-
e COLOURS.palegreen('italic in palegreen:')
|
96
|
-
ee ' '; e Colours.string_italic(txt) { :palegreen }
|
97
|
-
e COLOURS.slateblue('italic in slateblue:')
|
98
|
-
ee ' '; e Colours.string_italic(txt) { :slateblue }
|
99
|
-
e COLOURS.orange('italic in orange:')
|
100
|
-
ee ' '; e Colours.string_italic(txt) { :orange }
|
101
|
-
e COLOURS.crimson('italic in crimson:')
|
102
|
-
ee ' '; e Colours.string_italic(txt) { :crimson }
|
103
|
-
e 'Italic without colours:'
|
104
|
-
ee ' '; e 'Die '+Colours.string_italic('R-Gruppe bei')+
|
105
|
-
' Serin (S) besteht aus ...'
|
106
|
-
else
|
107
|
-
ee ' '; e Colours.string_italic(ARGV.join(' ').strip)
|
108
|
-
ee ' '; e Colours.string_italic(ARGV.join(' ').strip) { :crimson }
|
109
|
-
end
|
110
|
-
end # italic
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'colours/toplevel_methods/make_colour.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module Colours
|
8
|
-
|
9
|
-
require 'colours/constants/misc.rb'
|
10
|
-
require 'colours/toplevel_methods/e.rb'
|
11
|
-
|
12
|
-
# ========================================================================= #
|
13
|
-
# === Colours.make_colour
|
14
|
-
#
|
15
|
-
# This is used primarily for testing.
|
16
|
-
# ========================================================================= #
|
17
|
-
def self.make_colour(
|
18
|
-
what_colour_to_use
|
19
|
-
)
|
20
|
-
i = what_colour_to_use # Copy.
|
21
|
-
constant = i.to_s.upcase
|
22
|
-
name_of_colour = const_get(constant)
|
23
|
-
string = '%-34s' % ("#{name_of_colour} Test with #{constant}.")
|
24
|
-
string << IS_A_TEST+'('+name_of_colour.inspect.delete('"')+')'
|
25
|
-
e(string)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,336 +0,0 @@
|
|
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
|