colours 0.8.12 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +331 -200
  3. data/bin/colours +2 -2
  4. data/bin/show_basic_colour_palette +7 -0
  5. data/colours.gemspec +1 -2
  6. data/doc/README.gen +294 -178
  7. data/doc/how_to_pick_your_own_colours/how_to_pick_your_own_colours.md +33 -0
  8. data/lib/colours/autoalias_e.rb +4 -1
  9. data/lib/colours/autogenerated/256_colours_instance_methods.rb +1429 -0
  10. data/lib/colours/autogenerated/256_colours_methods.rb +1429 -0
  11. data/lib/colours/autogenerated/html_colours_instance_methods.rb +1191 -0
  12. data/lib/colours/autogenerated/html_colours_methods.rb +1191 -0
  13. data/lib/colours/base/base.rb +61 -13
  14. data/lib/colours/class/colours.rb +8 -6
  15. data/lib/colours/{toplevel_methods/use_colours.rb → colour/colour.rb} +4 -125
  16. data/lib/colours/commandline/README.md +2 -1
  17. data/lib/colours/commandline/commandline.rb +177 -34
  18. data/lib/colours/constants/constants.rb +752 -6
  19. data/lib/colours/e/README.md +6 -6
  20. data/lib/colours/eparse/eparse.rb +2 -1
  21. data/lib/colours/essentials/README.md +5 -0
  22. data/lib/colours/{basic_colours/basic_colours.rb → essentials/essentials.rb} +87 -85
  23. data/lib/colours/html_colours/README.md +2 -1
  24. data/lib/colours/html_colours/hash_html_colours.rb +168 -0
  25. data/lib/colours/html_colours/html_colours.rb +226 -244
  26. data/lib/colours/html_colours/push_the_html_colours_methods_onto_the_toplevel_namespace.rb +30 -0
  27. data/lib/colours/html_colours/random_html_colour.rb +67 -0
  28. data/lib/colours/{requires/require_the_basic_colours.rb → html_colours.rb} +4 -2
  29. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +12 -10
  30. data/lib/colours/module_256_colours/module_256_colours.rb +465 -0
  31. data/lib/colours/project/project.rb +3 -1
  32. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +4 -0
  33. data/lib/colours/rainbow_colours/constants.rb +3 -3
  34. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +9 -10
  35. data/lib/colours/rainbow_colours/print_rainbow_line.rb +4 -4
  36. data/lib/colours/rainbow_colours/println_ani.rb +7 -7
  37. data/lib/colours/rainbow_colours/println_plain.rb +2 -2
  38. data/lib/colours/rainbow_colours/rainbow.rb +31 -1
  39. data/lib/colours/rainbow_colours/report_errors.rb +7 -7
  40. data/lib/colours/rainbow_colours/returnln_plain.rb +3 -3
  41. data/lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb +409 -0
  42. data/lib/colours/requires/require_autogenerated_colour_methods.rb +4 -1
  43. data/lib/colours/requires/{require_the_colour_table.rb → require_essentials.rb} +2 -2
  44. data/lib/colours/requires/require_save_file.rb +11 -0
  45. data/lib/colours/requires/require_the_256_colours_module.rb +1 -3
  46. data/lib/colours/requires/require_the_colour_methods.rb +1 -22
  47. data/lib/colours/requires/require_the_project.rb +31 -29
  48. data/lib/colours/requires/require_the_toplevel_methods.rb +2 -20
  49. data/lib/colours/rgb/rgb.rb +107 -89
  50. 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
  51. data/lib/colours/testing/testing.rb +1 -3
  52. data/lib/colours/toplevel_methods/e.rb +9 -13
  53. data/lib/colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb +57 -0
  54. data/lib/colours/toplevel_methods/{revert.rb → rev.rb} +5 -48
  55. data/lib/colours/toplevel_methods/toplevel_methods.rb +1204 -0
  56. data/lib/colours/version/version.rb +2 -2
  57. data/lib/colours/yaml/256_colours.yml +776 -257
  58. data/lib/colours/yaml/html_colours.yml +1 -1
  59. data/lib/colours/yaml/prefer_this_colour_schemata.yml +1 -1
  60. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +5 -1
  61. data/lib/colours.rb +1 -1
  62. data/test/testing_256_colours_support.rb +10 -1
  63. data/test/testing_replace_number_words_with_the_corresponding_html_colour.rb +15 -9
  64. data/test/testing_the_colour_methods_such_as_simp_sdir_sfile_swarn_sfancy_sargument_and_ssymlink.rb +53 -0
  65. metadata +30 -57
  66. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +0 -28
  67. data/lib/colours/256_colours/support_for_256_colours.rb +0 -196
  68. data/lib/colours/autogenerated/support_for_256_colours.rb +0 -2235
  69. data/lib/colours/autogenerated/support_for_html_colours.rb +0 -1778
  70. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +0 -7001
  71. data/lib/colours/basic_colours/README.md +0 -4
  72. data/lib/colours/colour_methods/README.md +0 -11
  73. data/lib/colours/colour_table/README.md +0 -2
  74. data/lib/colours/colour_table/colour_table.rb +0 -282
  75. data/lib/colours/commandline/menu.rb +0 -122
  76. data/lib/colours/constants/escape.rb +0 -22
  77. data/lib/colours/constants/file_constants.rb +0 -73
  78. data/lib/colours/constants/hash_ansi_colours.rb +0 -39
  79. data/lib/colours/constants/hash_simple_colours.rb +0 -148
  80. data/lib/colours/constants/misc.rb +0 -361
  81. data/lib/colours/constants/newline.rb +0 -14
  82. data/lib/colours/constants/registered_colour_methods.rb +0 -53
  83. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +0 -22
  84. data/lib/colours/toplevel_methods/autogenerate.rb +0 -310
  85. data/lib/colours/toplevel_methods/bold.rb +0 -41
  86. data/lib/colours/toplevel_methods/bold_and_italic.rb +0 -38
  87. data/lib/colours/toplevel_methods/cat.rb +0 -39
  88. data/lib/colours/toplevel_methods/clear_screen.rb +0 -18
  89. data/lib/colours/toplevel_methods/cliner.rb +0 -17
  90. data/lib/colours/toplevel_methods/col.rb +0 -54
  91. data/lib/colours/toplevel_methods/esystem.rb +0 -19
  92. data/lib/colours/toplevel_methods/html_colour_to_hex_value.rb +0 -41
  93. data/lib/colours/toplevel_methods/html_colourize.rb +0 -69
  94. data/lib/colours/toplevel_methods/is_on_roebe.rb +0 -16
  95. data/lib/colours/toplevel_methods/italic.rb +0 -110
  96. data/lib/colours/toplevel_methods/make_colour.rb +0 -28
  97. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +0 -336
  98. data/lib/colours/toplevel_methods/misc.rb +0 -226
  99. data/lib/colours/toplevel_methods/open_this_file.rb +0 -26
  100. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +0 -88
  101. data/lib/colours/toplevel_methods/random_value.rb +0 -37
  102. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +0 -112
  103. data/lib/colours/toplevel_methods/set_last_colour_used.rb +0 -32
  104. data/lib/colours/toplevel_methods/shell_file_containing_the_html_colours.sh +0 -148
  105. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +0 -36
  106. data/lib/colours/toplevel_methods/underline.rb +0 -130
  107. data/test/testing_the_colour_methods.rb +0 -36
  108. /data/doc/{COLOUR_CODES_CHART.md → colour_codes_chart/colour_codes_chart.md} +0 -0
