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
@@ -2,229 +2,185 @@
|
|
2
2
|
# Encoding: UTF-8
|
3
3
|
# frozen_string_literal: true
|
4
4
|
# =========================================================================== #
|
5
|
-
# require 'colours/
|
5
|
+
# require 'colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb'
|
6
6
|
# =========================================================================== #
|
7
7
|
module Colours
|
8
8
|
|
9
|
-
require 'colours/toplevel_methods/
|
10
|
-
require 'colours/
|
11
|
-
require 'colours/
|
12
|
-
require 'colours/autogenerated/support_for_html_colours.rb'
|
9
|
+
require 'colours/toplevel_methods/rev.rb'
|
10
|
+
require 'colours/module_256_colours/module_256_colours.rb'
|
11
|
+
require 'colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb'
|
13
12
|
|
14
13
|
# ========================================================================= #
|
15
|
-
# ===
|
14
|
+
# === @use_html_colours
|
16
15
|
#
|
17
|
-
# This
|
16
|
+
# This is a separate variable so that we can selectively disable or
|
17
|
+
# enable the colours for the Konsole submodule. Some terminals do
|
18
|
+
# not respond nicely to the R,G,B values that the Konsole submodule
|
19
|
+
# may require.
|
18
20
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# that method. By default it will split on the token '#'.
|
21
|
+
# Since as of November 2023 this variable is semi-deprecated, but
|
22
|
+
# not entirely disabled.
|
22
23
|
# ========================================================================= #
|
23
|
-
|
24
|
-
i,
|
25
|
-
optional_split_at_this_character = '#', # ← Specify which character to split at.
|
26
|
-
first_colour_to_use = :steelblue,
|
27
|
-
second_colour_to_use = :seagreen,
|
28
|
-
colour_to_use_for_the_token = :slategray
|
29
|
-
)
|
30
|
-
_ = i.to_s
|
31
|
-
if optional_split_at_this_character.is_a? Hash
|
32
|
-
# ===================================================================== #
|
33
|
-
# === :token
|
34
|
-
# ===================================================================== #
|
35
|
-
if optional_split_at_this_character.has_key? :token
|
36
|
-
optional_split_at_this_character = optional_split_at_this_character.delete :token
|
37
|
-
end
|
38
|
-
end
|
39
|
-
optional_split_at_this_character = optional_split_at_this_character.to_s
|
40
|
-
# ======================================================================= #
|
41
|
-
# === If we can find a token to split at
|
42
|
-
# ======================================================================= #
|
43
|
-
if _.include? optional_split_at_this_character
|
44
|
-
_ = _.dup if _.frozen?
|
45
|
-
splitted = _.split(optional_split_at_this_character)
|
46
|
-
first_part = ::Colours::SupportForHTMLColours.send(first_colour_to_use, splitted.first)
|
47
|
-
middle_part = ::Colours::SupportForHTMLColours.send(colour_to_use_for_the_token, optional_split_at_this_character)
|
48
|
-
second_part = ::Colours::SupportForHTMLColours.send(second_colour_to_use, splitted.last)
|
49
|
-
_ = first_part+
|
50
|
-
middle_part+
|
51
|
-
second_part+
|
52
|
-
::Colours.rev
|
53
|
-
end
|
54
|
-
e _
|
55
|
-
end
|
24
|
+
@use_html_colours = true
|
56
25
|
|
57
26
|
# ========================================================================= #
|
58
|
-
# ===
|
27
|
+
# === @colour_table (default tag, default colours tag)
|
59
28
|
#
|
60
|
-
#
|
29
|
+
# This toplevel instance variable has the default colours assigned to
|
30
|
+
# the different methods. If you ever wish to change the default colours
|
31
|
+
# in use, you can do so by manipulating this instance variable.
|
61
32
|
#
|
62
|
-
#
|
33
|
+
# The colour-table is a table that maps from e. g. sfancy() to the
|
34
|
+
# corresponding colour at hand.
|
63
35
|
#
|
36
|
+
# Keep it sorted alphabetically.
|
64
37
|
# ========================================================================= #
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
78
|
-
else
|
79
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
80
|
-
"#{i}"\
|
81
|
-
"#{rev}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
return i
|
85
|
-
end
|
38
|
+
@colour_table = {
|
39
|
+
default_colour: :green,
|
40
|
+
sfancy: :bold_green, # === sfancy()
|
41
|
+
# sargument: :bold_green, # === sargument()
|
42
|
+
scomments: :grey, # === scomments()
|
43
|
+
sdir: :chocolate, # === sdir()
|
44
|
+
sfile: :saddlebrown, # === sfile()
|
45
|
+
simportant: :gold, # === simportant()
|
46
|
+
ssymlink: :lightblue, # === ssymlink()
|
47
|
+
swarn: :bold_red, # === swarn()
|
48
|
+
# snormal: :light_grey # === snormal()
|
49
|
+
}
|
86
50
|
|
87
51
|
# ========================================================================= #
|
88
|
-
# ===
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
# === default_colour
|
99
|
-
# ========================================================================= #
|
100
|
-
def default_colour(i = '')
|
101
|
-
::Colours.default_colour(i)
|
102
|
-
end
|
103
|
-
|
104
|
-
# ========================================================================= #
|
105
|
-
# === edir
|
52
|
+
# === Colours::HASH_NEW_COLOURS
|
53
|
+
#
|
54
|
+
# This is the new hash, which we can transition-into if necessary.
|
55
|
+
#
|
56
|
+
# Since as of the year 2018, this Hash is rarely used anymore, though.
|
57
|
+
#
|
58
|
+
# If you want to use these colours nonetheless, you can use this simpler API:
|
59
|
+
#
|
60
|
+
# Colourss.set_method_to_colour_table(:new_colours)
|
61
|
+
#
|
106
62
|
# ========================================================================= #
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
)
|
111
|
-
|
112
|
-
|
63
|
+
HASH_NEW_COLOURS = {
|
64
|
+
default_colour: :green,
|
65
|
+
# sargument: :bold_brown, # === sarg() # removed in November 2023.
|
66
|
+
# scomments: :bold_blue, # === scomments() # removed in November 2023.
|
67
|
+
sdir: :thistle, # === sdir()
|
68
|
+
sfancy: :rosybrown, # === sfancy()
|
69
|
+
sfile: :brown, # === sfile()
|
70
|
+
simportant: :pink, # === simportant()
|
71
|
+
ssymlink: :teal, # === ssymlink()
|
72
|
+
swarn: :olivedrab, # === swarn
|
73
|
+
snormal: :mediumaquamarine, # === snormal()
|
74
|
+
scomments: :grey, # === scomments()
|
75
|
+
}
|
113
76
|
|
114
77
|
# ========================================================================= #
|
115
|
-
# ===
|
78
|
+
# === Colours.update_the_colour_codes_with (update tag)
|
116
79
|
# ========================================================================= #
|
117
|
-
def
|
118
|
-
i =
|
80
|
+
def self.update_the_colour_codes_with(
|
81
|
+
i = HASH_NEW_COLOURS
|
119
82
|
)
|
120
|
-
|
121
|
-
end
|
83
|
+
@colour_table.update(i)
|
84
|
+
end; self.instance_eval { alias update_colour_table_with update_the_colour_codes_with } # === Colours.update_colour_table_with
|
85
|
+
self.instance_eval { alias update_the_colour_codes update_the_colour_codes_with } # === Colours.update_the_colour_codes
|
86
|
+
self.instance_eval { alias update_colour_codes update_the_colour_codes_with } # === Colours.update_colour_codes
|
122
87
|
|
123
88
|
# ========================================================================= #
|
124
|
-
# === Colours.
|
89
|
+
# === Colours.sfancy
|
125
90
|
#
|
126
91
|
# Invocation example:
|
127
92
|
#
|
128
|
-
# Colours.
|
93
|
+
# Colours.sfancy('Hello world!')
|
129
94
|
#
|
130
95
|
# ========================================================================= #
|
131
|
-
def self.
|
96
|
+
def self.sfancy(
|
132
97
|
i = '',
|
133
98
|
make_newline = false
|
134
99
|
)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
elsif @use_256_colours
|
142
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
143
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
144
|
-
else
|
145
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
146
|
-
"#{i}"\
|
147
|
-
"#{rev}"
|
148
|
-
end
|
100
|
+
# ======================================================================= #
|
101
|
+
# Fetch the appropriate replacement-colour next:
|
102
|
+
# ======================================================================= #
|
103
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
104
|
+
unless ::Colours::HtmlColoursMethods.respond_to?(replacement_colour.to_sym)
|
105
|
+
replacement_colour = ::Colours.map_this_symbol_to_that_html_colour(replacement_colour.to_sym)
|
149
106
|
end
|
150
|
-
i
|
151
|
-
end; self.instance_eval { alias argument sargument } # === Colours.argument
|
152
|
-
self.instance_eval { alias sarg sargument } # === Colours.sarg
|
153
|
-
|
154
|
-
# ========================================================================= #
|
155
|
-
# === sargument
|
156
|
-
# ========================================================================= #
|
157
|
-
def sargument(
|
158
|
-
i = '',
|
159
|
-
make_newline = false
|
160
|
-
)
|
161
|
-
::Colours.sargument(i, make_newline)
|
162
|
-
end; alias sarg sargument # === sarg
|
163
|
-
|
164
|
-
# ========================================================================= #
|
165
|
-
# === eargument
|
166
|
-
#
|
167
|
-
# The various simple colourize methods.
|
168
|
-
# ========================================================================= #
|
169
|
-
def eargument(
|
170
|
-
i = '',
|
171
|
-
make_newline = false
|
172
|
-
)
|
173
|
-
e ::Colours.sargument(i, make_newline)
|
107
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
174
108
|
end
|
175
109
|
|
176
110
|
# ========================================================================= #
|
177
|
-
# ===
|
111
|
+
# === use_new_colour_codes
|
178
112
|
#
|
179
|
-
#
|
113
|
+
# Use this method to assign new colour codes.
|
114
|
+
# We assume that you must pass a hash to this method.
|
115
|
+
#
|
116
|
+
# Usage example:
|
180
117
|
#
|
181
|
-
#
|
118
|
+
# new_hash = {
|
119
|
+
# :sfancy => 'green',
|
120
|
+
# :simportant => 'teal',
|
121
|
+
# :default_colour => 'grey',
|
122
|
+
# :sfile => 'magenta',
|
123
|
+
# :sdir => 'cyan'
|
124
|
+
# }
|
125
|
+
# Colours.assign_new_colour_codes(new_hash)
|
182
126
|
#
|
183
127
|
# ========================================================================= #
|
184
|
-
def
|
185
|
-
i
|
186
|
-
make_newline = false
|
128
|
+
def use_new_colour_codes(
|
129
|
+
i = HASH_NEW_COLOURS
|
187
130
|
)
|
188
|
-
|
189
|
-
|
190
|
-
end
|
191
|
-
if @use_colours
|
192
|
-
if @use_html_colours
|
193
|
-
i = SupportForHTMLColours.send(@colour_table[__method__.to_sym], i)
|
194
|
-
elsif @use_256_colours
|
195
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
196
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
197
|
-
else
|
198
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
199
|
-
"#{i}"\
|
200
|
-
"#{rev}"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
i
|
204
|
-
end
|
131
|
+
@colour_table.update(i)
|
132
|
+
end; alias assign_new_colour_codes use_new_colour_codes # === assign_new_colour_codes
|
205
133
|
|
206
134
|
# ========================================================================= #
|
207
|
-
# === Colours.
|
135
|
+
# === Colours.set_colour_table
|
208
136
|
#
|
209
|
-
# This method
|
210
|
-
#
|
137
|
+
# This method can be used to modify the instance variable
|
138
|
+
# @colour_table.
|
211
139
|
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
# Colours.sfile_or_sdir('/home/x/Temp/opened_files.yml')
|
140
|
+
# The input to this method should be a Hash. It can also be a Symbol,
|
141
|
+
# in which case we will try to find a Hash that corresponds to that
|
142
|
+
# Symbol.
|
216
143
|
#
|
144
|
+
# If in doubt, pass in a Hash though.
|
217
145
|
# ========================================================================= #
|
218
|
-
def self.
|
219
|
-
i
|
220
|
-
make_newline = false
|
146
|
+
def self.set_colour_table(
|
147
|
+
i = :new_colours
|
221
148
|
)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
149
|
+
case i
|
150
|
+
# ======================================================================= #
|
151
|
+
# === :new_colours
|
152
|
+
# ======================================================================= #
|
153
|
+
when :new_colours,
|
154
|
+
:new_colour_table,
|
155
|
+
:default
|
156
|
+
i = HASH_NEW_COLOURS
|
226
157
|
end
|
227
|
-
|
158
|
+
# ======================================================================= #
|
159
|
+
# Note that we must ensure that all the necessary keys are there
|
160
|
+
# in the given input. If this is not the case, then we will
|
161
|
+
# determine which entries are missing, and assign them from the
|
162
|
+
# instance variable @colour_table.
|
163
|
+
# ======================================================================= #
|
164
|
+
missing_entries = (
|
165
|
+
i.keys - @colour_table.keys
|
166
|
+
).flatten
|
167
|
+
unless missing_entries.empty?
|
168
|
+
# ===================================================================== #
|
169
|
+
# Push them onto i in this case.
|
170
|
+
# ===================================================================== #
|
171
|
+
missing_entries.each {|this_key|
|
172
|
+
if i.has_key? this_key
|
173
|
+
# All fine, pass through in this case.
|
174
|
+
else
|
175
|
+
add_this = missing_entries[this_key]
|
176
|
+
i[key] = add_this
|
177
|
+
|
178
|
+
end
|
179
|
+
}
|
180
|
+
end
|
181
|
+
@colour_table = i
|
182
|
+
end; self.instance_eval { alias assign_new_colour_codes set_colour_table } # === Colours.assign_new_colour_codes
|
183
|
+
self.instance_eval { alias set_method_to_colour_table set_colour_table } # === Colours.set_method_to_colour_table
|
228
184
|
|
229
185
|
# ========================================================================= #
|
230
186
|
# === Colours.sfile
|
@@ -243,163 +199,239 @@ module Colours
|
|
243
199
|
i = '',
|
244
200
|
make_newline = false
|
245
201
|
)
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
|
250
|
-
)
|
251
|
-
elsif @use_256_colours
|
252
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
253
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
254
|
-
else
|
255
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
256
|
-
"#{i}"\
|
257
|
-
"#{rev}"
|
258
|
-
end
|
202
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
203
|
+
if ::Colours.const_defined?(:HtmlColoursMethods)
|
204
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
259
205
|
end
|
260
|
-
i
|
261
206
|
end
|
262
207
|
|
263
208
|
# ========================================================================= #
|
264
|
-
# ===
|
209
|
+
# === Colours.colour_table?
|
210
|
+
#
|
211
|
+
# This method will feedback the available colour-table.
|
212
|
+
#
|
213
|
+
# To invoke this method, try the following code:
|
214
|
+
#
|
215
|
+
# pp Colours.colours?
|
216
|
+
#
|
265
217
|
# ========================================================================= #
|
266
|
-
def
|
267
|
-
|
268
|
-
|
269
|
-
|
218
|
+
def self.colour_table?
|
219
|
+
@colour_table
|
220
|
+
end; self.instance_eval { alias method_to_colour_table colour_table? } # === Colours.method_to_colour_table
|
221
|
+
self.instance_eval { alias method_to_colour_table? colour_table? } # === Colours.method_to_colour_table?
|
222
|
+
self.instance_eval { alias colours? colour_table? } # === Colours.colours?
|
223
|
+
self.instance_eval { alias table? colour_table? } # === Colours.table?
|
224
|
+
self.instance_eval { alias table_colour_methods_to_specific_colour colour_table? } # === Colours.table_colour_methods_to_specific_colour
|
225
|
+
self.instance_eval { alias colour_methods_to_specific_colour? colour_table? } # === Colours.colour_methods_to_specific_colour?
|
226
|
+
|
227
|
+
# ========================================================================= #
|
228
|
+
# === Colours.use_new_colour_table
|
229
|
+
# ========================================================================= #
|
230
|
+
def self.use_new_colour_table
|
231
|
+
set_colour_table(:new_colour_table)
|
270
232
|
end
|
271
233
|
|
272
234
|
# ========================================================================= #
|
273
|
-
# ===
|
235
|
+
# === Colours.show_the_colour_table
|
236
|
+
#
|
237
|
+
# This will simply pretty-print the current colour table.
|
274
238
|
# ========================================================================= #
|
275
|
-
def
|
239
|
+
def self.show_the_colour_table
|
240
|
+
pp @colour_table
|
241
|
+
end
|
242
|
+
|
243
|
+
# ========================================================================= #
|
244
|
+
# === Colours.shuffle
|
245
|
+
#
|
246
|
+
# Shuffle the above table. The available colours to take here will
|
247
|
+
# be from the HtmlColours namespace.
|
248
|
+
# ========================================================================= #
|
249
|
+
def self.shuffle
|
250
|
+
# ======================================================================= #
|
251
|
+
# Point to the html "table" to use.
|
252
|
+
# ======================================================================= #
|
253
|
+
_ = ::Colours::HtmlColours.all?.shuffle
|
254
|
+
@colour_table = {
|
255
|
+
simp: _.shift,
|
256
|
+
sdir: _.shift,
|
257
|
+
sfile: _.shift,
|
258
|
+
swarn: _.shift,
|
259
|
+
sfancy: _.shift,
|
260
|
+
ssymlink: _.shift
|
261
|
+
}
|
262
|
+
end
|
263
|
+
|
264
|
+
# ========================================================================= #
|
265
|
+
# === edir
|
266
|
+
# ========================================================================= #
|
267
|
+
def edir(
|
276
268
|
i = '',
|
277
269
|
make_newline = false
|
278
270
|
)
|
279
|
-
e
|
271
|
+
e ::Colours.sdir(i, make_newline)
|
280
272
|
end
|
281
273
|
|
282
274
|
# ========================================================================= #
|
283
|
-
# === Colours.
|
275
|
+
# === Colours.ssymlink
|
276
|
+
# ========================================================================= #
|
277
|
+
def self.ssymlink(
|
278
|
+
i = '',
|
279
|
+
make_newline = false
|
280
|
+
)
|
281
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
282
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
283
|
+
end; self.instance_eval { alias sym ssymlink } # === Colours.sym
|
284
|
+
self.instance_eval { alias ssym ssymlink } # === Colours.ssym
|
285
|
+
|
286
|
+
# ========================================================================= #
|
287
|
+
# === Colours.default_colour
|
284
288
|
#
|
285
289
|
# Invocation example:
|
286
290
|
#
|
287
|
-
# Colours.
|
291
|
+
# puts Colours.default_colour('Hello world!')
|
288
292
|
#
|
289
293
|
# ========================================================================= #
|
290
|
-
def self.
|
294
|
+
def self.default_colour(
|
291
295
|
i = '',
|
292
296
|
make_newline = false
|
293
297
|
)
|
294
|
-
if
|
298
|
+
if use_colours?
|
299
|
+
if make_newline
|
300
|
+
i = "#{i}#{N}"
|
301
|
+
end
|
295
302
|
if @use_html_colours
|
296
|
-
|
297
|
-
|
298
|
-
)
|
299
|
-
elsif @use_256_colours
|
300
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
301
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
302
|
-
else
|
303
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
304
|
-
"#{i}"\
|
305
|
-
"#{rev}"
|
303
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
304
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
306
305
|
end
|
307
306
|
end
|
308
|
-
i
|
307
|
+
return i
|
309
308
|
end
|
310
309
|
|
311
310
|
# ========================================================================= #
|
312
|
-
# ===
|
311
|
+
# === Colours.colour_for_symlinks
|
312
|
+
#
|
313
|
+
# This method will simply return the colour for symlinks.
|
313
314
|
# ========================================================================= #
|
314
|
-
def
|
315
|
-
|
316
|
-
make_newline = false
|
317
|
-
)
|
318
|
-
::Colours.snormal(i, make_newline)
|
315
|
+
def self.colour_for_symlinks
|
316
|
+
return @colour_table[:ssymlink].to_sym
|
319
317
|
end
|
320
318
|
|
321
319
|
# ========================================================================= #
|
322
|
-
# ===
|
320
|
+
# === ssymlink
|
321
|
+
#
|
322
|
+
# Note that a symlink called symlink() exists to this method, but it
|
323
|
+
# is not exactly clear whether this alias will be kept, as it may
|
324
|
+
# interfere with some other methods when we do an include-action.
|
323
325
|
# ========================================================================= #
|
324
|
-
def
|
326
|
+
def ssymlink(i = '')
|
327
|
+
::Colours.ssymlink(i)
|
328
|
+
end; alias symlink ssymlink # === symlink
|
329
|
+
alias ssym ssymlink # === ssym
|
330
|
+
alias slink ssymlink # === slink
|
331
|
+
|
332
|
+
# ========================================================================= #
|
333
|
+
# === default_colour
|
334
|
+
# ========================================================================= #
|
335
|
+
def default_colour(i = '')
|
336
|
+
::Colours.default_colour(i)
|
337
|
+
end
|
338
|
+
|
339
|
+
# ========================================================================= #
|
340
|
+
# === edefault_colour
|
341
|
+
# ========================================================================= #
|
342
|
+
def edefault_colour(
|
325
343
|
i = '',
|
326
344
|
make_newline = false
|
327
345
|
)
|
328
|
-
e
|
346
|
+
e ::Colours.default_colour(i, make_newline)
|
329
347
|
end
|
330
348
|
|
331
349
|
# ========================================================================= #
|
332
|
-
# === Colours.
|
333
|
-
#
|
334
|
-
#This method is the one to denote "important" text components.
|
335
|
-
#
|
336
|
-
# Invocation examples:
|
350
|
+
# === Colours.ecomment
|
337
351
|
#
|
338
|
-
#
|
339
|
-
# Colours.simportant('yo there')
|
352
|
+
# This method was added on Nov 2013.
|
340
353
|
#
|
354
|
+
# In April 2014, the ability to split at any arbitrary character was
|
355
|
+
# added, which can be controlled via the second argument given to
|
356
|
+
# that method. By default it will split on the token '#'.
|
341
357
|
# ========================================================================= #
|
342
|
-
def self.
|
343
|
-
i
|
344
|
-
|
358
|
+
def self.ecomment(
|
359
|
+
i,
|
360
|
+
optional_split_at_this_character = '#', # ← Specify which character to split at.
|
361
|
+
first_colour_to_use = :steelblue,
|
362
|
+
second_colour_to_use = :seagreen,
|
363
|
+
colour_to_use_for_the_token = :slategray
|
345
364
|
)
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
354
|
-
else
|
355
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
356
|
-
"#{i}"\
|
357
|
-
"#{rev}"
|
365
|
+
_ = i.to_s
|
366
|
+
if optional_split_at_this_character.is_a? Hash
|
367
|
+
# ===================================================================== #
|
368
|
+
# === :token
|
369
|
+
# ===================================================================== #
|
370
|
+
if optional_split_at_this_character.has_key? :token
|
371
|
+
optional_split_at_this_character = optional_split_at_this_character.delete :token
|
358
372
|
end
|
359
373
|
end
|
360
|
-
|
361
|
-
|
374
|
+
optional_split_at_this_character = optional_split_at_this_character.to_s
|
375
|
+
# ======================================================================= #
|
376
|
+
# === If we can find a token to split at
|
377
|
+
# ======================================================================= #
|
378
|
+
if _.include? optional_split_at_this_character
|
379
|
+
_ = _.dup if _.frozen?
|
380
|
+
splitted = _.split(optional_split_at_this_character)
|
381
|
+
first_part = ::Colours::HtmlColoursMethods.send(first_colour_to_use, splitted.first)
|
382
|
+
middle_part = ::Colours::HtmlColoursMethods.send(colour_to_use_for_the_token, optional_split_at_this_character)
|
383
|
+
second_part = ::Colours::HtmlColoursMethods.send(second_colour_to_use, splitted.last)
|
384
|
+
_ = first_part+
|
385
|
+
middle_part+
|
386
|
+
second_part+
|
387
|
+
::Colours.rev
|
388
|
+
end
|
389
|
+
e _
|
390
|
+
end
|
362
391
|
|
363
392
|
# ========================================================================= #
|
364
|
-
# ===
|
393
|
+
# === Colours.scomments
|
394
|
+
#
|
395
|
+
# Invocation example:
|
396
|
+
#
|
397
|
+
# Colours.scomments('Hello world!')
|
365
398
|
#
|
366
|
-
# Delegate towards Colours.simportant() here.
|
367
399
|
# ========================================================================= #
|
368
|
-
def
|
400
|
+
def self.scomments(
|
369
401
|
i = '',
|
370
402
|
make_newline = false
|
371
403
|
)
|
372
|
-
|
373
|
-
|
374
|
-
|
404
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
405
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
406
|
+
end; self.instance_eval { alias comment scomments } # === Colours.comment
|
375
407
|
|
376
408
|
# ========================================================================= #
|
377
|
-
# ===
|
409
|
+
# === Colours.scomments?
|
410
|
+
#
|
411
|
+
# This method will usually return :grey.
|
378
412
|
# ========================================================================= #
|
379
|
-
def
|
380
|
-
|
381
|
-
end
|
413
|
+
def self.scomments?
|
414
|
+
colour_table?[:scomments]
|
415
|
+
end
|
382
416
|
|
383
417
|
# ========================================================================= #
|
384
|
-
# ===
|
418
|
+
# === scomments
|
385
419
|
# ========================================================================= #
|
386
|
-
def
|
387
|
-
|
388
|
-
|
389
|
-
)
|
390
|
-
e simp(i, make_newline)
|
391
|
-
end
|
420
|
+
def scomments(i = '')
|
421
|
+
::Colours.scomments(i) # Delegate towards Colours.scomments? here.
|
422
|
+
end; alias scomment scomments # === scomment
|
392
423
|
|
393
424
|
# ========================================================================= #
|
394
|
-
# ===
|
425
|
+
# === ecomment
|
426
|
+
#
|
427
|
+
# Just a wrapper over the Colours.ecomment() functionality.
|
395
428
|
# ========================================================================= #
|
396
|
-
def
|
397
|
-
i
|
398
|
-
|
429
|
+
def ecomment(
|
430
|
+
i,
|
431
|
+
optional_split_at_this_character = '#'
|
399
432
|
)
|
400
|
-
::Colours.
|
401
|
-
end
|
402
|
-
alias cii eimportant # === cii
|
433
|
+
::Colours.ecomment(i, optional_split_at_this_character)
|
434
|
+
end
|
403
435
|
|
404
436
|
# ========================================================================= #
|
405
437
|
# === Colours.swarn
|
@@ -413,21 +445,8 @@ module Colours
|
|
413
445
|
i = '',
|
414
446
|
make_newline = false
|
415
447
|
)
|
416
|
-
|
417
|
-
|
418
|
-
i = SupportForHTMLColours.send(
|
419
|
-
map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
|
420
|
-
)
|
421
|
-
elsif @use_256_colours
|
422
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
423
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
424
|
-
else
|
425
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
426
|
-
"#{i}"\
|
427
|
-
"#{rev}"
|
428
|
-
end
|
429
|
-
end
|
430
|
-
i
|
448
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
449
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
431
450
|
end
|
432
451
|
|
433
452
|
# ========================================================================= #
|
@@ -440,6 +459,26 @@ module Colours
|
|
440
459
|
::Colours.swarn(i, make_newline)
|
441
460
|
end
|
442
461
|
|
462
|
+
# ========================================================================= #
|
463
|
+
# === Colours.esymlink
|
464
|
+
# ========================================================================= #
|
465
|
+
def self.esymlink(
|
466
|
+
i = '',
|
467
|
+
make_newline = false
|
468
|
+
)
|
469
|
+
e ::Colours.ssymlink(i, make_newline)
|
470
|
+
end
|
471
|
+
|
472
|
+
# ========================================================================= #
|
473
|
+
# === esymlink
|
474
|
+
# ========================================================================= #
|
475
|
+
def esymlink(
|
476
|
+
i = '',
|
477
|
+
make_newline = false
|
478
|
+
)
|
479
|
+
::Colours.esymlink(i, make_newline)
|
480
|
+
end
|
481
|
+
|
443
482
|
# ========================================================================= #
|
444
483
|
# === Colours.ewarn
|
445
484
|
# ========================================================================= #
|
@@ -461,117 +500,71 @@ module Colours
|
|
461
500
|
end
|
462
501
|
|
463
502
|
# ========================================================================= #
|
464
|
-
# === Colours.
|
503
|
+
# === Colours.simportant
|
465
504
|
#
|
466
|
-
#
|
505
|
+
#This method is the one to denote "important" text components.
|
467
506
|
#
|
468
|
-
#
|
507
|
+
# Invocation examples:
|
508
|
+
#
|
509
|
+
# Colours.simportant('Hello world!')
|
510
|
+
# Colours.simportant('yo there')
|
469
511
|
#
|
470
512
|
# ========================================================================= #
|
471
|
-
def self.
|
513
|
+
def self.simportant(
|
472
514
|
i = '',
|
473
515
|
make_newline = false
|
474
516
|
)
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
483
|
-
else
|
484
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
485
|
-
"#{i}"\
|
486
|
-
"#{rev}"
|
487
|
-
end
|
517
|
+
require 'colours/essentials/essentials.rb'
|
518
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
519
|
+
_ = ::Colours::HtmlColoursMethods
|
520
|
+
if _.respond_to? replacement_colour
|
521
|
+
return _.send(replacement_colour, i)
|
522
|
+
else
|
523
|
+
::Colours::Essentials.send(replacement_colour, i)
|
488
524
|
end
|
489
|
-
|
490
|
-
end; self.instance_eval { alias sym ssymlink } # === Colours.sym
|
491
|
-
self.instance_eval { alias ssym ssymlink } # === Colours.ssym
|
492
|
-
|
493
|
-
# ========================================================================= #
|
494
|
-
# === Colours.colour_for_symlinks
|
495
|
-
#
|
496
|
-
# This method will simply return the colour for symlinks.
|
497
|
-
# ========================================================================= #
|
498
|
-
def self.colour_for_symlinks
|
499
|
-
result = ''.dup
|
500
|
-
if @use_colours
|
501
|
-
if @use_html_colours
|
502
|
-
result = SupportForHTMLColours.send(
|
503
|
-
map_this_symbol_to_that_html_colour(@colour_table[:ssymlink])
|
504
|
-
)
|
505
|
-
elsif @use_256_colours
|
506
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
507
|
-
result = SupportFor256Colours.send(use_this_colour)
|
508
|
-
else
|
509
|
-
result = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"
|
510
|
-
end
|
511
|
-
end
|
512
|
-
result
|
513
|
-
end
|
525
|
+
end; self.instance_eval { alias simp simportant } # === Colours.simp
|
514
526
|
|
515
527
|
# ========================================================================= #
|
516
|
-
# ===
|
528
|
+
# === simportant
|
517
529
|
#
|
518
|
-
#
|
519
|
-
# is not exactly clear whether this alias will be kept, as it may
|
520
|
-
# interfere with some other methods when we do an include-action.
|
530
|
+
# Delegate towards Colours.simportant() here.
|
521
531
|
# ========================================================================= #
|
522
|
-
def
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
532
|
+
def simportant(
|
533
|
+
i = '',
|
534
|
+
make_newline = false
|
535
|
+
)
|
536
|
+
::Colours.simportant(i, make_newline)
|
537
|
+
end; alias simp simportant # === simp
|
538
|
+
alias si simportant # === si
|
527
539
|
|
528
540
|
# ========================================================================= #
|
529
|
-
# === Colours.
|
541
|
+
# === Colours.eimp
|
530
542
|
# ========================================================================= #
|
531
|
-
def self.
|
543
|
+
def self.eimp(
|
532
544
|
i = '',
|
533
545
|
make_newline = false
|
534
546
|
)
|
535
|
-
e
|
547
|
+
e simp(i, make_newline)
|
536
548
|
end
|
537
549
|
|
538
550
|
# ========================================================================= #
|
539
|
-
# ===
|
551
|
+
# === eimportant
|
540
552
|
# ========================================================================= #
|
541
|
-
def
|
553
|
+
def eimportant(
|
542
554
|
i = '',
|
543
555
|
make_newline = false
|
544
556
|
)
|
545
|
-
::Colours.
|
546
|
-
end
|
557
|
+
::Colours.eimp(i, make_newline)
|
558
|
+
end; alias eimp eimportant # === eimp
|
559
|
+
alias cii eimportant # === cii
|
547
560
|
|
548
561
|
# ========================================================================= #
|
549
|
-
# ===
|
550
|
-
#
|
551
|
-
# Invocation example:
|
552
|
-
#
|
553
|
-
# Colours.sfancy('Hello world!')
|
562
|
+
# === ciif
|
554
563
|
#
|
564
|
+
# Alias to the above method, basically, aka eimportant().
|
555
565
|
# ========================================================================= #
|
556
|
-
def
|
557
|
-
|
558
|
-
make_newline = false
|
559
|
-
)
|
560
|
-
if @use_colours
|
561
|
-
if @use_html_colours
|
562
|
-
i = SupportForHTMLColours.send(
|
563
|
-
map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
|
564
|
-
)
|
565
|
-
elsif @use_256_colours
|
566
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
567
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
568
|
-
else
|
569
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
570
|
-
"#{i}"\
|
571
|
-
"#{rev}"
|
572
|
-
end
|
573
|
-
end
|
574
|
-
i
|
566
|
+
def ciif(i)
|
567
|
+
eimportant(i, false)
|
575
568
|
end
|
576
569
|
|
577
570
|
# ========================================================================= #
|
@@ -613,73 +606,142 @@ module Colours
|
|
613
606
|
end; alias ff cif # === ff (alias to the above ^^^)
|
614
607
|
|
615
608
|
# ========================================================================= #
|
616
|
-
# === Colours.
|
617
|
-
#
|
618
|
-
# Invocation example:
|
619
|
-
#
|
620
|
-
# Colours.scomments('Hello world!')
|
621
|
-
#
|
609
|
+
# === Colours.sdir
|
622
610
|
# ========================================================================= #
|
623
|
-
def self.
|
611
|
+
def self.sdir(
|
624
612
|
i = '',
|
625
613
|
make_newline = false
|
626
614
|
)
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
elsif @use_256_colours
|
631
|
-
use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
|
632
|
-
i = SupportFor256Colours.send(use_this_colour, i)
|
633
|
-
else
|
634
|
-
i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
|
635
|
-
"#{i}"\
|
636
|
-
"#{rev}"
|
637
|
-
end
|
638
|
-
end
|
639
|
-
i
|
640
|
-
end; self.instance_eval { alias comment scomments } # === Colours.comment
|
615
|
+
replacement_colour = @colour_table[__method__.to_sym].to_sym
|
616
|
+
return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
|
617
|
+
end
|
641
618
|
|
642
619
|
# ========================================================================= #
|
643
|
-
# ===
|
620
|
+
# === sdir
|
644
621
|
# ========================================================================= #
|
645
|
-
def
|
646
|
-
|
647
|
-
|
622
|
+
def sdir(
|
623
|
+
i = '',
|
624
|
+
make_newline = false
|
625
|
+
)
|
626
|
+
::Colours.sdir(i, make_newline)
|
627
|
+
end
|
648
628
|
|
649
629
|
# ========================================================================= #
|
650
|
-
# ===
|
630
|
+
# === sfile
|
631
|
+
# ========================================================================= #
|
632
|
+
def sfile(
|
633
|
+
i = '',
|
634
|
+
make_newline = false
|
635
|
+
)
|
636
|
+
::Colours.sfile(i, make_newline)
|
637
|
+
end
|
638
|
+
|
639
|
+
# ========================================================================= #
|
640
|
+
# === efile
|
641
|
+
# ========================================================================= #
|
642
|
+
def efile(
|
643
|
+
i = '',
|
644
|
+
make_newline = false
|
645
|
+
)
|
646
|
+
e sfile(i, make_newline)
|
647
|
+
end
|
648
|
+
|
649
|
+
# ========================================================================= #
|
650
|
+
# === Colours.sfile_or_sdir
|
651
|
+
#
|
652
|
+
# This method will directly delegate to either Colours.sfile() or
|
653
|
+
# Colours.sdir(), depending on whether we have a file at hand or
|
654
|
+
# whether we have a directory at hand.
|
655
|
+
#
|
656
|
+
# Usage examples:
|
657
|
+
#
|
658
|
+
# Colours.sfile_or_sdir('/home/x/Temp/MyGems/')
|
659
|
+
# Colours.sfile_or_sdir('/home/x/Temp/opened_files.yml')
|
651
660
|
#
|
652
|
-
# This method will usually return :grey.
|
653
661
|
# ========================================================================= #
|
654
|
-
def self.
|
655
|
-
|
662
|
+
def self.sfile_or_sdir(
|
663
|
+
i = '',
|
664
|
+
make_newline = false
|
665
|
+
)
|
666
|
+
if File.exist?(i) and File.file?(i)
|
667
|
+
return ::Colours.sfile(i, make_newline)
|
668
|
+
elsif File.directory?(i)
|
669
|
+
return ::Colours.sdir(i, make_newline)
|
670
|
+
end
|
671
|
+
end; self.instance_eval { alias sdir_or_sfile sfile_or_sdir } # === Colours.sdir_or_sfile
|
672
|
+
|
673
|
+
# ========================================================================= #
|
674
|
+
# === Update the colour-table next
|
675
|
+
# ========================================================================= #
|
676
|
+
if @use_html_colours and File.exist?(FILE_USE_THESE_VALUES_FOR_THE_COLOUR_METHODS)
|
677
|
+
these_colours = YAML.load_file(FILE_USE_THESE_VALUES_FOR_THE_COLOUR_METHODS).
|
678
|
+
transform_keys(&:to_sym)
|
679
|
+
update_colour_table_with(these_colours)
|
656
680
|
end
|
657
681
|
|
658
682
|
# ========================================================================= #
|
659
|
-
# ===
|
683
|
+
# === Colours.col (col tag)
|
684
|
+
#
|
685
|
+
# Careful - this method may collide with other methods named col().
|
686
|
+
#
|
687
|
+
# Usage examples:
|
688
|
+
#
|
689
|
+
# Colours.col '/Depot/j/geojgirjh'
|
690
|
+
# Colours.col '/home/x/songs/'
|
691
|
+
# Colours.col '/home/x/songs/Westbam_Sunshine.mp3'
|
660
692
|
#
|
661
|
-
# Just a wrapper over the Colours.ecomment() functionality.
|
662
693
|
# ========================================================================= #
|
663
|
-
def
|
694
|
+
def self.col(
|
664
695
|
i,
|
665
|
-
|
696
|
+
optional_arg_not_in_use_right_now = ''
|
666
697
|
)
|
667
|
-
|
698
|
+
if File.exist? i
|
699
|
+
ftype = File.ftype(i)
|
700
|
+
# ===================================================================== #
|
701
|
+
# e 'The ftype is: '+ftype # <- This could be used for debugging.
|
702
|
+
# ===================================================================== #
|
703
|
+
case ftype
|
704
|
+
# ===================================================================== #
|
705
|
+
# === file
|
706
|
+
# ===================================================================== #
|
707
|
+
when 'file'
|
708
|
+
return sfile(i)
|
709
|
+
# ===================================================================== #
|
710
|
+
# === directory
|
711
|
+
# ===================================================================== #
|
712
|
+
when 'directory'
|
713
|
+
return sdir(i)
|
714
|
+
# ===================================================================== #
|
715
|
+
# === link
|
716
|
+
# ===================================================================== #
|
717
|
+
when 'link'
|
718
|
+
return ssymlink(i)
|
719
|
+
else
|
720
|
+
e "module Colours: We do not know the filetype `#{ftype}`"
|
721
|
+
end
|
722
|
+
else # Else return the input a bit changed.
|
723
|
+
return sfile(i) # We modify it because that is better.
|
724
|
+
end
|
668
725
|
end
|
669
726
|
|
670
727
|
end
|
671
728
|
|
672
729
|
if __FILE__ == $PROGRAM_NAME
|
673
730
|
alias e puts
|
674
|
-
e ::Colours.
|
731
|
+
e ::Colours.sdir('Hello world!')
|
675
732
|
e ::Colours.sfile('Hello world!')+' And this should appear in another colour.'
|
676
|
-
e ::Colours.snormal('Hello world!')
|
677
733
|
e ::Colours.simportant('Hello world!')
|
734
|
+
e ::Colours.simp('Hello world!')
|
678
735
|
e ::Colours.swarn('Hello world!')
|
679
736
|
e ::Colours.ssymlink('Hello world!')
|
680
737
|
e ::Colours.sfancy('Hello world!')
|
681
|
-
e ::Colours.default_colour('Hello world!')
|
682
|
-
e ::Colours.sdir('Hello world!')
|
683
738
|
e ::Colours.scomments('Hello world!')
|
739
|
+
e ::Colours.col '/Depot/j/geojgirjh.md'
|
740
|
+
e ::Colours.col '/home/x/songs/'
|
741
|
+
e ::Colours.col '/home/x/songs/Westbam_Sunshine.mp3'
|
684
742
|
::Colours.ecomment('Hello world! # this is the associated comment')
|
685
|
-
|
743
|
+
e
|
744
|
+
pp Colours::HASH_NEW_COLOURS
|
745
|
+
e
|
746
|
+
e ::Colours.default_colour('Hello world!')
|
747
|
+
end # ruby sfile_sdir*.rb
|