colours 0.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +1152 -0
  4. data/bin/colours +7 -0
  5. data/bin/egreen +7 -0
  6. data/bin/fancy_parse +7 -0
  7. data/bin/html_colour_to_hex_value +7 -0
  8. data/bin/html_colourize +7 -0
  9. data/bin/orange +7 -0
  10. data/bin/print_rainbow_line +7 -0
  11. data/bin/rainbow_colours +7 -0
  12. data/bin/remove_ansii_escape_sequences +7 -0
  13. data/bin/steelblue +7 -0
  14. data/colours.gemspec +74 -0
  15. data/doc/COLOUR_CODES_CHART.md +27 -0
  16. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +28 -0
  17. data/doc/README.gen +1105 -0
  18. data/doc/todo/todo.md +25 -0
  19. data/lib/colours/256_colours/support_for_256_colours.rb +196 -0
  20. data/lib/colours/autoalias_e.rb +10 -0
  21. data/lib/colours/autogenerated/README.md +2 -0
  22. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  23. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  24. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +7001 -0
  25. data/lib/colours/autoinclude.rb +14 -0
  26. data/lib/colours/base/base.rb +29 -0
  27. data/lib/colours/basic_colours/README.md +4 -0
  28. data/lib/colours/basic_colours/basic_colours.rb +334 -0
  29. data/lib/colours/class/colours.rb +537 -0
  30. data/lib/colours/colour_methods/README.md +11 -0
  31. data/lib/colours/colour_methods/colour_methods.rb +685 -0
  32. data/lib/colours/colour_table/README.md +2 -0
  33. data/lib/colours/colour_table/colour_table.rb +282 -0
  34. data/lib/colours/colours_e_autoinclude.rb +9 -0
  35. data/lib/colours/commandline/README.md +2 -0
  36. data/lib/colours/commandline/commandline.rb +58 -0
  37. data/lib/colours/commandline/menu.rb +122 -0
  38. data/lib/colours/constants/constants.rb +9 -0
  39. data/lib/colours/constants/escape.rb +22 -0
  40. data/lib/colours/constants/file_constants.rb +73 -0
  41. data/lib/colours/constants/hash_ansi_colours.rb +39 -0
  42. data/lib/colours/constants/hash_simple_colours.rb +148 -0
  43. data/lib/colours/constants/misc.rb +361 -0
  44. data/lib/colours/constants/newline.rb +14 -0
  45. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  46. data/lib/colours/e/README.md +13 -0
  47. data/lib/colours/e/autoinclude.rb +11 -0
  48. data/lib/colours/e/e.rb +35 -0
  49. data/lib/colours/e.rb +5 -0
  50. data/lib/colours/eparse/eparse.rb +114 -0
  51. data/lib/colours/everything/autoinclude.rb +11 -0
  52. data/lib/colours/html_colours/README.md +1 -0
  53. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  54. data/lib/colours/html_colours/html_colours.rb +424 -0
  55. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +132 -0
  56. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +224 -0
  57. data/lib/colours/module.rb +11 -0
  58. data/lib/colours/project/project.rb +22 -0
  59. data/lib/colours/rainbow_colours/README.md +2 -0
  60. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  61. data/lib/colours/rainbow_colours/constants.rb +30 -0
  62. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  63. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  64. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  65. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  66. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  67. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  68. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  69. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  70. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  71. data/lib/colours/requires/require_autogenerated_colour_methods.rb +5 -0
  72. data/lib/colours/requires/require_commandline.rb +7 -0
  73. data/lib/colours/requires/require_eparse.rb +11 -0
  74. data/lib/colours/requires/require_rgb.rb +5 -0
  75. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  76. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  77. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  78. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  79. data/lib/colours/requires/require_the_constants.rb +5 -0
  80. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  81. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  82. data/lib/colours/requires/require_the_project.rb +53 -0
  83. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  84. data/lib/colours/requires/require_yaml.rb +9 -0
  85. data/lib/colours/rgb/rgb.rb +550 -0
  86. data/lib/colours/testing/README.md +2 -0
  87. data/lib/colours/testing/testing.rb +168 -0
  88. data/lib/colours/toplevel_methods/autogenerate.rb +310 -0
  89. data/lib/colours/toplevel_methods/bold.rb +41 -0
  90. data/lib/colours/toplevel_methods/bold_and_italic.rb +38 -0
  91. data/lib/colours/toplevel_methods/cat.rb +39 -0
  92. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  93. data/lib/colours/toplevel_methods/cliner.rb +17 -0
  94. data/lib/colours/toplevel_methods/col.rb +54 -0
  95. data/lib/colours/toplevel_methods/e.rb +69 -0
  96. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  97. data/lib/colours/toplevel_methods/html_colour_to_hex_value.rb +41 -0
  98. data/lib/colours/toplevel_methods/html_colourize.rb +69 -0
  99. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  100. data/lib/colours/toplevel_methods/italic.rb +110 -0
  101. data/lib/colours/toplevel_methods/make_colour.rb +28 -0
  102. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +336 -0
  103. data/lib/colours/toplevel_methods/misc.rb +226 -0
  104. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  105. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +88 -0
  106. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  107. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +112 -0
  108. data/lib/colours/toplevel_methods/revert.rb +104 -0
  109. data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
  110. data/lib/colours/toplevel_methods/shell_file_containing_the_html_colours.sh +148 -0
  111. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  112. data/lib/colours/toplevel_methods/underline.rb +130 -0
  113. data/lib/colours/toplevel_methods/use_colours.rb +290 -0
  114. data/lib/colours/version/version.rb +25 -0
  115. data/lib/colours/yaml/256_colours.yml +279 -0
  116. data/lib/colours/yaml/basic_colours.yml +25 -0
  117. data/lib/colours/yaml/html_colours.yml +837 -0
  118. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  119. data/lib/colours/yaml/prefer_this_colour_schemata.yml +17 -0
  120. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +15 -0
  121. data/lib/colours.rb +1 -0
  122. data/test/test.html +18 -0
  123. data/test/testing_256_colours_support.rb +29 -0
  124. data/test/testing_bold_italic_underline.rb +26 -0
  125. data/test/testing_class_colours.rb +46 -0
  126. data/test/testing_col.rb +10 -0
  127. data/test/testing_colours.rb +96 -0
  128. data/test/testing_colours_e.rb +13 -0
  129. data/test/testing_eparse.rb +13 -0
  130. data/test/testing_italic.rb +28 -0
  131. data/test/testing_kde_colour_palette.rb +30 -0
  132. data/test/testing_konsole_submodule.rb +226 -0
  133. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  134. data/test/testing_replace_number_words_with_the_corresponding_html_colour.rb +39 -0
  135. data/test/testing_rgb_to_hex.rb +32 -0
  136. data/test/testing_the_basic_colours_of_the_colours_project.rb +62 -0
  137. data/test/testing_the_colour_methods.rb +36 -0
  138. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  139. data/test/testing_the_ecomment_method.rb +11 -0
  140. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  141. data/test/testing_the_regex_for_capturing_the_commandline_coloured_content.rb +112 -0
  142. data/test/testing_whether_colours_will_be_used.rb +7 -0
  143. metadata +225 -0
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Add the test() method to the Colours module here.
6
+ # =========================================================================== #
7
+ # require 'colours/testing/testing.rb'
8
+ # =========================================================================== #
9
+ module Colours
10
+
11
+ require 'colours/toplevel_methods/e.rb'
12
+ require 'colours/toplevel_methods/show_basic_colour_palette.rb'
13
+ require 'colours/toplevel_methods/make_colour.rb'
14
+ require 'colours/colour_table/colour_table.rb'
15
+
16
+ # ========================================================================= #
17
+ # === Colours.simple_colours_test
18
+ #
19
+ # This method purposely tests only the basic parts for colours-related
20
+ # output onto the terminal.
21
+ # ========================================================================= #
22
+ def self.simple_colours_test
23
+ show_basic_colour_palette
24
+ end
25
+
26
+ # ========================================================================= #
27
+ # === Colours.test
28
+ #
29
+ # This class-method can be used to test the Colours module.
30
+ #
31
+ # It will be called from the test.rb file, in order to test all components
32
+ # of the Colours module.
33
+ #
34
+ # To invoke it, do:
35
+ #
36
+ # Colours.test
37
+ #
38
+ # ========================================================================= #
39
+ def self.test
40
+ require 'colours/basic_colours/basic_colours.rb'
41
+ require 'colours/colour_table/colour_table.rb'
42
+ cliner
43
+ show_basic_colour_palette
44
+ cliner
45
+ e red('Hello ')+cyan('World!')
46
+ e 'Hi '+Colours.red+'there.'+rev
47
+ e 'Hi '+Colours.cyan+'there.'+rev
48
+ e 'Hi '+Colours::BasicColours.bold_white+'there.'+rev
49
+ e 'Hi '+Colours.pink+'there.'+rev
50
+ e 'Hi '+Colours.brown+'there.'+rev
51
+ cliner
52
+ e CYAN+'Hi there.'
53
+ e BWHITE+'Hi there.'+BBLUE+' Yo there.'+rev
54
+ e sfancy('yo')+simp(' there')
55
+ disable_colours(true)
56
+ e sfancy('yo')+simp(' there')
57
+ enable_colours(true)
58
+ e sfancy('yo')+simp(' there')
59
+ e rgb_to_hex('155255255')
60
+ e col '/Depot/Audio'
61
+ e col '/Depot/Audio/Westbam_Sunshine.mp3'
62
+ e rev+'This is '+simp('elegant => simportant()')+'.'
63
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
64
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
65
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
66
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
67
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
68
+ ecomment 'An this # could be a comment.'
69
+ e
70
+ e 'Changing colour codes now. We should see different colours '+
71
+ 'when compared to the above.'
72
+ e
73
+ ::Colours.update_the_colour_codes_with
74
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
75
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
76
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
77
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
78
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
79
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
80
+ e 'Do we use colours? '+use_colours?.to_s
81
+ e cyan+' ==> Hi there.'
82
+ e red+' ==> Hi there.'
83
+ e green+' ==> Hi there.'
84
+ e brown+' ==> Hi there.'
85
+ e blue+' ==> Hi there.'
86
+ e teal+' ==> Hi there.'
87
+ e white+' ==> Hi there.'
88
+ e grey+' ==> Hi there.'
89
+ e lightblue+' ==> Hi there.'+red()+' yo'
90
+ e RED+'This is red galore.'
91
+ e 'right?'+::Colours.rev
92
+ e BLUE+'This is blue now.'
93
+ e 'right?'+rev
94
+ e 'Hi there - this should be white.'
95
+ # html_colours?
96
+ p main_colours
97
+ main_colours.each {|entry|
98
+ send(entry, 'test')
99
+ }
100
+ e 'yo this should '+pink('be pink.')
101
+ puts CFANCY+' Hi there.'
102
+ puts CIMPORTANT+' Hi there.'
103
+ # Next, we will disable the colours.
104
+ disable_colours(true)
105
+ # The following ones have a newline.
106
+ e rev+'This is '+simportant('elegant => simportant().',true)
107
+ e rev+'This is '+sfancy('elegant => sfancy().',true)
108
+ e rev+'This is '+sdir('elegant => sdir().',true)
109
+ e rev+'This is '+sfile('elegant => sfancy().',true)
110
+ ::Colours.enable_colours(true)
111
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
112
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
113
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
114
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'; e
115
+ e 'Next, trying to underline:'
116
+ underline 'Hi there'
117
+ e 'Next trying eparse:'
118
+ eparse 'Joe: Hey Tim, how do you do?'
119
+ eparse 'Tim: Really fine. How about you?'
120
+ eparse ' Joe: ok man let us proceed'
121
+ eparse ' [name of character here] # show when this character last logged in'
122
+ e
123
+ e 'Next some tests with col():'
124
+ e
125
+ e ' '+col('/Depot/Audio/AVAILABLE_SONGS').to_s
126
+ e ' '+col('/Depot/Audio').to_s
127
+ e
128
+ cliner
129
+ e 'Now testing Colours.red("foobar"):'
130
+ e red('foobar')
131
+ e 'Next, we test Colours.enable() and Colours.disable()'
132
+ disable
133
+ e 'Colours.disable()'
134
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
135
+ e 'Colours.enable()'
136
+ enable
137
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
138
+ e rev+'The colour for symlinks is: '+simportant('Colours.colour_for_symlinks')
139
+ pp colour_for_symlinks
140
+ e rev+'A classical Hello World! example, and the colour-code for it.'
141
+ efancy 'Hello World!'
142
+ pp sfancy('Hello World!')
143
+ e 'Next removing some escape sequences:'
144
+ e
145
+ e remove_escape_sequences(" \e[1;31mhello world\e[0;0m # <-- "+
146
+ "This here is not coloured and it also does not have "+
147
+ "escape-sequences either.")
148
+ e
149
+ e 'Next testing whether Colours.yellow() works:'
150
+ e
151
+ e " hello #{Colours.yellow('world!')}#{rev}"
152
+ e
153
+ e 'Next testing Colours.eparse():'
154
+ e
155
+ eparse ' hello # world!'
156
+ e
157
+ e 'Next testing Colours.ecomment():'
158
+ e
159
+ ecomment ' hello # world!'
160
+ e
161
+ end
162
+
163
+ end
164
+
165
+ if __FILE__ == $PROGRAM_NAME
166
+ include Colours
167
+ ::Colours.test
168
+ end # Colours.test
@@ -0,0 +1,310 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file contains code that can be used to autogenerate ruby code,
6
+ # and store this into a .rb file. That functionality is mostly useful
7
+ # on my home system, though.
8
+ # =========================================================================== #
9
+ # require 'colours/toplevel_methods/autogenerate.rb'
10
+ # =========================================================================== #
11
+ module Colours
12
+
13
+ require 'yaml'
14
+ require 'colours/constants/newline.rb'
15
+ require 'colours/constants/file_constants.rb'
16
+ require 'colours/toplevel_methods/is_on_roebe.rb'
17
+ require 'colours/256_colours/support_for_256_colours.rb'
18
+ require 'colours/html_colours/html_colours.rb'
19
+
20
+ # ========================================================================= #
21
+ # === GENERIC_RUBY_HEADER
22
+ # ========================================================================= #
23
+ GENERIC_RUBY_HEADER = "#!/usr/bin/ruby -w
24
+ # Encoding: UTF-8
25
+ # frozen_string_literal: true
26
+ # =========================================================================== #"
27
+
28
+ # ========================================================================= #
29
+ # === Colours.autogenerate_the_module_for_the_html_colours
30
+ #
31
+ # This method will autogenerate the module that will support
32
+ # the html colours.
33
+ # ========================================================================= #
34
+ def self.autogenerate_the_module_for_the_html_colours(
35
+ into = HOME_DIRECTORY_OF_USER_X+'programming/ruby/src/'\
36
+ 'colours/lib/colours/autogenerated/support_for_html_colours.rb'
37
+ )
38
+ _ = ''.dup
39
+ _ << GENERIC_RUBY_HEADER+"
40
+ # require 'colours/autogenerated/support_for_html_colours.rb'
41
+ # =========================================================================== #
42
+ "
43
+ _ << "module Colours\n\n"
44
+ _ << "module SupportForHTMLColours # include Colours::SupportForHTMLColours\n\n".dup
45
+ _ << " require 'colours/toplevel_methods/html_colourize.rb'\n"
46
+ _ << " require 'colours/toplevel_methods/use_colours.rb'\n\n"
47
+ comment_line = ' # '+('='*73)+' #'+N
48
+ available_html_colours?.each {|name_of_the_html_colour|
49
+ _ << comment_line
50
+ _ << ' # === Colours::SupportForHTMLColours.'+name_of_the_html_colour+N
51
+ _ << comment_line
52
+ _ << " def self.#{name_of_the_html_colour}(i = '', &block)\n"
53
+ _ << " if ::Colours.use_html_colours?\n"
54
+ _ << " return ::Colours.html_colourize(__method__, i, &block)\n"
55
+ _ << " else\n"
56
+ _ << " return i\n"
57
+ _ << " end\n"
58
+ _ << " end; def #{name_of_the_html_colour}(i = '', &block); SupportForHTMLColours.#{name_of_the_html_colour}(i, &block); end#{N}"
59
+ # ===================================================================== #
60
+ # Next, due to several reasons, we add a prepended "konsole_colour_"
61
+ # as name to this method.
62
+ # ===================================================================== #
63
+ _ << " def konsole_colour_#{name_of_the_html_colour}(i = '', &block); SupportForHTMLColours.#{name_of_the_html_colour}(i, &block); end#{N}#{N}"
64
+ }
65
+ _ << 'end; end'
66
+ what = _
67
+ # ======================================================================= #
68
+ # This is only useful on my home system really:
69
+ # ======================================================================= #
70
+ puts 'Storing into:'
71
+ puts
72
+ puts ' '+into
73
+ puts
74
+ require 'save_file'
75
+ SaveFile.write_what_into(what, into)
76
+ end
77
+
78
+ # ========================================================================= #
79
+ # === Colours.autogenerate_toplevel_basic_colour_methods
80
+ #
81
+ # The code in this method will autogenerate the toplevel colour
82
+ # methods, such as Colours.yellow().
83
+ #
84
+ # The code needs to respect several settings. For example, whether colours
85
+ # are used or not. Additionally, for methods such as Colours.yellow(),
86
+ # we need to find out whether we use the basic colours, the 256-colours or
87
+ # the HTML colours, and call the corresponding method in these cases.
88
+ # ========================================================================= #
89
+ def self.autogenerate_toplevel_basic_colour_methods(
90
+ into = HOME_DIRECTORY_OF_USER_X+'programming/ruby/src/'\
91
+ 'colours/lib/colours/autogenerated/'\
92
+ 'toplevel_basic_colour_methods.rb'
93
+ )
94
+ comment_line = " # ======================================================================== \n"
95
+ store_this_string = ''.dup
96
+ header = <<-EOF
97
+ #{GENERIC_RUBY_HEADER}
98
+ # This file contains the code that will call the corresponding colour method
99
+ # depending on which colour-mode the user prefers.
100
+ # =========================================================================== #
101
+ # require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
102
+ # =========================================================================== #
103
+ module Colours
104
+
105
+ require 'colours/toplevel_methods/use_colours.rb'
106
+ require 'colours/basic_colours/basic_colours.rb'
107
+ require 'colours/256_colours/support_for_256_colours.rb'
108
+ require 'colours/autogenerated/support_for_html_colours.rb'
109
+ require 'colours/html_colours/html_colours.rb'
110
+
111
+ module AllColourMethods # include Colours::AllColourMethods
112
+
113
+ EOF
114
+
115
+ store_this_string << header
116
+ # ======================================================================= #
117
+ # First define the methods for the basic colours:
118
+ # ======================================================================= #
119
+ array = return_a_unique_array_containing_all_available_colours
120
+ array.each {|this_basic_colour| # <- e. g. "yellow".
121
+ this_basic_colour = this_basic_colour.dup
122
+ if this_basic_colour.include?(' ') and
123
+ array.include?(this_basic_colour.delete(' '))
124
+ # =================================================================== #
125
+ # === This must be an alias
126
+ #
127
+ # In this case we will also add an alias containing the '_' part.
128
+ # We will only add this as an alias for include-actions, though.
129
+ # (This may change at a later point in the future - not sure yet.)
130
+ # =================================================================== #
131
+ store_this_string << " def #{this_basic_colour.tr(' ','_')}(i = ARGV)
132
+ if i.is_a? Array
133
+ i = i.join(' ').strip
134
+ end
135
+ AllColourMethods.#{this_basic_colour.delete(' ')}(i)
136
+ end\n\n"
137
+ else
138
+ name_of_the_method = this_basic_colour.downcase.delete(' ').dup
139
+ store_this_string << comment_line
140
+ store_this_string << " # === Colours::AllColourMethods.#{name_of_the_method}\n"
141
+ store_this_string << comment_line
142
+ store_this_string << " def self.#{name_of_the_method}(i = '', &block)\n"
143
+ store_this_string << " if ::Colours.use_colours?\n"
144
+ # =================================================================== #
145
+ # Ok, so we determine what to do with this colour-method:
146
+ # =================================================================== #
147
+ store_this_string << " if ::Colours.is_this_a_html_colour?(__method__)\n"
148
+ store_this_string << " return ::Colours::SupportForHTMLColours.#{name_of_the_method}(i, &block)\n"
149
+ store_this_string << " elsif ::Colours.is_this_a_256_colour?(__method__)\n"
150
+ store_this_string << " return ::Colours::SupportFor256Colours.#{name_of_the_method}(i, &block)\n"
151
+ store_this_string << " else\n"
152
+ store_this_string << " return ::Colours::BasicColours.#{name_of_the_method}(i, &block)\n"
153
+ store_this_string << " end\n"
154
+ store_this_string << " else\n"
155
+ store_this_string << " return i\n"
156
+ store_this_string << " end\n"
157
+ store_this_string << " end; def #{name_of_the_method}(i = '', &block); AllColourMethods.#{name_of_the_method}(i, &block); end\n"
158
+ # =================================================================== #
159
+ # Next, due to several reasons, we add a prepended "konsole_colour_"
160
+ # as name to this method.
161
+ # =================================================================== #
162
+ store_this_string << " def konsole_colour_#{name_of_the_method}(i = ''); AllColourMethods.#{name_of_the_method}(i); end\n"
163
+ store_this_string << " def konsole_#{name_of_the_method}(i = ''); AllColourMethods.#{name_of_the_method}(i); end\n"
164
+ store_this_string << " self.instance_eval { alias konsole_colour_#{name_of_the_method} #{name_of_the_method} } # === Colours::AllColourMethods.konsole_colour_#{name_of_the_method}\n"
165
+ # =================================================================== #
166
+ # The next line adds something like: Colours.egreen(), as a method.
167
+ # =================================================================== #
168
+ store_this_string << " def Colours.e#{name_of_the_method}(i = ARGV); i = i.join(' ') if i.is_a? Array; puts AllColourMethods.#{name_of_the_method}(i); end\n"
169
+ store_this_string << " def e#{name_of_the_method}(i = ''); puts AllColourMethods.#{name_of_the_method}(i); end\n"
170
+ store_this_string << " alias ekonsole_colour_#{name_of_the_method} e#{name_of_the_method}\n"
171
+ store_this_string << "\n"
172
+ end
173
+ }
174
+ store_this_string << "end; end\n"
175
+ what = store_this_string .dup
176
+ # ======================================================================= #
177
+ # This is only useful on my home system really:
178
+ # ======================================================================= #
179
+ puts 'Storing into the file:'
180
+ puts
181
+ puts " #{into}"
182
+ puts
183
+ File.delete(into) if File.exist? into # Get rid of the old file.
184
+ begin
185
+ require 'save_file'
186
+ SaveFile.write_what_into(what, into)
187
+ rescue LoadError
188
+ puts 'save_file gem is not available/installed.'
189
+ end
190
+ end; self.instance_eval { alias define_colour_methods autogenerate_toplevel_basic_colour_methods } # === Colours.define_colour_methods
191
+
192
+ # ========================================================================= #
193
+ # === Colours.autogenerate_the_module_for_the_256_colours
194
+ #
195
+ # This method will autogenerate the module that will support
196
+ # the 256 colours.
197
+ # ========================================================================= #
198
+ def self.autogenerate_the_module_for_the_256_colours
199
+ _ = ''.dup
200
+ _ << GENERIC_RUBY_HEADER+"
201
+ # require 'colours/autogenerated/support_for_256_colours.rb'
202
+ # =========================================================================== #
203
+ "
204
+ _ << "module Colours\n\n"
205
+ _ << "module SupportFor256Colours # include Colours::SupportFor256Colours\n\n".dup
206
+ _ << " require 'colours/256_colours/support_for_256_colours.rb'\n\n"
207
+ comment_line = ' # '+('='*73)+' #'+N
208
+ @dataset_for_the_256_colours.each {|name_of_the_colour, id|
209
+ use_this_name = name_of_the_colour.downcase
210
+ _ << comment_line
211
+ _ << ' # === Colours::SupportFor256Colours.'+use_this_name+N
212
+ _ << comment_line
213
+ _ << " def self.#{use_this_name}(i = '')#{N}"
214
+ _ << " if Colours.use_colours?\n"
215
+ _ << " return Colours.return_this_256_colour(__method__, i)\n"
216
+ _ << " else\n"
217
+ _ << " return i\n"
218
+ _ << " end\n"
219
+ _ << " end; def #{use_this_name}(i = ''); SupportFor256Colours.#{use_this_name}(i); end#{N}#{N}"
220
+ }
221
+ _ << 'end; end'
222
+ what = _
223
+ # ======================================================================= #
224
+ # This is only useful on my home system really:
225
+ # ======================================================================= #
226
+ into = HOME_DIRECTORY_OF_USER_X+'programming/ruby/src/'\
227
+ 'colours/lib/colours/autogenerated/support_for_256_colours.rb'
228
+ puts 'Storing into:'
229
+ puts
230
+ puts ' '+into
231
+ puts
232
+ require 'save_file'
233
+ SaveFile.write_what_into(what, into)
234
+ end
235
+
236
+ require 'colours/toplevel_methods/html_colourize.rb'
237
+ # ========================================================================= #
238
+ # === Colours.generate_shell_file_containing_the_html_colours
239
+ #
240
+ # This method will generate a shell file into the current directory
241
+ # by default.
242
+ #
243
+ # The code in that file will generate a shell script that holds all
244
+ # the HTML-colours, via UPCASED names.
245
+ #
246
+ # These entries will then look like this:
247
+ #
248
+ # SADDLEBROWN: "\e[38;2;139;69;19m"
249
+ # PERU: "\e[38;2;205;133;63m"
250
+ # CHOCOLATE: "\e[38;2;210;105;30m"
251
+ #
252
+ # ========================================================================= #
253
+ def self.generate_shell_file_containing_the_html_colours(
254
+ generate_the_shell_file_into_this_directory = Dir.pwd
255
+ )
256
+ require 'save_file/module'
257
+ unless generate_the_shell_file_into_this_directory.end_with? '/'
258
+ if generate_the_shell_file_into_this_directory.frozen?
259
+ generate_the_shell_file_into_this_directory = generate_the_shell_file_into_this_directory.dup
260
+ end
261
+ generate_the_shell_file_into_this_directory << '/'
262
+ end
263
+ result = ''.dup
264
+ result << "# This is a shell file that contains the HTML colours\n"
265
+ available_html_colours?.each {|this_colour|
266
+ colour_code_to_use = ::Colours.html_colourize(this_colour.to_sym,'',false).inspect
267
+ result << "export #{this_colour.upcase}=#{colour_code_to_use}\n"
268
+ }
269
+ generate_the_shell_file_into_this_directory << 'shell_file_containing_the_html_colours.sh'
270
+ into = generate_the_shell_file_into_this_directory
271
+ e "Now creating a shell file at `#{into}`."
272
+ SaveFile.write_what_into(result, into)
273
+ # ======================================================================= #
274
+ # Generate files on my home system as well:
275
+ # ======================================================================= #
276
+ if is_on_roebe?
277
+ into = '/home/x/programming/ruby/src/'\
278
+ 'roebe/lib/roebe/shell_scripts/'+
279
+ File.basename(generate_the_shell_file_into_this_directory)
280
+ puts "And also saving into `#{into}`."
281
+ SaveFile.write_what_into(result, into)
282
+ end
283
+ end; self.instance_eval { alias autogenerate_shell_file_containing_the_html_colours generate_shell_file_containing_the_html_colours } # === Colours.autogenerate_shell_file_containing_the_html_colours
284
+
285
+ # ========================================================================= #
286
+ # === Colours.return_a_unique_array_containing_all_available_colours
287
+ # ========================================================================= #
288
+ def self.return_a_unique_array_containing_all_available_colours
289
+ array = []
290
+ array << YAML.load_file(FILE_HTML_COLOURS).keys # (1) First the HTML colours
291
+ array << YAML.load_file(FILE_256_COLOURS).keys.map(&:downcase) # (2) Then the basic colours
292
+ array << YAML.load_file(FILE_BASIC_COLOURS) # (3) And finally the basic colours
293
+ array.flatten!
294
+ array.uniq!
295
+ array.map!(&:strip)
296
+ array.sort
297
+ end; self.instance_eval { alias all_available_colour_methods? return_a_unique_array_containing_all_available_colours } # === Colours.all_available_colour_methods?
298
+
299
+ end
300
+
301
+ if __FILE__ == $PROGRAM_NAME
302
+ alias e puts
303
+ e
304
+ # pp Colours.return_a_unique_array_containing_all_available_colours
305
+ # e
306
+ Colours.autogenerate_the_module_for_the_html_colours
307
+ Colours.autogenerate_shell_file_containing_the_html_colours
308
+ Colours.autogenerate_the_module_for_the_256_colours
309
+ Colours.autogenerate_toplevel_basic_colour_methods
310
+ end # autogeneratecolours
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/bold.rb'
6
+ # Colours.bold
7
+ # =========================================================================== #
8
+ module Colours
9
+
10
+ require 'colours/toplevel_methods/revert.rb'
11
+
12
+ # ========================================================================= #
13
+ # === Colours.bold
14
+ #
15
+ # ANSI colour escape code for bold is "1".
16
+ #
17
+ # The method has to call Colours.rev() at the end, because that way
18
+ # downstream users can modify the default rev-colour in use.
19
+ #
20
+ # Usage example:
21
+ #
22
+ # puts ' ok | '+Colours.bold('Hello world!')+' | ok'
23
+ #
24
+ # ========================================================================= #
25
+ def self.bold(
26
+ show_this_text = 'This must be bold.'
27
+ )
28
+ return "\x1b[1m#{show_this_text}#{::Colours.rev}"
29
+ end; self.instance_eval { alias return_bold bold } # === Colours.return_bold
30
+
31
+ end
32
+
33
+ if __FILE__ == $PROGRAM_NAME
34
+ alias e puts
35
+ if ARGV.empty?
36
+ e Colours.bold('Hello world!')
37
+ e 'Hello world!'
38
+ else
39
+ e Colours.bold(ARGV.join(' ').strip)
40
+ end
41
+ end # colours_bold hello there how do you do
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/bold_and_italic.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/toplevel_methods/bold.rb'
10
+ require 'colours/toplevel_methods/italic.rb'
11
+ require 'colours/toplevel_methods/revert.rb'
12
+
13
+ # ========================================================================= #
14
+ # === Colours.bold_and_italic
15
+ #
16
+ # Usage example:
17
+ #
18
+ # puts Colours.bold_and_italic 'Hello world!'
19
+ #
20
+ # ========================================================================= #
21
+ def self.bold_and_italic(
22
+ i = 'This must be bold.'
23
+ )
24
+ if i.is_a? Array
25
+ i = i.join(' ')
26
+ end
27
+ italic(bold(i))
28
+ end
29
+
30
+ end
31
+
32
+ if __FILE__ == $PROGRAM_NAME
33
+ if ARGV.empty?
34
+ puts Colours.bold_and_italic('Hello world!')+' All is fine.'
35
+ else
36
+ puts Colours.bold_and_italic(ARGV)
37
+ end
38
+ end # boldanditalic yo there yoda
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/cat.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/rainbow_colours/print_rainbow_line.rb'
10
+
11
+ # ========================================================================= #
12
+ # === Colours.cat
13
+ #
14
+ # The first argument may be ARGF. It ought to respond to .each anyway.
15
+ #
16
+ # Note that .cat() will delegate towards print_line().
17
+ # ========================================================================= #
18
+ def self.cat(
19
+ file_descriptor, hash_options = {}
20
+ )
21
+ print "\e[?25l" if hash_options[:animate] # Print this if we animate (enabling psychedelics).
22
+ # ======================================================================= #
23
+ # Iterate over the file_descriptor passed.
24
+ # ======================================================================= #
25
+ file_descriptor.each { |line|
26
+ hash_options[:os] += 1 # Increase the output-count.
27
+ # ===================================================================== #
28
+ # Next, colourize the line. This depends on the method called
29
+ # print_rainbow_line().
30
+ # ===================================================================== #
31
+ RainbowColours.print_rainbow_line(
32
+ line, hash_options
33
+ ) # Delegate towards print_line.
34
+ }
35
+ ensure
36
+ print "\e[?25h" if hash_options[:animate]
37
+ end
38
+
39
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/clear_screen.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours.clear_screen
11
+ #
12
+ # Simply perform 'clear' here.
13
+ # ========================================================================= #
14
+ def self.clear_screen
15
+ system 'clear'
16
+ end; self.instance_eval { alias clear clear_screen } # === Colours.clear_screen
17
+
18
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/cliner.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours.cliner
11
+ # ========================================================================= #
12
+ def self.cliner(i = 78, &block)
13
+ yield if block_given?
14
+ puts '=' * i
15
+ end
16
+
17
+ end