@@ -1,226 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/misc.rb'
6
- # =========================================================================== #
7
- module Colours
8
-
9
- require 'colours/html_colours/html_colours.rb'
10
- require 'colours/toplevel_methods/esystem.rb'
11
- require 'colours/toplevel_methods/open_this_file.rb'
12
- require 'colours/toplevel_methods/remove_escape_sequence.rb'
13
-
14
- # ========================================================================= #
15
- # === Colours.colour_method_or_display_the_content_of_the_file_or_use_via_pipe
16
- #
17
- # This method has an awful name, but its core use case is simple.
18
- #
19
- # It will handle commandline instructions such as:
20
- #
21
- # orange Hey there
22
- # slateblue how are you doing?
23
- #
24
- # Usage example from within ruby:
25
- #
26
- # Colours.testing123('abc', :orange)
27
- #
28
- # ========================================================================= #
29
- def self.colour_method_or_display_the_content_of_the_file_or_use_via_pipe(
30
- i = ARGF,
31
- name_of_the_colour = $PROGRAM_NAME
32
- )
33
- require 'colours/autogenerated/support_for_html_colours.rb'
34
- # ======================================================================= #
35
- # === :read
36
- # ======================================================================= #
37
- if i.respond_to? :read
38
- i = i.read
39
- elsif i and File.exist?(i)
40
- i = File.read(i)
41
- end
42
- i = Colours.remove_trailing_end_from(i)
43
- if i.is_a? Array
44
- i = i.join(' ').strip
45
- end
46
- if name_of_the_colour
47
- if name_of_the_colour.respond_to?(:include?) and
48
- name_of_the_colour.include?('/')
49
- name_of_the_colour = File.basename(name_of_the_colour)
50
- end
51
- end
52
- name_of_the_colour = name_of_the_colour.to_sym
53
- return ::Colours::SupportForHTMLColours.send(name_of_the_colour, i)
54
- end
55
-
56
- # ========================================================================= #
57
- # === Colours.sanitize_line
58
- #
59
- # This method will replace one line with the proper R,G,B valid entries.
60
- # ========================================================================= #
61
- def self.sanitize_line(entry)
62
- all_potential_matches = entry.scan(/<(\w+)>/).flatten
63
- all_potential_matches.each {|substring|
64
- entry.gsub!(/<\/>/, rev)
65
- entry.gsub!(/<#{substring}>/, rgb_format(substring))
66
- }
67
- begin
68
- require 'roebe/modules/remove_html.rb'
69
- rescue LoadError; end
70
- if Object.const_defined?(:Roebe) and
71
- Roebe.respond_to?(:remove_html)
72
- entry = Roebe.remove_html[entry]
73
- end
74
- return entry
75
- end
76
-
77
- # ========================================================================= #
78
- # === Colours.read_and_display_this_file
79
- #
80
- # This method accepts a file path - in other words, the input should be
81
- # the location of a specific file on your filesystem - and then simply
82
- # reads in the content of said file via File.readlines().
83
- #
84
- # Content such as <slateblue> found in this file will be replaced
85
- # with the respective R,G,B substring value.
86
- #
87
- # In the test/ subdirectory there is an example file for this - have
88
- # a look there for more information.
89
- # ========================================================================= #
90
- def self.read_and_display_this_file(
91
- i = TEST_FILE
92
- )
93
- i = i.to_s
94
- if File.exist? i
95
- new_array = []
96
- data = File.readlines(i)
97
- data.each {|entry|
98
- # ======================================================================= #
99
- # Check whether the entry has a <> tag:
100
- # ======================================================================= #
101
- if entry.include?('<') and entry.include?('>') and
102
- entry.include?('</>')
103
- # ================================================================= #
104
- # Ok, we may assume that something like <slateblue> is there.
105
- # ================================================================= #
106
- entry = sanitize_line(entry)
107
- end
108
- new_array << entry
109
- }
110
- e new_array # For now we will simply output that modified Array.
111
- else
112
- e "Notice: The file at `#{sfile(i)}` does not exist."
113
- end
114
- end; self.instance_eval { alias read_file read_and_display_this_file } # === Colours.read_file
115
-
116
- # ========================================================================= #
117
- # === Colours.does_this_line_include_a_html_colour?
118
- #
119
- # This method can be used to determine whether the given input-string
120
- # contains a valid HTML colour or whether it does not.
121
- #
122
- # Returns: a boolean.
123
- #
124
- # Invocation examples:
125
- #
126
- # Colours.does_this_line_include_a_html_colour? "<green>yo there</green> <orange>getline() function</orange>" # => true
127
- # Colours.does_this_line_include_a_html_colour? "foo bar" # => false
128
- #
129
- # ========================================================================= #
130
- def self.does_this_line_include_a_html_colour?(
131
- line
132
- )
133
- html_colours?.any? {|entry|
134
- line.include? entry
135
- }
136
- end
137
-
138
- # ========================================================================= #
139
- # === Colours.convert_hex_to_rgb
140
- #
141
- # This method will convert e. g. #baf185 to [186, 241, 133]. Thus it
142
- # will return an Array, denoting the R, G, B values.
143
- #
144
- # How to do this conversion on your own?
145
- #
146
- # (1) Get the 2 left digits of the hex color code and convert
147
- # to decimal value to get the red color level.
148
- # (2) Get the 2 middle digits of the hex color code and
149
- # convert to decimal value to get the green color level.
150
- # (3) Get the 2 right digits of the hex color code and
151
- # convert to decimal value to get the blue color level.
152
- #
153
- # Usage example:
154
- #
155
- # Colours.convert_hex_to_rgb('#baf185') # => [186, 241, 133]
156
- #
157
- # ========================================================================= #
158
- def self.convert_hex_to_rgb(hex)
159
- if hex.is_a? Array
160
- hex = hex.first
161
- end
162
- hex = hex.to_s.dup
163
- hex.delete!('#') if hex.include? '#'
164
- array = [] # We will return this Array.
165
- r = hex[0,2].to_i(16)
166
- g = hex[2,2].to_i(16)
167
- b = hex[4,2].to_i(16)
168
- array << r << g << b
169
- return array
170
- end; self.instance_eval { alias hex_to_rgb convert_hex_to_rgb } # === Colours.hex_to_rgb
171
-
172
- # ========================================================================= #
173
- # === Colours.convert_hex_code_to_RGBA_array
174
- #
175
- # RGBA stands for "red, green, blue, alpha". Alpha indicates how
176
- # opaque each pixel is.
177
- #
178
- # The usual values for the alpha parameter, aka the last parameter,
179
- # is a number between 0.0 (which means "fully transparent") and
180
- # the number 1.0 (which means "not transparent at all").
181
- #
182
- # Note that this method is similar to Colours.convert_hex_to_rgb(hex),
183
- # but it has a fourth argument, aka A (for Alpha), on top of
184
- # the RGB values.
185
- #
186
- # Usage example:
187
- #
188
- # Colours.convert_hex_code_to_RGBA_array('#baf185') # => [186, 241, 133]
189
- #
190
- # ========================================================================= #
191
- def self.convert_hex_code_to_RGBA_array(
192
- i, default_alpha_value = 1.0
193
- )
194
- rgba_array = convert_hex_to_rgb(i)
195
- rgba_array << default_alpha_value
196
- return rgba_array
197
- end
198
-
199
- # ========================================================================= #
200
- # === Colours.reset_the_line
201
- #
202
- # This method will reset the current line. This can then be used in a
203
- # progress indicator application.
204
- # ========================================================================= #
205
- def self.reset_the_line
206
- STDOUT.write("\u001b[1000D") # Move to the left by 1000 characters. Aka reset.
207
- STDOUT.flush # This line will force the output to appear immediately,
208
- end
209
-
210
- end
211
-
212
- if __FILE__ == $PROGRAM_NAME
213
- # ========================================================================= #
214
- # Example code demonstrating the method defined above:
215
- # ========================================================================= #
216
- index = 1
217
- loop {
218
- Colours.reset_the_line
219
- print 'OK! '+
220
- Random.rand(11).to_s
221
- index += 1
222
- break if index == 50
223
- sleep 0.3
224
- }
225
- puts
226
- end
@@ -1,26 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/open_this_file.rb'
6
- # =========================================================================== #
7
- module Colours
8
-
9
- require 'colours/toplevel_methods/esystem.rb'
10
-
11
- # ========================================================================= #
12
- # === Colours.open_this_file
13
- # ========================================================================= #
14
- def open_this_file(
15
- shall_we_exit = false
16
- )
17
- case shall_we_exit
18
- when :then_exit
19
- shall_we_exit = true
20
- end
21
- _ = "bluefish #{__FILE__}"
22
- esystem(_)
23
- exit if shall_we_exit
24
- end
25
-
26
- end
@@ -1,88 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/prefer_this_colour_schemata.rb'
6
- # =========================================================================== #
7
- module Colours
8
-
9
- require 'colours/requires/require_yaml.rb'
10
- require 'colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb'
11
- require 'colours/autogenerated/support_for_html_colours.rb'
12
-
13
- # ========================================================================= #
14
- # === @prefer_this_colour_schemata
15
- #
16
- # The following Array ranks which colour schemata we will try to use.
17
- # More important entries should come on top.
18
- #
19
- # Konsole will be the default, normally, followed by the 256 colours; and
20
- # then the basic colours.
21
- #
22
- # Of course you can decide on your own via the .yml file, and other
23
- # methods that allow us to change this setting, but when it comes
24
- # to implementations such as for simp() or sfancy() then we will
25
- # honour the setting in the yaml file (if we use any colours at all,
26
- # that is). The yaml file is typically called
27
- # "prefer_this_colour_schemata.yml".
28
- # ========================================================================= #
29
- if File.exist? FILE_PREFER_THIS_COLOUR_SCHEMATA
30
- @prefer_this_colour_schemata = YAML.load_file(FILE_PREFER_THIS_COLOUR_SCHEMATA)
31
- end
32
-
33
- # ========================================================================= #
34
- # === @use_html_colours
35
- #
36
- # If the following variable is set to true then the HTML colours will
37
- # be used, if available. These are colours such as 'slateblue' or
38
- # 'crimson'.
39
- # ========================================================================= #
40
- @use_html_colours = false
41
-
42
- # ========================================================================= #
43
- # === @use_256_colours
44
- # ========================================================================= #
45
- @use_256_colours = false
46
-
47
- # ========================================================================= #
48
- # === @use_basic_colours
49
- # ========================================================================= #
50
- @use_basic_colours = false
51
-
52
- # ========================================================================= #
53
- # Next, we will set some other toplevel instance variables based on
54
- # the value of this yaml file.
55
- # ========================================================================= #
56
- if @prefer_this_colour_schemata
57
- first_entry = @prefer_this_colour_schemata[1]
58
- _second_entry = @prefer_this_colour_schemata[2]
59
- _third_entry = @prefer_this_colour_schemata[3]
60
-
61
- case first_entry
62
- # === :html_colours
63
- when :html_colours
64
- @use_html_colours = true
65
- # === :support_for_256_colours
66
- when :support_for_256_colours
67
- @use_256_colours = true
68
- # === :basic_colours
69
- when :basic_colours
70
- @use_basic_colours = true
71
- end
72
- end
73
-
74
- # ========================================================================= #
75
- # === Colours.prefer_which_colour_schemata?
76
- # ========================================================================= #
77
- def self.prefer_which_colour_schemata?
78
- @prefer_this_colour_schemata[1].to_sym if @prefer_this_colour_schemata
79
- end; self.instance_eval { alias prefer_which_colour_scheme? prefer_which_colour_schemata? } # === Colours.prefer_which_colour_scheme
80
-
81
- # ========================================================================= #
82
- # Designate @use_256_colours to true:
83
- # ========================================================================= #
84
- if prefer_which_colour_schemata? == :support_for_256_colours
85
- @use_256_colours = true
86
- end
87
-
88
- end
@@ -1,37 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/random_value.rb'
6
- # =========================================================================== #
7
- module Colours
8
-
9
- # ========================================================================= #
10
- # === Colours.random_value?
11
- #
12
- # We will obtain a random value between 0 and 255, hence why we will
13
- # use rand(256).
14
- # ========================================================================= #
15
- def self.random_value?
16
- rand(256)
17
- end; self.instance_eval { alias random_value random_value? } # === Colours.random_value
18
- self.instance_eval { alias rvalue random_value? } # === Colours.rvalue
19
- self.instance_eval { alias r? random_value? } # === Colours.r?
20
- self.instance_eval { alias g? random_value? } # === Colours.g?
21
- self.instance_eval { alias b? random_value? } # === Colours.b?
22
-
23
- # ========================================================================= #
24
- # === random_value
25
- #
26
- # We will obtain a random value between 0 and 255, hence why we will
27
- # use rand(256).
28
- # ========================================================================= #
29
- def random_value?
30
- Colours.random_value?
31
- end; alias rvalue random_value? # === rvalue
32
- alias random_value random_value? # === random_value
33
- alias r? random_value? # === r?
34
- alias g? random_value? # === g?
35
- alias b? random_value? # === b?
36
-
37
- end
@@ -1,112 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/remove_escape_sequence.rb'
6
- # Colours.remove_escape_sequence
7
- # =========================================================================== #
8
- module Colours
9
-
10
- require 'colours/constants/misc.rb'
11
-
12
- # ========================================================================= #
13
- # === Colours.remove_escape_sequence
14
- #
15
- # The method Colours.remove_escape_sequence() will remove all Ansi
16
- # Escape sequences from a given string.
17
- # ========================================================================= #
18
- def self.remove_escape_sequence(i = ARGV)
19
- if i.is_a? Array
20
- i = i.join("\n")
21
- end
22
- i = i.to_s.dup
23
- # ======================================================================= #
24
- # Iterate over the registered ansi-colours next.
25
- # ======================================================================= #
26
- ARRAY_REGISTERED_ANSI_COLOURS.each {|entry|
27
- if i.include? entry
28
- entry = Regexp.quote(entry)
29
- i.sub!(/#{entry}/, '')
30
- end
31
- # ===================================================================== #
32
- # Next, check for KDE konsole colours. We must use "" there, not ''.
33
- # ===================================================================== #
34
- if i.include?("\e[") and i =~ /\d+m/ # Such as: "\e[38;2;220;20;60m|"
35
- # =================================================================== #
36
- # The next regex will (hopefully) remove all escape-characters
37
- # from the given String.
38
- # =================================================================== #
39
- regex_for_html_colours = # Detect entries such as: \e[38;2;106;90;205m
40
- /(\e\[\d{2};\d{1};\d{3};\d{1,2};\d{3}m)/ # See: https://rubular.com/r/tG3XeOK5NPsfmI
41
- i.gsub!(regex_for_html_colours, '')
42
- # =================================================================== #
43
- # See: https://rubular.com/r/SdS28fAGSxIELn
44
- # =================================================================== #
45
- # /(\\e\[\d{1,2};?\d{1,2};?\d{0,3};?\d{0,3};?\d{1,2}m|\\e\[\d{0,2}m|\\e\[K|\\e\[\d{0,2};\d{0,2}m|(\\e\[.+\dm)|\\e\[0;37m)/
46
- [
47
- /\e\[\d{1,2};?\d{1,2};?\d{0,3};?\d{0,3};?\d{1,2}m/,
48
- /\\e\[\d{0,2}m|\\e\[K|\\e\[\d{0,2};\d{0,2}m/,
49
- /\\e\[.+\dm/,
50
- /\\e\[0;37m/
51
- ].each {|regex_to_use|
52
- i.gsub!(regex_to_use, '')
53
- }
54
- end
55
- }
56
- return i
57
- end; self.instance_eval { alias remove remove_escape_sequence } # === Colours.remove
58
- self.instance_eval { alias remove_escape_sequences remove_escape_sequence } # === Colours.remove_escape_sequences
59
- self.instance_eval { alias remove_colours remove_escape_sequence } # === Colours.remove_colours
60
- self.instance_eval { alias escape remove_escape_sequence } # === Colours.escape
61
-
62
- # ========================================================================= #
63
- # === Colours.remove_trailing_end_from
64
- #
65
- # The second argument to this method can be the escape sequence that you
66
- # wish to remove.
67
- #
68
- # Invocation example:
69
- #
70
- # x = Colours.remove_trailing_end_from("\e[38;2;70;130;180m\e[0;37m") # => "\e[38;2;70;130;180m"
71
- #
72
- # ========================================================================= #
73
- def self.remove_trailing_end_from(
74
- i,
75
- remove_this_escape_sequence = revert?
76
- )
77
- quoted = Regexp.quote(remove_this_escape_sequence)
78
- # ======================================================================= #
79
- # Anchor it at the end via $.
80
- # ======================================================================= #
81
- return i.sub(
82
- /#{quoted}$/, ''
83
- )
84
- end; self.instance_eval { alias remove_trailing_escape_part remove_trailing_end_from } # === Colours.remove_trailing_escape_part
85
- self.instance_eval { alias remove_trailing_ansii_escape_code remove_trailing_end_from } # === Colours.remove_trailing_ansii_escape_code
86
- self.instance_eval { alias remove_trailing_ANSII_escape_code remove_trailing_end_from } # === Colours.remove_trailing_ANSII_escape_code
87
- self.instance_eval { alias remove_trailing_escape_code remove_trailing_end_from } # === Colours.remove_trailing_escape_code
88
- self.instance_eval { alias remove_trailing_code remove_trailing_end_from } # === Colours.remove_trailing_code
89
-
90
- end
91
-
92
- if __FILE__ == $PROGRAM_NAME
93
- alias e puts
94
- begin
95
- require 'colours/autoinclude'
96
- rescue LoadError; e 'the colours gem is not available.'; end
97
- include Colours
98
- e
99
- e 'Next testing an escape sequence (which will be shown via pp only):'
100
- e
101
- x = "\e[01m\e[Kcc1:\e[m\e[K \e[01;35m\e[Kwarning: \e[m\e[K-Wabi won't warn about anything [\e[01;35m\e[K-Wabi\e[m\e[K]
102
-
103
- A\e[38;2;220;20;60m|AGCTT"
104
- pp x
105
- e
106
- x = Colours.remove_escape_sequence(x)
107
- e
108
- pp x
109
- e x
110
- pp Colours.remove_escape_sequences(Colours.slateblue('Hello world!')) # => "\e[38;2;106;90;205mHello world!"
111
- p Colours.slateblue('Hello world!') # => "\e[38;2;106;90;205mHello world!\e[0;37m"
112
- end
@@ -1,32 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'colours/toplevel_methods/set_last_colour_used.rb'
6
- # =========================================================================== #
7
- module Colours
8
-
9
- # ========================================================================= #
10
- # === @last_colour_used
11
- #
12
- # This instance variable keeps track what the last colour used was.
13
- # ========================================================================= #
14
- @last_colour_used = nil
15
-
16
- # ========================================================================= #
17
- # === last_colour_used?
18
- #
19
- # Tell us which colour was used last.
20
- # ========================================================================= #
21
- def last_colour_used?
22
- @last_colour_used.to_s # Always required a string.
23
- end
24
-
25
- # ========================================================================= #
26
- # === Colours.set_last_colour_used
27
- # ========================================================================= #
28
- def self.set_last_colour_used(i)
29
- @last_colour_used = i
30
- end
31
-
32
- end
@@ -1,148 +0,0 @@
1
- # This is a shell file that contains the HTML colours
2
- export ALICEBLUE="\e[38;2;240;248;255m"
3
- export ANTIQUEWHITE="\e[38;2;250;235;215m"
4
- export AQUA="\e[38;2;0;255;255m"
5
- export AQUAMARINE="\e[38;2;127;255;212m"
6
- export AZURE="\e[38;2;240;255;255m"
7
- export BEIGE="\e[38;2;245;245;220m"
8
- export BISQUE="\e[38;2;255;228;196m"
9
- export BLACK="\e[38;2;0;0;0m"
10
- export BLANCHEDALMOND="\e[38;2;255;235;205m"
11
- export BLUE="\e[38;2;0;0;255m"
12
- export BLUEVIOLET="\e[38;2;138;43;226m"
13
- export BROWN="\e[38;2;165;42;42m"
14
- export BURLYWOOD="\e[38;2;222;184;135m"
15
- export CADETBLUE="\e[38;2;95;158;160m"
16
- export CHARTREUSE="\e[38;2;127;255;0m"
17
- export CHOCOLATE="\e[38;2;210;105;30m"
18
- export CORAL="\e[38;2;255;127;80m"
19
- export CORNFLOWERBLUE="\e[38;2;100;149;237m"
20
- export CORNSILK="\e[38;2;255;248;220m"
21
- export CRIMSON="\e[38;2;220;20;60m"
22
- export CYAN="\e[38;2;0;255;255m"
23
- export DARKBLUE="\e[38;2;0;0;139m"
24
- export DARKCYAN="\e[38;2;0;139;139m"
25
- export DARKGOLDENROD="\e[38;2;184;134;11m"
26
- export DARKGRAY="\e[38;2;169;169;169m"
27
- export DARKGREEN="\e[38;2;0;100;0m"
28
- export DARKGREY="\e[38;2;169;169;169m"
29
- export DARKKHAKI="\e[38;2;189;183;107m"
30
- export DARKMAGENTA="\e[38;2;139;0;139m"
31
- export DARKOLIVEGREEN="\e[38;2;85;107;47m"
32
- export DARKORANGE="\e[38;2;255;140;0m"
33
- export DARKORCHID="\e[38;2;153;50;204m"
34
- export DARKRED="\e[38;2;139;0;0m"
35
- export DARKSALMON="\e[38;2;233;150;122m"
36
- export DARKSEAGREEN="\e[38;2;143;188;143m"
37
- export DARKSLATEBLUE="\e[38;2;72;61;139m"
38
- export DARKSLATEGRAY="\e[38;2;47;79;79m"
39
- export DARKSLATEGREY="\e[38;2;47;79;79m"
40
- export DARKTURQUOISE="\e[38;2;0;206;209m"
41
- export DARKVIOLET="\e[38;2;148;0;211m"
42
- export DEEPPINK="\e[38;2;255;20;147m"
43
- export DEEPSKYBLUE="\e[38;2;0;191;255m"
44
- export DIMGRAY="\e[38;2;105;105;105m"
45
- export DIMGREY="\e[38;2;105;105;105m"
46
- export DODGERBLUE="\e[38;2;30;144;255m"
47
- export FIREBRICK="\e[38;2;178;34;34m"
48
- export FLORALWHITE="\e[38;2;255;250;240m"
49
- export FORESTGREEN="\e[38;2;34;139;34m"
50
- export FUCHSIA="\e[38;2;255;0;255m"
51
- export GAINSBORO="\e[38;2;220;220;220m"
52
- export GHOSTWHITE="\e[38;2;248;248;255m"
53
- export GOLD="\e[38;2;255;215;0m"
54
- export GOLDENROD="\e[38;2;218;165;32m"
55
- export GRAY="\e[38;2;128;128;128m"
56
- export GREY="\e[38;2;128;128;128m"
57
- export GREEN="\e[38;2;0;128;0m"
58
- export GREENYELLOW="\e[38;2;173;255;47m"
59
- export HONEYDEW="\e[38;2;240;255;240m"
60
- export HOTPINK="\e[38;2;255;105;180m"
61
- export INDIANRED="\e[38;2;205;92;92m"
62
- export INDIGO="\e[38;2;75;0;130m"
63
- export IVORY="\e[38;2;255;255;240m"
64
- export KHAKI="\e[38;2;240;230;140m"
65
- export LAVENDER="\e[38;2;230;230;250m"
66
- export LAVENDERBLUSH="\e[38;2;255;240;245m"
67
- export LAWNGREEN="\e[38;2;124;252;0m"
68
- export LEMONCHIFFON="\e[38;2;255;250;205m"
69
- export LIGHTBLUE="\e[38;2;173;216;230m"
70
- export LIGHTCORAL="\e[38;2;240;128;128m"
71
- export LIGHTCYAN="\e[38;2;224;255;255m"
72
- export LIGHTGOLDENRODYELLOW="\e[38;2;250;250;210m"
73
- export LIGHTGRAY="\e[38;2;211;211;211m"
74
- export LIGHTGREY="\e[38;2;211;211;211m"
75
- export LIGHTGREEN="\e[38;2;144;238;144m"
76
- export LIGHTPINK="\e[38;2;255;182;193m"
77
- export LIGHTSALMON="\e[38;2;255;160;122m"
78
- export LIGHTSEAGREEN="\e[38;2;32;178;170m"
79
- export LIGHTSKYBLUE="\e[38;2;135;206;250m"
80
- export LIGHTSLATEGRAY="\e[38;2;119;136;153m"
81
- export LIGHTSLATEGREY="\e[38;2;119;136;153m"
82
- export LIGHTSTEELBLUE="\e[38;2;176;196;222m"
83
- export LIGHTYELLOW="\e[38;2;255;255;224m"
84
- export LIME="\e[38;2;0;255;0m"
85
- export LIMEGREEN="\e[38;2;50;205;50m"
86
- export LINEN="\e[38;2;250;240;230m"
87
- export MAGENTA="\e[38;2;255;0;255m"
88
- export MAROON="\e[38;2;128;0;0m"
89
- export MEDIUMAQUAMARINE="\e[38;2;102;205;170m"
90
- export MEDIUMBLUE="\e[38;2;0;0;205m"
91
- export MEDIUMORCHID="\e[38;2;186;85;211m"
92
- export MEDIUMPURPLE="\e[38;2;147;112;219m"
93
- export MEDIUMSEAGREEN="\e[38;2;60;179;113m"
94
- export MEDIUMSLATEBLUE="\e[38;2;123;104;238m"
95
- export MEDIUMSPRINGGREEN="\e[38;2;0;250;154m"
96
- export MEDIUMTURQUOISE="\e[38;2;72;209;204m"
97
- export MEDIUMVIOLETRED="\e[38;2;199;21;133m"
98
- export MIDNIGHTBLUE="\e[38;2;25;25;112m"
99
- export MINTCREAM="\e[38;2;245;255;250m"
100
- export MISTYROSE="\e[38;2;255;228;225m"
101
- export MOCCASIN="\e[38;2;255;228;181m"
102
- export NAVAJOWHITE="\e[38;2;255;222;173m"
103
- export NAVY="\e[38;2;0;0;128m"
104
- export OLDLACE="\e[38;2;253;245;230m"
105
- export OLIVE="\e[38;2;128;128;0m"
106
- export OLIVEDRAB="\e[38;2;107;142;35m"
107
- export ORANGE="\e[38;2;255;165;0m"
108
- export ORANGERED="\e[38;2;255;69;0m"
109
- export ORCHID="\e[38;2;218;112;214m"
110
- export PALEGOLDENROD="\e[38;2;238;232;170m"
111
- export PALEGREEN="\e[38;2;152;251;152m"
112
- export PALETURQUOISE="\e[38;2;175;238;238m"
113
- export PALEVIOLETRED="\e[38;2;219;112;147m"
114
- export PAPAYAWHIP="\e[38;2;255;239;213m"
115
- export PEACHPUFF="\e[38;2;255;218;185m"
116
- export PERU="\e[38;2;205;133;63m"
117
- export PINK="\e[38;2;255;192;203m"
118
- export PLUM="\e[38;2;221;160;221m"
119
- export POWDERBLUE="\e[38;2;176;224;230m"
120
- export PURPLE="\e[38;2;128;0;128m"
121
- export RED="\e[38;2;255;0;0m"
122
- export ROSYBROWN="\e[38;2;188;143;143m"
123
- export ROYALBLUE="\e[38;2;65;105;225m"
124
- export SADDLEBROWN="\e[38;2;139;69;19m"
125
- export SALMON="\e[38;2;250;128;114m"
126
- export SANDYBROWN="\e[38;2;244;164;96m"
127
- export SEAGREEN="\e[38;2;46;139;87m"
128
- export SEASHELL="\e[38;2;255;245;238m"
129
- export SIENNA="\e[38;2;160;82;45m"
130
- export SILVER="\e[38;2;192;192;192m"
131
- export SKYBLUE="\e[38;2;135;206;235m"
132
- export SLATEBLUE="\e[38;2;106;90;205m"
133
- export SLATEGRAY="\e[38;2;112;128;144m"
134
- export SLATEGREY="\e[38;2;112;128;144m"
135
- export SNOW="\e[38;2;255;250;250m"
136
- export SPRINGGREEN="\e[38;2;0;255;127m"
137
- export STEELBLUE="\e[38;2;70;130;180m"
138
- export TAN="\e[38;2;210;180;140m"
139
- export TEAL="\e[38;2;0;128;128m"
140
- export THISTLE="\e[38;2;216;191;216m"
141
- export TOMATO="\e[38;2;255;99;71m"
142
- export TURQUOISE="\e[38;2;64;224;208m"
143
- export VIOLET="\e[38;2;238;130;238m"
144
- export WHEAT="\e[38;2;245;222;179m"
145
- export WHITE="\e[38;2;255;255;255m"
146
- export WHITESMOKE="\e[38;2;245;245;245m"
147
- export YELLOW="\e[38;2;255;255;0m"
148
- export YELLOWGREEN="\e[38;2;154;205;50m"