colours 0.5.55

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.

Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +890 -0
  4. data/bin/colours +7 -0
  5. data/bin/html_colour_to_hex_value +7 -0
  6. data/bin/html_colourize +7 -0
  7. data/bin/print_rainbow_line +7 -0
  8. data/bin/rainbow_colours +7 -0
  9. data/bin/remove_ansii_escape_sequences +7 -0
  10. data/colours.gemspec +76 -0
  11. data/doc/COLOUR_CODES_CHART.md +28 -0
  12. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
  13. data/doc/README.gen +862 -0
  14. data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
  15. data/lib/colours/autoalias_e.rb +10 -0
  16. data/lib/colours/autogenerated/README.md +2 -0
  17. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  18. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  19. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
  20. data/lib/colours/autoinclude.rb +14 -0
  21. data/lib/colours/base/base.rb +23 -0
  22. data/lib/colours/basic_colours/README.md +4 -0
  23. data/lib/colours/basic_colours/basic_colours.rb +279 -0
  24. data/lib/colours/colour_methods/README.md +11 -0
  25. data/lib/colours/colour_methods/default_colour.rb +66 -0
  26. data/lib/colours/colour_methods/sargument.rb +70 -0
  27. data/lib/colours/colour_methods/scomments.rb +105 -0
  28. data/lib/colours/colour_methods/sdir.rb +66 -0
  29. data/lib/colours/colour_methods/sfancy.rb +84 -0
  30. data/lib/colours/colour_methods/sfile.rb +71 -0
  31. data/lib/colours/colour_methods/simportant.rb +92 -0
  32. data/lib/colours/colour_methods/snormal.rb +66 -0
  33. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  34. data/lib/colours/colour_methods/swarn.rb +76 -0
  35. data/lib/colours/colour_table/README.md +3 -0
  36. data/lib/colours/colour_table/colour_table.rb +275 -0
  37. data/lib/colours/colours_e_autoinclude.rb +9 -0
  38. data/lib/colours/commandline/README.md +2 -0
  39. data/lib/colours/commandline/commandline.rb +44 -0
  40. data/lib/colours/commandline/menu.rb +111 -0
  41. data/lib/colours/constants/colour_constants.rb +299 -0
  42. data/lib/colours/constants/file_constants.rb +72 -0
  43. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  44. data/lib/colours/constants/misc.rb +59 -0
  45. data/lib/colours/constants/newline.rb +14 -0
  46. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  47. data/lib/colours/e/README.md +13 -0
  48. data/lib/colours/e/autoinclude.rb +11 -0
  49. data/lib/colours/e/e.rb +35 -0
  50. data/lib/colours/e.rb +5 -0
  51. data/lib/colours/eparse/eparse.rb +77 -0
  52. data/lib/colours/everything/autoinclude.rb +11 -0
  53. data/lib/colours/html_colours/README.md +1 -0
  54. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  55. data/lib/colours/html_colours/hash_html_colours.rb +63 -0
  56. data/lib/colours/html_colours/html_colourize.rb +48 -0
  57. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  58. data/lib/colours/html_colours/misc.rb +186 -0
  59. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  60. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  61. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  62. data/lib/colours/module.rb +11 -0
  63. data/lib/colours/project/project_base_directory.rb +22 -0
  64. data/lib/colours/rainbow_colours/README.md +2 -0
  65. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  66. data/lib/colours/rainbow_colours/constants.rb +30 -0
  67. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  68. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  69. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  70. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  71. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  72. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  73. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  74. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  75. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  76. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  77. data/lib/colours/requires/require_commandline.rb +7 -0
  78. data/lib/colours/requires/require_eparse.rb +11 -0
  79. data/lib/colours/requires/require_rgb.rb +5 -0
  80. data/lib/colours/requires/require_sdir.rb +5 -0
  81. data/lib/colours/requires/require_sfile.rb +5 -0
  82. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  83. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  84. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  85. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  86. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  87. data/lib/colours/requires/require_the_constants.rb +11 -0
  88. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  89. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  90. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  91. data/lib/colours/revert/revert.rb +106 -0
  92. data/lib/colours/rgb/rgb.rb +547 -0
  93. data/lib/colours/testing/README.md +2 -0
  94. data/lib/colours/testing/testing.rb +157 -0
  95. data/lib/colours/toplevel_methods/bold.rb +35 -0
  96. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  97. data/lib/colours/toplevel_methods/cat.rb +39 -0
  98. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  99. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  100. data/lib/colours/toplevel_methods/col.rb +56 -0
  101. data/lib/colours/toplevel_methods/e.rb +63 -0
  102. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  103. data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
  104. data/lib/colours/toplevel_methods/html_colourize.rb +64 -0
  105. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  106. data/lib/colours/toplevel_methods/italic.rb +104 -0
  107. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  108. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +325 -0
  109. data/lib/colours/toplevel_methods/misc.rb +129 -0
  110. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  111. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
  112. data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
  113. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  114. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +112 -0
  115. data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
  116. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  117. data/lib/colours/toplevel_methods/underline.rb +114 -0
  118. data/lib/colours/toplevel_methods/use_colours.rb +290 -0
  119. data/lib/colours/utility_scripts/README.md +2 -0
  120. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  121. data/lib/colours/version/version.rb +25 -0
  122. data/lib/colours/yaml/256_colours.yml +277 -0
  123. data/lib/colours/yaml/basic_colours.yml +23 -0
  124. data/lib/colours/yaml/html_colours.yml +835 -0
  125. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  126. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  127. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
  128. data/lib/colours.rb +5 -0
  129. data/test/test.html +18 -0
  130. data/test/testing_256_colours_support.rb +29 -0
  131. data/test/testing_col.rb +10 -0
  132. data/test/testing_colours.rb +95 -0
  133. data/test/testing_colours_e.rb +13 -0
  134. data/test/testing_eparse.rb +13 -0
  135. data/test/testing_kde_colour_palette.rb +30 -0
  136. data/test/testing_konsole_submodule.rb +226 -0
  137. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  138. data/test/testing_rgb_to_hex.rb +32 -0
  139. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  140. data/test/testing_the_colour_methods.rb +36 -0
  141. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  142. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  143. data/test/testing_whether_colours_will_be_used.rb +7 -0
  144. metadata +226 -0
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/kde_colour_palette/kde_colour_palette.rb'
6
+ # =========================================================================== #
7
+ require 'yaml'
8
+ require 'colours/constants/file_constants.rb'
9
+ require 'colours/rgb/rgb.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours::KDE_COLOUR_PALETTE
15
+ #
16
+ # The format for the following Hash is this:
17
+ # - The key is the name of the colour at hand
18
+ # - There are two values per name. The first is the hex value,
19
+ # and the second is the R,G,B value stored as a Hash.
20
+ # ========================================================================= #
21
+ if File.exist? FILE_KDE_COLOUR_PALETTE
22
+ KDE_COLOUR_PALETTE = YAML.load_file(FILE_KDE_COLOUR_PALETTE)
23
+ else
24
+ KDE_COLOUR_PALETTE = {}
25
+ end
26
+
27
+ # ========================================================================= #
28
+ # Next, we will batch-define the KDE colour palette as class methods.
29
+ #
30
+ # To test this, you can try:
31
+ #
32
+ # Colours.kde_colour_palette_icon_yellow 'Hello world!'
33
+ #
34
+ # ========================================================================= #
35
+ KDE_COLOUR_PALETTE.keys.each {|this_key|
36
+ short_symbol_name_for_the_key = this_key.downcase.tr(' ','_').to_sym
37
+ use_this_as_method_name = ('kde_colour_palette_'+short_symbol_name_for_the_key.to_s).to_sym
38
+ unless Colours.respond_to? use_this_as_method_name
39
+ self.class.class_eval {
40
+ define_method(use_this_as_method_name) {|output_this_text = ''| # Allow input.
41
+ Colours.return_this_via_kde_colour_palette(output_this_text, short_symbol_name_for_the_key)
42
+ }
43
+ # =================================================================== #
44
+ # The next enables colours such as:
45
+ #
46
+ # Colours.pimpinella 'Hello cats!'
47
+ #
48
+ # =================================================================== #
49
+ define_method(short_symbol_name_for_the_key.to_sym) {|output_this_text = ''| # Allow input.
50
+ Colours.return_this_via_kde_colour_palette(output_this_text, short_symbol_name_for_the_key.to_sym)
51
+ }
52
+ # =================================================================== #
53
+ # The next enables colours such as:
54
+ # Colours.epimpinella 'Hello cats!'
55
+ # =================================================================== #
56
+ define_method(('e'+short_symbol_name_for_the_key.to_s).to_sym) {|output_this_text = ''| # Allow input.
57
+ Colours.write_this_via_kde_colour_palette(output_this_text, short_symbol_name_for_the_key.to_sym)
58
+ }
59
+ }
60
+ end
61
+ }
62
+
63
+ # ========================================================================= #
64
+ # === Colours.return_this_via_kde_colour_palette
65
+ #
66
+ # To invoke this method, try:
67
+ #
68
+ # Colours.return_this_via_kde_colour_palette 'Hello world!'
69
+ # Colours.return_this_via_kde_colour_palette 'Hello world!', :random
70
+ # Colours.return_this_via_kde_colour_palette 'Hello world!', :plasma_blue
71
+ #
72
+ # ========================================================================= #
73
+ def self.return_this_via_kde_colour_palette(
74
+ this_text = '',
75
+ this_colour = 'Pimpinella'
76
+ )
77
+ use_this_rgb_value_array = []
78
+ case this_colour
79
+ when :random # Pick a random colour in this case.
80
+ this_colour = KDE_COLOUR_PALETTE.keys.sample
81
+ else
82
+ if this_colour.is_a? Symbol
83
+ if this_colour.to_s.include? '_'
84
+ # ================================================================= #
85
+ # In this case, try to convert it.
86
+ # ================================================================= #
87
+ this_colour = this_colour.to_s.split('_').map(&:capitalize).join(' ')
88
+ else
89
+ this_colour = this_colour.to_s.capitalize
90
+ end
91
+ end
92
+ end
93
+ if KDE_COLOUR_PALETTE.has_key? this_colour
94
+ use_this_rgb_value_array = KDE_COLOUR_PALETTE[this_colour][1]
95
+ end
96
+ # ======================================================================= #
97
+ # Finally return the text, in the corresponding colour at hand.
98
+ # ======================================================================= #
99
+ return Colours.rgb_value_as_escape_code_string(use_this_rgb_value_array)+
100
+ this_text+
101
+ rev
102
+ end
103
+
104
+ # ========================================================================= #
105
+ # === Colours.write_this_via_kde_colour_palette
106
+ #
107
+ # To invoke this method, try:
108
+ # Colours.write_this_via_kde_colour_palette 'Hello world!'
109
+ # Colours.write_this_via_kde_colour_palette 'Hello world!', :random
110
+ # Colours.write_this_via_kde_colour_palette 'Hello world!', :plasma_blue
111
+ # ========================================================================= #
112
+ def self.write_this_via_kde_colour_palette(
113
+ this_text = '',
114
+ this_colour = 'Pimpinella',
115
+ append_newline = true
116
+ )
117
+ result = Colours.return_this_via_kde_colour_palette(this_text, this_colour)
118
+ if append_newline
119
+ result << "#{N}"
120
+ end
121
+ print result
122
+ end
123
+
124
+ end
125
+
126
+ if __FILE__ == $PROGRAM_NAME
127
+ pp Colours::KDE_COLOUR_PALETTE.keys
128
+ end
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb'
6
+ # =========================================================================== #
7
+ require 'colours/constants/colour_constants.rb'
8
+ require 'colours/constants/hash_simple_colours.rb'
9
+
10
+ module Colours
11
+
12
+ # ========================================================================= #
13
+ # === Colours.map_symbol_to_corresponding_colour (menu tag)
14
+ #
15
+ # This method will accept a symbol as input, such as :bold_blue, and
16
+ # return the corresponding CONSTANT (or rather, the value this constant
17
+ # refers to). This allows us to "map" the respective symbol to the
18
+ # corresponding constant.
19
+ #
20
+ # For example, the Symbol :bold_blue will correspond to the BOLD_BLUE
21
+ # constant. The Symbol :bold_green will correspond to the BOLD_GREEN
22
+ # constant (or COLOUR_BOLD_GREEN; there are some "aliases" on the
23
+ # constant-level as well). This constant thus represents the symbol
24
+ # at hand.
25
+ #
26
+ # Take note that this method here has several aliases:
27
+ #
28
+ # Colours.translate()
29
+ # Colours.beautify()
30
+ # Colours.convert()
31
+ # Colours.parse()
32
+ # Colours.map_colour_to_constant()
33
+ #
34
+ # This is partially due to historic reasons; and partially simply
35
+ # because some of them are shorter and hence easier to type.
36
+ #
37
+ # Usage example for this method:
38
+ #
39
+ # Colours.beautiful(:bold_blue)
40
+ #
41
+ # ========================================================================= #
42
+ def self.map_symbol_to_corresponding_colour(i)
43
+ if i.is_a? String # Handle Strings as well.
44
+ # ===================================================================== #
45
+ # === random
46
+ # ===================================================================== #
47
+ if i == 'random' # Fetch a random entry in this case.
48
+ i = MAIN_COLOURS.sample
49
+ end
50
+ i = i.tr(' ','_').to_sym
51
+ end
52
+ case i # case tag
53
+ # ======================================================================= #
54
+ # === :default
55
+ # ======================================================================= #
56
+ when :default,
57
+ :si,
58
+ :default_colour,
59
+ :defaultcolour,
60
+ :normal,
61
+ nil
62
+ return DEFAULT_COLOUR
63
+ # ======================================================================= #
64
+ # === :bold_green
65
+ # ======================================================================= #
66
+ when :bold_green,
67
+ :boldgreen,
68
+ :bright_green,
69
+ :greenb,
70
+ :lightgreen
71
+ return BOLD_GREEN
72
+ # ======================================================================= #
73
+ # === :bold_brown
74
+ # ======================================================================= #
75
+ when :bold_brown,
76
+ :bbrown,
77
+ :gold,
78
+ :saddlebrown
79
+ return BOLD_BROWN
80
+ # ======================================================================= #
81
+ # === :white
82
+ # ======================================================================= #
83
+ when :white,
84
+ :whitebonblack
85
+ return WHITE
86
+ # ======================================================================= #
87
+ # === :red
88
+ # ======================================================================= #
89
+ when :red
90
+ return RED
91
+ # ======================================================================= #
92
+ # === :light_grey
93
+ # ======================================================================= #
94
+ when :light_grey,
95
+ :grey
96
+ return COLOUR_LIGHT_GREY
97
+ # ======================================================================= #
98
+ # === :pink
99
+ # ======================================================================= #
100
+ when :pink,
101
+ :bright_magenta
102
+ return BRIGHT_MAGENTA
103
+ # ======================================================================= #
104
+ # === :bright_cyan
105
+ # ======================================================================= #
106
+ when :bright_cyan,
107
+ :cyanb,
108
+ :cyan
109
+ return BOLD_CYAN
110
+ # ======================================================================= #
111
+ # === :brown
112
+ # ======================================================================= #
113
+ when :brown
114
+ return BROWN
115
+ # ======================================================================= #
116
+ # === :yellow
117
+ # ======================================================================= #
118
+ when :yellow,
119
+ :yel
120
+ return YELLOW
121
+ # ======================================================================= #
122
+ # === :green
123
+ # ======================================================================= #
124
+ when :green,
125
+ :greengreen
126
+ return GREEN
127
+ # ======================================================================= #
128
+ # === :blue
129
+ # ======================================================================= #
130
+ when :blue
131
+ return BLUE
132
+ # ======================================================================= #
133
+ # === :magenta
134
+ # ======================================================================= #
135
+ when :magenta
136
+ return MAGENTA
137
+ # ======================================================================= #
138
+ # === :teal
139
+ # ======================================================================= #
140
+ when :teal
141
+ return TEAL
142
+ # ======================================================================= #
143
+ # === :revert
144
+ # ======================================================================= #
145
+ when :revert,
146
+ :reset,
147
+ :clear
148
+ return REVERT
149
+ # ======================================================================= #
150
+ # === :bold_red
151
+ # ======================================================================= #
152
+ when :bold_red,
153
+ :boldred,
154
+ :bright_red,
155
+ :lightred,
156
+ :redb
157
+ return BOLD_RED
158
+ # ======================================================================= #
159
+ # === :lightblue
160
+ # ======================================================================= #
161
+ when :lightblue
162
+ return LIGHTBLUE
163
+ # ======================================================================= #
164
+ # === :bold_yellow
165
+ # ======================================================================= #
166
+ when :bold_yellow,
167
+ :boldyellow,
168
+ :yelb,
169
+ :bright_yellow,
170
+ :byellow
171
+ return BOLD_YELLOW
172
+ # ======================================================================= #
173
+ # === :bold_blue
174
+ # ======================================================================= #
175
+ when :bold_blue,
176
+ :boldblue,
177
+ :bright_blue,
178
+ :blueb
179
+ return BOLD_BLUE
180
+ # ======================================================================= #
181
+ # === :bold_white
182
+ # ======================================================================= #
183
+ when :bold_white,
184
+ :boldwhite,
185
+ :bright_white
186
+ return BOLD_WHITE
187
+ # ======================================================================= #
188
+ # === :black
189
+ # ======================================================================= #
190
+ when :black,
191
+ :bold_black,
192
+ :boldblack,
193
+ :bright_black
194
+ return COLOUR_BLACK
195
+ else
196
+ puts "Unknown symbol given as input: #{i}"
197
+ pp i
198
+ end
199
+ i # else return the input-argument again.
200
+ end; self.instance_eval { alias beautiful map_symbol_to_corresponding_colour } # === Colours.beautiful
201
+ self.instance_eval { alias beautify map_symbol_to_corresponding_colour } # === Colours.beautify
202
+ self.instance_eval { alias translate map_symbol_to_corresponding_colour } # === Colours.translate
203
+ self.instance_eval { alias convert map_symbol_to_corresponding_colour } # === Colours.convert
204
+ self.instance_eval { alias parse map_symbol_to_corresponding_colour } # === Colours.parse
205
+ self.instance_eval { alias map_colour_to_constant map_symbol_to_corresponding_colour } # === Colours.map_colour_to_constant
206
+ self.instance_eval { alias map_this_symbol map_symbol_to_corresponding_colour } # === Colours.map_this_symbol
207
+ self.instance_eval { alias map_symbol_to_colour map_symbol_to_corresponding_colour } # === Colours.map_symbol_to_colour
208
+ self.instance_eval { alias corresponding_colour? map_symbol_to_corresponding_colour } # === Colours.corresponding_colour?
209
+
210
+ # ========================================================================= #
211
+ # === map_symbol_to_corresponding_colour
212
+ #
213
+ # This maps a colour (string) to the respective constant.
214
+ # ========================================================================= #
215
+ def map_symbol_to_corresponding_colour(i)
216
+ ::Colours.map_symbol_to_corresponding_colour(i)
217
+ end; alias map_colour_to_constant map_symbol_to_corresponding_colour # === map_colour_to_constant
218
+
219
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/module.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ include Colours::E
10
+
11
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/project/project_base_directory.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours::PROJECT_BASE_DIRECTORY
11
+ # ========================================================================= #
12
+ PROJECT_BASE_DIRECTORY =
13
+ File.absolute_path("#{__dir__}/..")+'/'
14
+
15
+ # ========================================================================= #
16
+ # === Colours.project_base_dir?
17
+ # ========================================================================= #
18
+ def self.project_base_dir?
19
+ PROJECT_BASE_DIRECTORY
20
+ end
21
+
22
+ end
@@ -0,0 +1,2 @@
1
+ This directory contains code that can be used for displaying
2
+ text in a rainbow-colourspray variant, on the commandline.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module Colours
6
+
7
+ module RainbowColours
8
+
9
+ # ========================================================================= #
10
+ # === Colours::RainbowColours.check_for_trollop_being_available_or_exit
11
+ # ========================================================================= #
12
+ def self.check_for_trollop_being_available_or_exit
13
+ # ======================================================================= #
14
+ # First check whether the user has the Trollop gem installed.
15
+ # ======================================================================= #
16
+ unless Object.const_defined? :Trollop
17
+ e
18
+ e 'Trollop is not installed. Please install it via:'
19
+ e
20
+ e ' gem install trollop'
21
+ e
22
+ exit
23
+ end
24
+ end
25
+
26
+ end; end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/rainbow_colours/constants.rb'
6
+ # =========================================================================== #
7
+ require 'colours/constants/newline.rb'
8
+
9
+ module Colours
10
+
11
+ module RainbowColours # === Colours::RainbowColours
12
+
13
+ # ========================================================================= #
14
+ # === DEFAULT_RAINBOW_SPREAD
15
+ # ========================================================================= #
16
+ DEFAULT_RAINBOW_SPREAD = 3.0
17
+
18
+ # ========================================================================= #
19
+ # === Colours::RainbowColours::STRIP_ANSI
20
+ #
21
+ # Checking for escape sequences (and a number).
22
+ #
23
+ # Official documentation can be seen here:
24
+ #
25
+ # https://ruby-doc.org/core/Regexp.html#method-c-new
26
+ #
27
+ # ========================================================================= #
28
+ STRIP_ANSI = Regexp.new('\e\[[\d;]*[m|K]', nil)
29
+
30
+ end; end
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Colours::RainbowColours
6
+ # =========================================================================== #
7
+ # require 'colours/rainbow_colours/do_parse_via_rainbow_colours.rb'
8
+ # =========================================================================== #
9
+ require 'colours/toplevel_methods/cat.rb'
10
+ require 'colours/toplevel_methods/clear_screen.rb'
11
+ require 'colours/toplevel_methods/e.rb'
12
+ # =========================================================================== #
13
+ # Require rainbow_colours specific code next:
14
+ # =========================================================================== #
15
+ require 'colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb'
16
+ require 'colours/rainbow_colours/constants.rb'
17
+ require 'colours/rainbow_colours/paint_detected_mode.rb'
18
+ require 'colours/rainbow_colours/report_errors.rb'
19
+
20
+ module Colours
21
+
22
+ module RainbowColours
23
+
24
+ begin
25
+ require 'stringio'
26
+ rescue LoadError; end
27
+
28
+ begin
29
+ require 'trollop'
30
+ rescue LoadError; end
31
+
32
+ # ========================================================================= #
33
+ # === Colours::RainbowColours.do_parse_via_rainbow_colours
34
+ #
35
+ # This is the rainbow_colours initializer.
36
+ # ========================================================================= #
37
+ def self.do_parse_via_rainbow_colours(
38
+ i = ARGV
39
+ )
40
+ check_for_trollop_being_available_or_exit
41
+ # ======================================================================= #
42
+ # Setup the trollop-parser instance next.
43
+ # ======================================================================= #
44
+ trollop_parser = Trollop::Parser.new {
45
+ banner <<HEADER
46
+
47
+ Usage: rainbow_colours [OPTION]... [FILE]...
48
+
49
+ Display one or several files. Alternatively, obtain input via STDIN.
50
+
51
+ With no FILE, or when FILE is -, read standard input.
52
+
53
+ HEADER
54
+ banner ''
55
+ # ll | rainbowc -a
56
+ opt :animate, 'Enable psychedelics', short: 'a', :default => false
57
+ opt :spread, 'Rainbow spread', short: 'p', :default => DEFAULT_RAINBOW_SPREAD
58
+ opt :freq, 'Rainbow frequency', short: 'F', :default => 0.1
59
+ opt :seed, 'Rainbow seed, 0 = random', short: 'S', :default => 0
60
+ opt :duration, 'Animation duration', short: 'd', :default => 12
61
+ opt :speed, 'Animation speed', short: 's', :default => 20.0
62
+ opt :invert, 'Invert fg and bg', short: 'i', :default => false
63
+ opt :truecolor, '24-bit (truecolor)', short: 't', :default => false
64
+ opt :force, 'Force color even when stdout is not a tty', short: 'f', :default => false
65
+ opt :help, 'Show this help menu', short: 'h'
66
+ banner <<FOOTER
67
+
68
+ Examples:
69
+
70
+ rainbow_colours f - g Output f's contents, then stdin, then g's contents.
71
+ rainbow_colours Copy standard input to standard output.
72
+ fortune | rainbow_colours Display a rainbow cookie.
73
+
74
+ FOOTER
75
+ } # End of the help-banner.
76
+ # ======================================================================= #
77
+ # Keep the Trollop instance assigned to the variable opts.
78
+ # ======================================================================= #
79
+ opts = Trollop.with_standard_exception_handling(trollop_parser) {
80
+ begin
81
+ o = trollop_parser.parse(i) # Parse the given input here.
82
+ rescue Trollop::HelpNeeded # If we need some more help.
83
+ string_io_buffer = StringIO.new
84
+ trollop_parser.educate(string_io_buffer) # <- display the help message and then exit.
85
+ string_io_buffer.rewind
86
+ opts = {
87
+ animate: false,
88
+ speed: 20,
89
+ duration: 12,
90
+ os: rand(256),
91
+ spread: 8.0,
92
+ freq: 0.3
93
+ }
94
+ splitted = string_io_buffer.read.split("\n")
95
+ ::Colours.cat(splitted, opts)
96
+ e
97
+ string_io_buffer.close # Close the buffer again.
98
+ exit 1
99
+ end
100
+ o
101
+ }
102
+
103
+ p.die(:spread, 'must be >= 0.1') if opts[:spread] < 0.1
104
+ p.die(:duration, 'must be >= 0.1') if opts[:duration] < 0.1
105
+ p.die(:speed, 'must be >= 0.1') if opts[:speed] < 0.1
106
+
107
+ # ======================================================================= #
108
+ # Build up the option-hash next.
109
+ # ======================================================================= #
110
+ opts[:os] = opts[:seed]
111
+ opts[:os] = rand(256) if opts[:os] == 0
112
+
113
+ begin
114
+ if ARGV.empty?
115
+ files = [:stdin]
116
+ else
117
+ files = ARGV[0..-1]
118
+ end
119
+ files.each { |file|
120
+ case file
121
+ when '-', :stdin
122
+ fd = ARGF
123
+ end
124
+ begin
125
+ fd = File.open(file) unless fd == ARGF
126
+ if $stdout.tty? or opts[:force]
127
+ # =============================================================== #
128
+ # Work on TTY terminals. This also includes terminals such
129
+ # as KDE Konsole. The second argument are the options passed
130
+ # towards Colours.cat().
131
+ # =============================================================== #
132
+ ::Colours.cat(fd, opts)
133
+ else
134
+ until fd.eof? do
135
+ # ============================================================= #
136
+ # Keep on writing the input to $stdout here.
137
+ # ============================================================= #
138
+ $stdout.write(fd.read(8192))
139
+ end
140
+ end
141
+ rescue Errno::ENOENT
142
+ report_no_such_file_or_directory(file)
143
+ exit 1
144
+ rescue Errno::EACCES
145
+ report_permission_denied(file)
146
+ exit 1
147
+ rescue Errno::EISDIR
148
+ report_is_a_directory(file)
149
+ exit 1
150
+ rescue Errno::EPIPE
151
+ exit 1
152
+ end
153
+ }
154
+ rescue Interrupt
155
+ end
156
+ end
157
+
158
+ end; end
159
+
160
+ if __FILE__ == $PROGRAM_NAME
161
+ Colours::RainbowColours.do_parse_via_rainbow_colours(ARGV)
162
+ end # rainbow_colours
163
+ # ll | rainbow_colours
164
+ # ll | rainbow_colours -a
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'paint_detected_mode.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ module RainbowColours
10
+
11
+ # ========================================================================= #
12
+ # === @paint_detected_mode
13
+ # ========================================================================= #
14
+ if Object.const_defined? :Paint
15
+ @paint_detected_mode = Paint.detect_mode
16
+ else
17
+ @paint_detected_mode = nil
18
+ end
19
+
20
+ end; end