colours 0.5.48
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of colours might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENCE.md +22 -0
- data/README.md +867 -0
- data/bin/colours +7 -0
- data/bin/html_colour_to_hex_value +7 -0
- data/bin/html_colourize +7 -0
- data/bin/print_rainbow_line +7 -0
- data/bin/rainbow_colours +7 -0
- data/colours.gemspec +75 -0
- data/doc/COLOUR_CODES_CHART.md +28 -0
- data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
- data/doc/README.gen +850 -0
- data/lib/colours.rb +5 -0
- data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
- data/lib/colours/autoalias_e.rb +10 -0
- data/lib/colours/autogenerated/README.md +2 -0
- data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
- data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
- data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
- data/lib/colours/autoinclude.rb +14 -0
- data/lib/colours/base/base.rb +23 -0
- data/lib/colours/basic_colours/README.md +4 -0
- data/lib/colours/basic_colours/basic_colours.rb +279 -0
- data/lib/colours/colour_methods/README.md +11 -0
- data/lib/colours/colour_methods/default_colour.rb +66 -0
- data/lib/colours/colour_methods/sargument.rb +70 -0
- data/lib/colours/colour_methods/scomments.rb +105 -0
- data/lib/colours/colour_methods/sdir.rb +66 -0
- data/lib/colours/colour_methods/sfancy.rb +84 -0
- data/lib/colours/colour_methods/sfile.rb +71 -0
- data/lib/colours/colour_methods/simportant.rb +92 -0
- data/lib/colours/colour_methods/snormal.rb +66 -0
- data/lib/colours/colour_methods/ssymlink.rb +102 -0
- data/lib/colours/colour_methods/swarn.rb +76 -0
- data/lib/colours/colour_table/README.md +3 -0
- data/lib/colours/colour_table/colour_table.rb +275 -0
- data/lib/colours/colours_e_autoinclude.rb +9 -0
- data/lib/colours/commandline/README.md +2 -0
- data/lib/colours/commandline/commandline.rb +44 -0
- data/lib/colours/commandline/menu.rb +111 -0
- data/lib/colours/constants/colour_constants.rb +299 -0
- data/lib/colours/constants/file_constants.rb +72 -0
- data/lib/colours/constants/hash_simple_colours.rb +146 -0
- data/lib/colours/constants/misc.rb +59 -0
- data/lib/colours/constants/newline.rb +14 -0
- data/lib/colours/constants/registered_colour_methods.rb +53 -0
- data/lib/colours/e.rb +5 -0
- data/lib/colours/e/README.md +13 -0
- data/lib/colours/e/autoinclude.rb +11 -0
- data/lib/colours/e/e.rb +35 -0
- data/lib/colours/eparse/eparse.rb +77 -0
- data/lib/colours/everything/autoinclude.rb +11 -0
- data/lib/colours/html_colours/README.md +1 -0
- data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
- data/lib/colours/html_colours/hash_html_colours.rb +63 -0
- data/lib/colours/html_colours/html_colourize.rb +48 -0
- data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
- data/lib/colours/html_colours/misc.rb +186 -0
- data/lib/colours/html_colours/show_html_colours.rb +85 -0
- data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
- data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
- data/lib/colours/module.rb +11 -0
- data/lib/colours/project/project_base_directory.rb +22 -0
- data/lib/colours/rainbow_colours/README.md +2 -0
- data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
- data/lib/colours/rainbow_colours/constants.rb +30 -0
- data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
- data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
- data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
- data/lib/colours/rainbow_colours/println_ani.rb +32 -0
- data/lib/colours/rainbow_colours/println_plain.rb +36 -0
- data/lib/colours/rainbow_colours/rainbow.rb +38 -0
- data/lib/colours/rainbow_colours/report_errors.rb +32 -0
- data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
- data/lib/colours/rainbow_colours/set_mode.rb +24 -0
- data/lib/colours/requires/require_all_colour_methods.rb +5 -0
- data/lib/colours/requires/require_commandline.rb +7 -0
- data/lib/colours/requires/require_eparse.rb +11 -0
- data/lib/colours/requires/require_rgb.rb +5 -0
- data/lib/colours/requires/require_sdir.rb +5 -0
- data/lib/colours/requires/require_sfile.rb +5 -0
- data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
- data/lib/colours/requires/require_the_basic_colours.rb +7 -0
- data/lib/colours/requires/require_the_colour_methods.rb +34 -0
- data/lib/colours/requires/require_the_colour_table.rb +7 -0
- data/lib/colours/requires/require_the_colours_project.rb +52 -0
- data/lib/colours/requires/require_the_constants.rb +11 -0
- data/lib/colours/requires/require_the_html_colours.rb +11 -0
- data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
- data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
- data/lib/colours/revert/revert.rb +106 -0
- data/lib/colours/rgb/rgb.rb +547 -0
- data/lib/colours/testing/README.md +2 -0
- data/lib/colours/testing/testing.rb +157 -0
- data/lib/colours/toplevel_methods/bold.rb +35 -0
- data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
- data/lib/colours/toplevel_methods/cat.rb +39 -0
- data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
- data/lib/colours/toplevel_methods/cliner.rb +19 -0
- data/lib/colours/toplevel_methods/col.rb +56 -0
- data/lib/colours/toplevel_methods/e.rb +63 -0
- data/lib/colours/toplevel_methods/esystem.rb +19 -0
- data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
- data/lib/colours/toplevel_methods/html_colourize.rb +64 -0
- data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/colours/toplevel_methods/italic.rb +104 -0
- data/lib/colours/toplevel_methods/make_colour.rb +29 -0
- data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +325 -0
- data/lib/colours/toplevel_methods/misc.rb +95 -0
- data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
- data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
- data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
- data/lib/colours/toplevel_methods/random_value.rb +37 -0
- data/lib/colours/toplevel_methods/remove_escape_sequence.rb +107 -0
- data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
- data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
- data/lib/colours/toplevel_methods/underline.rb +114 -0
- data/lib/colours/toplevel_methods/use_colours.rb +290 -0
- data/lib/colours/utility_scripts/README.md +2 -0
- data/lib/colours/utility_scripts/autogenerate.rb +291 -0
- data/lib/colours/version/version.rb +25 -0
- data/lib/colours/yaml/256_colours.yml +277 -0
- data/lib/colours/yaml/basic_colours.yml +23 -0
- data/lib/colours/yaml/html_colours.yml +835 -0
- data/lib/colours/yaml/kde_colour_palette.yml +183 -0
- data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
- data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
- data/test/test.html +18 -0
- data/test/testing_256_colours_support.rb +29 -0
- data/test/testing_col.rb +10 -0
- data/test/testing_colours.rb +95 -0
- data/test/testing_colours_e.rb +13 -0
- data/test/testing_eparse.rb +13 -0
- data/test/testing_kde_colour_palette.rb +30 -0
- data/test/testing_konsole_submodule.rb +226 -0
- data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
- data/test/testing_rgb_to_hex.rb +32 -0
- data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
- data/test/testing_the_colour_methods.rb +36 -0
- data/test/testing_the_constants_of_the_colours_project.rb +9 -0
- data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
- data/test/testing_whether_colours_will_be_used.rb +7 -0
- metadata +224 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/colour_methods/ssymlink.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/revert/revert.rb'
|
8
|
+
require 'colours/colour_table/colour_table.rb'
|
9
|
+
require 'colours/toplevel_methods/use_colours.rb'
|
10
|
+
require 'colours/toplevel_methods/prefer_this_colour_schemata.rb'
|
11
|
+
require 'colours/autogenerated/support_for_html_colours.rb'
|
12
|
+
|
13
|
+
module Colours
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === Colours.ssymlink
|
17
|
+
#
|
18
|
+
# Invocation example:
|
19
|
+
# Colours.ssymlink('Hello world!')
|
20
|
+
# ========================================================================= #
|
21
|
+
def self.ssymlink(
|
22
|
+
i = '',
|
23
|
+
make_newline = false
|
24
|
+
)
|
25
|
+
if @use_colours
|
26
|
+
if @use_html_colours
|
27
|
+
i = SupportForHTMLColours.send(
|
28
|
+
map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
|
29
|
+
)
|
30
|
+
elsif @use_256_colours
|
31
|
+
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
32
|
+
i = SupportFor256Colours.send(use_this_colour, i)
|
33
|
+
else
|
34
|
+
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
35
|
+
"#{i}"\
|
36
|
+
"#{rev}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
i
|
40
|
+
end; self.instance_eval { alias sym ssymlink } # === Colours.sym
|
41
|
+
self.instance_eval { alias ssym ssymlink } # === Colours.ssym
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === Colours.colour_for_symlinks
|
45
|
+
#
|
46
|
+
# This method will simply return the colour for symlinks.
|
47
|
+
# ========================================================================= #
|
48
|
+
def self.colour_for_symlinks
|
49
|
+
result = ''.dup
|
50
|
+
if @use_colours
|
51
|
+
if @use_html_colours
|
52
|
+
result = SupportForHTMLColours.send(
|
53
|
+
map_this_symbol_to_that_html_colour(@colour_table[:ssymlink])
|
54
|
+
)
|
55
|
+
elsif @use_256_colours
|
56
|
+
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
57
|
+
result = SupportFor256Colours.send(use_this_colour)
|
58
|
+
else
|
59
|
+
result = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === ssymlink
|
67
|
+
#
|
68
|
+
# Note that a symlink called symlink() exists to this method, but it
|
69
|
+
# is not exactly clear whether this alias will be kept, as it may
|
70
|
+
# interfere with some other methods when we do an include-action.
|
71
|
+
# ========================================================================= #
|
72
|
+
def ssymlink(i = '')
|
73
|
+
::Colours.ssymlink(i)
|
74
|
+
end; alias symlink ssymlink # === symlink
|
75
|
+
alias ssym ssymlink # === ssym
|
76
|
+
alias slink ssymlink # === slink
|
77
|
+
|
78
|
+
# ========================================================================= #
|
79
|
+
# === Colours.esymlink
|
80
|
+
# ========================================================================= #
|
81
|
+
def self.esymlink(
|
82
|
+
i = '',
|
83
|
+
make_newline = false
|
84
|
+
)
|
85
|
+
e Colours.ssymlink(i, make_newline)
|
86
|
+
end
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === esymlink
|
90
|
+
# ========================================================================= #
|
91
|
+
def esymlink(
|
92
|
+
i = '',
|
93
|
+
make_newline = false
|
94
|
+
)
|
95
|
+
Colours.esymlink(i, make_newline)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
if __FILE__ == $PROGRAM_NAME
|
101
|
+
puts Colours.ssymlink('Hello world!')
|
102
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/colour_methods/swarn.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/revert/revert.rb'
|
8
|
+
require 'colours/colour_table/colour_table.rb'
|
9
|
+
require 'colours/toplevel_methods/use_colours.rb'
|
10
|
+
require 'colours/toplevel_methods/prefer_this_colour_schemata.rb'
|
11
|
+
require 'colours/autogenerated/support_for_html_colours.rb'
|
12
|
+
|
13
|
+
module Colours
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === Colours.swarn
|
17
|
+
#
|
18
|
+
# Invocation example:
|
19
|
+
# Colours.swarn('Hello world!')
|
20
|
+
# ========================================================================= #
|
21
|
+
def self.swarn(
|
22
|
+
i = '',
|
23
|
+
make_newline = false
|
24
|
+
)
|
25
|
+
if @use_colours
|
26
|
+
if @use_html_colours
|
27
|
+
i = SupportForHTMLColours.send(
|
28
|
+
map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
|
29
|
+
)
|
30
|
+
elsif @use_256_colours
|
31
|
+
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
32
|
+
i = SupportFor256Colours.send(use_this_colour, i)
|
33
|
+
else
|
34
|
+
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
35
|
+
"#{i}"\
|
36
|
+
"#{rev}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
i
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === swarn
|
44
|
+
# ========================================================================= #
|
45
|
+
def swarn(
|
46
|
+
i = '',
|
47
|
+
make_newline = false
|
48
|
+
)
|
49
|
+
Colours.swarn(i, make_newline)
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === Colours.ewarn
|
54
|
+
# ========================================================================= #
|
55
|
+
def self.ewarn(
|
56
|
+
i = '',
|
57
|
+
make_newline = false
|
58
|
+
)
|
59
|
+
e swarn(i, make_newline)
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === ewarn
|
64
|
+
# ========================================================================= #
|
65
|
+
def ewarn(
|
66
|
+
i = '',
|
67
|
+
make_newline = false
|
68
|
+
)
|
69
|
+
Colours.ewarn(i, make_newline)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
if __FILE__ == $PROGRAM_NAME
|
75
|
+
puts Colours.swarn('Hello world!')
|
76
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/colour_table/colour_table.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/toplevel_methods/use_colours.rb'
|
8
|
+
require 'colours/html_colours/is_this_html_colour_included.rb'
|
9
|
+
|
10
|
+
module Colours
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === HASH_NEW_COLOURS
|
14
|
+
#
|
15
|
+
# This is the new hash, which we can transition-into when necessary.
|
16
|
+
#
|
17
|
+
# It is only rarely used these days, though (as of the year 2018).
|
18
|
+
#
|
19
|
+
# If you want to use these colours, you can use this simpler API:
|
20
|
+
#
|
21
|
+
# Colourss.set_method_to_colour_table :new_colours
|
22
|
+
#
|
23
|
+
# ========================================================================= #
|
24
|
+
HASH_NEW_COLOURS = {
|
25
|
+
default_colour: :green,
|
26
|
+
sargument: :bold_brown, # === sarg()
|
27
|
+
scomments: :bold_blue, # === scomments()
|
28
|
+
sdir: :bold_green, # === sdir()
|
29
|
+
sfancy: :bold_yellow, # === sfancy()
|
30
|
+
sfile: :brown, # === sfile()
|
31
|
+
simportant: :pink, # === simportant()
|
32
|
+
ssymlink: :teal, # === ssymlink()
|
33
|
+
swarn: :bold_red, # === swarn
|
34
|
+
snormal: :light_grey # === snormal()
|
35
|
+
}
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === Colours.update_the_colour_codes_with (update tag)
|
39
|
+
# ========================================================================= #
|
40
|
+
def self.update_the_colour_codes_with(i = HASH_NEW_COLOURS)
|
41
|
+
@colour_table.update(i)
|
42
|
+
end; self.instance_eval { alias update_colour_table_with update_the_colour_codes_with } # === Colours.update_colour_table_with
|
43
|
+
self.instance_eval { alias update_the_colour_codes update_the_colour_codes_with } # === Colours.update_the_colour_codes
|
44
|
+
self.instance_eval { alias update_colour_codes update_the_colour_codes_with } # === Colours.update_colour_codes
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === @colour_table (default tag, default colours tag)
|
48
|
+
#
|
49
|
+
# This toplevel instance variable has the default colours assigned to
|
50
|
+
# the different methods. If you ever wish to change the default colours
|
51
|
+
# in use, you can do so by manipulating this instance variable.
|
52
|
+
#
|
53
|
+
# Keep it sorted alphabetically.
|
54
|
+
# ========================================================================= #
|
55
|
+
@colour_table = {
|
56
|
+
default_colour: :green,
|
57
|
+
sfancy: :bold_green, # === sfancy()
|
58
|
+
sargument: :bold_green, # === sargument()
|
59
|
+
scomments: :grey, # === scomments()
|
60
|
+
sdir: :chocolate, # === sdir()
|
61
|
+
sfile: :saddlebrown, # === sfile()
|
62
|
+
simportant: :gold, # === simportant()
|
63
|
+
ssymlink: :lightblue, # === ssymlink()
|
64
|
+
swarn: :bold_red, # === swarn()
|
65
|
+
snormal: :light_grey # === snormal()
|
66
|
+
}
|
67
|
+
|
68
|
+
if @use_html_colours
|
69
|
+
these_colours = YAML.load_file(FILE_USE_THESE_VALUES_FOR_THE_COLOUR_METHODS).
|
70
|
+
transform_keys(&:to_sym)
|
71
|
+
update_colour_table_with(these_colours)
|
72
|
+
end
|
73
|
+
|
74
|
+
# ========================================================================= #
|
75
|
+
# === Colours.map_this_symbol_to_that_html_colour
|
76
|
+
#
|
77
|
+
# The job of this method is to map entries such as :bold_green to
|
78
|
+
# a corresponding HTML colour.
|
79
|
+
# ========================================================================= #
|
80
|
+
def self.map_this_symbol_to_that_html_colour(i)
|
81
|
+
if is_a_html_colour? i
|
82
|
+
i
|
83
|
+
else
|
84
|
+
case i
|
85
|
+
when :cyanb
|
86
|
+
:lightseagreen
|
87
|
+
when :light_grey
|
88
|
+
:lightgray
|
89
|
+
when :bold_blue
|
90
|
+
:slateblue
|
91
|
+
when :bold_red, :redb
|
92
|
+
:crimson
|
93
|
+
when :bold_yellow
|
94
|
+
:goldenrod
|
95
|
+
when :bold_green
|
96
|
+
:seagreen
|
97
|
+
else
|
98
|
+
puts 'Unregistered input into the method '+__method__.to_s+': '+i.to_s
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === Colours.map_this_symbol_to_that_256_colour
|
105
|
+
#
|
106
|
+
# This method will take input such as :bold_green and associate it with
|
107
|
+
# a corresponding 256-colour. Thus, the resulting Symbol that is
|
108
|
+
# found here should correspond to a method on module SupportFor256Colours.
|
109
|
+
# ========================================================================= #
|
110
|
+
def self.map_this_symbol_to_that_256_colour(i)
|
111
|
+
case i
|
112
|
+
when :boldgreen,
|
113
|
+
:bold_green
|
114
|
+
:chartreuse2
|
115
|
+
when :teal
|
116
|
+
:teal
|
117
|
+
when :bold_yellow
|
118
|
+
:yellow2
|
119
|
+
when :gold
|
120
|
+
:gold3
|
121
|
+
when :bold_blue
|
122
|
+
:lightslateblue
|
123
|
+
when :bold_brown
|
124
|
+
:darkred
|
125
|
+
when :brown
|
126
|
+
:maroon
|
127
|
+
when :pink
|
128
|
+
:hotpink3
|
129
|
+
when :lightgrey,
|
130
|
+
:light_grey
|
131
|
+
:grey66
|
132
|
+
when :bold_red
|
133
|
+
:red1
|
134
|
+
when :lightblue,
|
135
|
+
:light_blue
|
136
|
+
:deepskyblue3
|
137
|
+
when :grey
|
138
|
+
:grey53
|
139
|
+
when :green
|
140
|
+
:chartreuse4
|
141
|
+
else
|
142
|
+
puts "Not known input to method #{__method__.to_s}: #{i}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# ========================================================================= #
|
147
|
+
# === use_new_colour_codes
|
148
|
+
#
|
149
|
+
# Use this method to assign new colour codes.
|
150
|
+
# We assume that you must pass a hash to this method.
|
151
|
+
#
|
152
|
+
# Usage example:
|
153
|
+
#
|
154
|
+
# new_hash = {
|
155
|
+
# :sfancy => 'green',
|
156
|
+
# :simportant => 'teal',
|
157
|
+
# :default_colour => 'grey',
|
158
|
+
# :sfile => 'magenta',
|
159
|
+
# :sdir => 'cyan'
|
160
|
+
# }
|
161
|
+
# Colours.assign_new_colour_codes(new_hash)
|
162
|
+
#
|
163
|
+
# ========================================================================= #
|
164
|
+
def use_new_colour_codes(
|
165
|
+
i = HASH_NEW_COLOURS
|
166
|
+
)
|
167
|
+
@colour_table.update(i)
|
168
|
+
end; alias assign_new_colour_codes use_new_colour_codes # === assign_new_colour_codes
|
169
|
+
|
170
|
+
# ========================================================================= #
|
171
|
+
# === Colours.set_colour_table
|
172
|
+
#
|
173
|
+
# This method can be used to modify the instance variable
|
174
|
+
# @colour_table.
|
175
|
+
#
|
176
|
+
# The input to this method should be a Hash. It can also be a Symbol,
|
177
|
+
# in which case we will try to find a Hash that corresponds to that
|
178
|
+
# Symbol.
|
179
|
+
#
|
180
|
+
# If in doubt, pass in a Hash though.
|
181
|
+
# ========================================================================= #
|
182
|
+
def self.set_colour_table(
|
183
|
+
i = :new_colours
|
184
|
+
)
|
185
|
+
case i
|
186
|
+
when :new_colours,
|
187
|
+
:new_colour_table,
|
188
|
+
:default
|
189
|
+
i = HASH_NEW_COLOURS
|
190
|
+
end
|
191
|
+
# ======================================================================= #
|
192
|
+
# Note that we must ensure that all the necessary keys are there
|
193
|
+
# in the given input. If this is not the case, then we will
|
194
|
+
# determine which entries are missing, and assign them from the
|
195
|
+
# instance variable @colour_table.
|
196
|
+
# ======================================================================= #
|
197
|
+
missing_entries = (
|
198
|
+
i.keys - @colour_table.keys
|
199
|
+
).flatten
|
200
|
+
unless missing_entries.empty?
|
201
|
+
# ===================================================================== #
|
202
|
+
# Push them onto i in this case.
|
203
|
+
# ===================================================================== #
|
204
|
+
missing_entries.each {|this_key|
|
205
|
+
if i.has_key? this_key
|
206
|
+
# All fine, pass through in this case.
|
207
|
+
else
|
208
|
+
add_this = missing_entries[this_key]
|
209
|
+
i[key] = add_this
|
210
|
+
|
211
|
+
end
|
212
|
+
}
|
213
|
+
end
|
214
|
+
@colour_table = i
|
215
|
+
end; self.instance_eval { alias assign_new_colour_codes set_colour_table } # === Colours.assign_new_colour_codes
|
216
|
+
self.instance_eval { alias set_method_to_colour_table set_colour_table } # === Colours.set_method_to_colour_table
|
217
|
+
|
218
|
+
# ========================================================================= #
|
219
|
+
# === Colours.use_new_colour_table
|
220
|
+
# ========================================================================= #
|
221
|
+
def self.use_new_colour_table
|
222
|
+
set_colour_table(:new_colour_table)
|
223
|
+
end
|
224
|
+
|
225
|
+
# ========================================================================= #
|
226
|
+
# === Colours.show_the_colour_table
|
227
|
+
#
|
228
|
+
# This will simply pretty-print the current colour table.
|
229
|
+
# ========================================================================= #
|
230
|
+
def self.show_the_colour_table
|
231
|
+
pp @colour_table
|
232
|
+
end
|
233
|
+
|
234
|
+
# ========================================================================= #
|
235
|
+
# === Colours.shuffle
|
236
|
+
#
|
237
|
+
# Shuffle the above table. The available colours to take here will
|
238
|
+
# be from the HtmlColours namespace.
|
239
|
+
# ========================================================================= #
|
240
|
+
def self.shuffle
|
241
|
+
# ======================================================================= #
|
242
|
+
# Point to the html "table" to use.
|
243
|
+
# ======================================================================= #
|
244
|
+
_ = ::Colours::HtmlColours.all?.shuffle
|
245
|
+
@colour_table = {
|
246
|
+
simp: _.shift,
|
247
|
+
sdir: _.shift,
|
248
|
+
sfile: _.shift,
|
249
|
+
swarn: _.shift,
|
250
|
+
sfancy: _.shift,
|
251
|
+
sargument: _.shift,
|
252
|
+
ssymlink: _.shift
|
253
|
+
}
|
254
|
+
end
|
255
|
+
|
256
|
+
# ========================================================================= #
|
257
|
+
# === Colours.colour_table?
|
258
|
+
#
|
259
|
+
# This method will feedback the available colour-table.
|
260
|
+
#
|
261
|
+
# To invoke this method, try the following code:
|
262
|
+
#
|
263
|
+
# pp Colours.colours?
|
264
|
+
#
|
265
|
+
# ========================================================================= #
|
266
|
+
def self.colour_table?
|
267
|
+
@colour_table
|
268
|
+
end; self.instance_eval { alias method_to_colour_table colour_table? } # === Colours.method_to_colour_table
|
269
|
+
self.instance_eval { alias method_to_colour_table? colour_table? } # === Colours.method_to_colour_table?
|
270
|
+
self.instance_eval { alias colours? colour_table? } # === Colours.colours?
|
271
|
+
self.instance_eval { alias table? colour_table? } # === Colours.table?
|
272
|
+
self.instance_eval { alias table_colour_methods_to_specific_colour colour_table? } # === Colours.table_colour_methods_to_specific_colour
|
273
|
+
self.instance_eval { alias colour_methods_to_specific_colour? colour_table? } # === Colours.colour_methods_to_specific_colour?
|
274
|
+
|
275
|
+
end
|