colours 0.6.12

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 (147) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +970 -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 +927 -0
  14. data/doc/todo/todo.md +25 -0
  15. data/lib/colours/256_colours/support_for_256_colours.rb +190 -0
  16. data/lib/colours/autoalias_e.rb +10 -0
  17. data/lib/colours/autogenerated/README.md +2 -0
  18. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  19. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  20. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6367 -0
  21. data/lib/colours/autoinclude.rb +14 -0
  22. data/lib/colours/base/base.rb +23 -0
  23. data/lib/colours/basic_colours/README.md +4 -0
  24. data/lib/colours/basic_colours/basic_colours.rb +334 -0
  25. data/lib/colours/class/class.rb +125 -0
  26. data/lib/colours/colour_methods/README.md +11 -0
  27. data/lib/colours/colour_methods/default_colour.rb +66 -0
  28. data/lib/colours/colour_methods/sargument.rb +70 -0
  29. data/lib/colours/colour_methods/scomments.rb +105 -0
  30. data/lib/colours/colour_methods/sdir.rb +66 -0
  31. data/lib/colours/colour_methods/sfancy.rb +84 -0
  32. data/lib/colours/colour_methods/sfile.rb +71 -0
  33. data/lib/colours/colour_methods/simportant.rb +92 -0
  34. data/lib/colours/colour_methods/snormal.rb +66 -0
  35. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  36. data/lib/colours/colour_methods/swarn.rb +76 -0
  37. data/lib/colours/colour_table/README.md +3 -0
  38. data/lib/colours/colour_table/colour_table.rb +275 -0
  39. data/lib/colours/colours_e_autoinclude.rb +9 -0
  40. data/lib/colours/commandline/README.md +2 -0
  41. data/lib/colours/commandline/commandline.rb +44 -0
  42. data/lib/colours/commandline/menu.rb +111 -0
  43. data/lib/colours/constants/colour_constants.rb +301 -0
  44. data/lib/colours/constants/file_constants.rb +72 -0
  45. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  46. data/lib/colours/constants/misc.rb +59 -0
  47. data/lib/colours/constants/newline.rb +14 -0
  48. data/lib/colours/constants/registered_colour_methods.rb +53 -0
  49. data/lib/colours/e/README.md +13 -0
  50. data/lib/colours/e/autoinclude.rb +11 -0
  51. data/lib/colours/e/e.rb +35 -0
  52. data/lib/colours/e.rb +5 -0
  53. data/lib/colours/eparse/eparse.rb +77 -0
  54. data/lib/colours/everything/autoinclude.rb +11 -0
  55. data/lib/colours/html_colours/README.md +1 -0
  56. data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
  57. data/lib/colours/html_colours/hash_html_colours.rb +63 -0
  58. data/lib/colours/html_colours/html_colourize.rb +48 -0
  59. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  60. data/lib/colours/html_colours/misc.rb +186 -0
  61. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  62. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  63. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  64. data/lib/colours/module.rb +11 -0
  65. data/lib/colours/project/project_base_directory.rb +22 -0
  66. data/lib/colours/rainbow_colours/README.md +2 -0
  67. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  68. data/lib/colours/rainbow_colours/constants.rb +30 -0
  69. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  70. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  71. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  72. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  73. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  74. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  75. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  76. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  77. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  78. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  79. data/lib/colours/requires/require_commandline.rb +7 -0
  80. data/lib/colours/requires/require_eparse.rb +11 -0
  81. data/lib/colours/requires/require_rgb.rb +5 -0
  82. data/lib/colours/requires/require_sdir.rb +5 -0
  83. data/lib/colours/requires/require_sfile.rb +5 -0
  84. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  85. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  86. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  87. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  88. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  89. data/lib/colours/requires/require_the_constants.rb +11 -0
  90. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  91. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  92. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  93. data/lib/colours/requires/require_yaml.rb +9 -0
  94. data/lib/colours/revert/revert.rb +106 -0
  95. data/lib/colours/rgb/rgb.rb +547 -0
  96. data/lib/colours/testing/README.md +2 -0
  97. data/lib/colours/testing/testing.rb +157 -0
  98. data/lib/colours/toplevel_methods/bold.rb +35 -0
  99. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  100. data/lib/colours/toplevel_methods/cat.rb +39 -0
  101. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  102. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  103. data/lib/colours/toplevel_methods/col.rb +56 -0
  104. data/lib/colours/toplevel_methods/e.rb +63 -0
  105. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  106. data/lib/colours/toplevel_methods/fancy_parse.rb +83 -0
  107. data/lib/colours/toplevel_methods/html_colourize.rb +64 -0
  108. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  109. data/lib/colours/toplevel_methods/italic.rb +110 -0
  110. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  111. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +350 -0
  112. data/lib/colours/toplevel_methods/misc.rb +156 -0
  113. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  114. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +85 -0
  115. data/lib/colours/toplevel_methods/random_html_colour.rb +48 -0
  116. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  117. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +112 -0
  118. data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
  119. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  120. data/lib/colours/toplevel_methods/underline.rb +129 -0
  121. data/lib/colours/toplevel_methods/use_colours.rb +290 -0
  122. data/lib/colours/utility_scripts/README.md +2 -0
  123. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  124. data/lib/colours/version/version.rb +25 -0
  125. data/lib/colours/yaml/256_colours.yml +277 -0
  126. data/lib/colours/yaml/basic_colours.yml +23 -0
  127. data/lib/colours/yaml/html_colours.yml +835 -0
  128. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  129. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  130. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +15 -0
  131. data/lib/colours.rb +5 -0
  132. data/test/test.html +18 -0
  133. data/test/testing_256_colours_support.rb +29 -0
  134. data/test/testing_col.rb +10 -0
  135. data/test/testing_colours.rb +95 -0
  136. data/test/testing_colours_e.rb +13 -0
  137. data/test/testing_eparse.rb +13 -0
  138. data/test/testing_kde_colour_palette.rb +30 -0
  139. data/test/testing_konsole_submodule.rb +226 -0
  140. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  141. data/test/testing_rgb_to_hex.rb +32 -0
  142. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  143. data/test/testing_the_colour_methods.rb +36 -0
  144. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  145. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  146. data/test/testing_whether_colours_will_be_used.rb +7 -0
  147. metadata +229 -0
@@ -0,0 +1,157 @@
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
+ require 'colours/toplevel_methods/e.rb'
10
+ require 'colours/toplevel_methods/show_basic_colour_palette.rb'
11
+ require 'colours/toplevel_methods/make_colour.rb'
12
+
13
+ module Colours
14
+
15
+ # ========================================================================= #
16
+ # === Colours.test
17
+ #
18
+ # This class-method can be used to test the Colours module.
19
+ #
20
+ # It will be called from the test.rb file, in order to test all components
21
+ # of the Colours module.
22
+ #
23
+ # To invoke it, do:
24
+ #
25
+ # Colours.test
26
+ #
27
+ # ========================================================================= #
28
+ def self.test
29
+ require 'colours/basic_colours/basic_colours.rb'
30
+ require 'colours/colour_table/colour_table.rb'
31
+ cliner
32
+ show_basic_colour_palette
33
+ cliner
34
+ e red('Hello ')+cyan('World!')
35
+ e 'Hi '+Colours.red+'there.'+rev
36
+ e 'Hi '+Colours.cyan+'there.'+rev
37
+ e 'Hi '+Colours::BasicColours.bold_white+'there.'+rev
38
+ e 'Hi '+Colours.pink+'there.'+rev
39
+ e 'Hi '+Colours.brown+'there.'+rev
40
+ cliner
41
+ e CYAN+'Hi there.'
42
+ e BWHITE+'Hi there.'+BBLUE+' Yo there.'+rev
43
+ e sfancy('yo')+simp(' there')
44
+ disable_colours(true)
45
+ e sfancy('yo')+simp(' there')
46
+ enable_colours(true)
47
+ e sfancy('yo')+simp(' there')
48
+ e rgb_to_hex('155255255')
49
+ e col '/Depot/Audio'
50
+ e col '/Depot/Audio/Westbam_Sunshine.mp3'
51
+ e rev+'This is '+simp('elegant => simportant()')+'.'
52
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
53
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
54
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
55
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
56
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
57
+ ecomment 'An this # could be a comment.'
58
+ e
59
+ e 'Changing colour codes now. We should see different colours '+
60
+ 'when compared to the above.'
61
+ e
62
+ Colours.update_the_colour_codes_with
63
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
64
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
65
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
66
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'
67
+ e rev+'This is '+swarn('elegant => swarn()')+'.'
68
+ e rev+'This is '+ssym('elegant => ssym()')+'.'
69
+ e 'Do we use colours? '+use_colours?.to_s
70
+ e cyan+' ==> Hi there.'
71
+ e red+' ==> Hi there.'
72
+ e green+' ==> Hi there.'
73
+ e brown+' ==> Hi there.'
74
+ e blue+' ==> Hi there.'
75
+ e teal+' ==> Hi there.'
76
+ e white+' ==> Hi there.'
77
+ e grey+' ==> Hi there.'
78
+ e lightblue+' ==> Hi there.'+red()+' yo'
79
+ e RED+'This is red galore.'
80
+ e 'right?'+Colours.rev
81
+ e BLUE+'This is blue now.'
82
+ e 'right?'+rev
83
+ e 'Hi there - this should be white.'
84
+ # html_colours?
85
+ p main_colours
86
+ main_colours.each {|entry|
87
+ send(entry, 'test')
88
+ }
89
+ e 'yo this should '+pink('be pink.')
90
+ puts CFANCY+' Hi there.'
91
+ puts CIMPORTANT+' Hi there.'
92
+ # Next, we will disable the colours.
93
+ disable_colours(true)
94
+ # The following ones have a newline.
95
+ e rev+'This is '+simportant('elegant => simportant().',true)
96
+ e rev+'This is '+sfancy('elegant => sfancy().',true)
97
+ e rev+'This is '+sdir('elegant => sdir().',true)
98
+ e rev+'This is '+sfile('elegant => sfancy().',true)
99
+ Colours.enable_colours(true)
100
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
101
+ e rev+'This is '+sfancy('elegant => sfancy()')+'.'
102
+ e rev+'This is '+sdir('elegant => sdir()')+'.'
103
+ e rev+'This is '+sfile('elegant => sfancy()')+'.'; e
104
+ e 'Next, trying to underline:'
105
+ underline 'Hi there'
106
+ e 'Next trying eparse:'
107
+ eparse 'Joe: Hey Tim, how do you do?'
108
+ eparse 'Tim: Really fine. How about you?'
109
+ eparse ' Joe: ok man let us proceed'
110
+ eparse ' [name of character here] # show when this character last logged in'
111
+ e
112
+ e 'Next some tests with col():'
113
+ e
114
+ e ' '+col('/Depot/Audio/AVAILABLE_SONGS').to_s
115
+ e ' '+col('/Depot/Audio').to_s
116
+ e
117
+ cliner
118
+ e 'Now testing Colours.red("foobar"):'
119
+ e red('foobar')
120
+ e 'Next, we test Colours.enable() and Colours.disable()'
121
+ disable
122
+ e 'Colours.disable()'
123
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
124
+ e 'Colours.enable()'
125
+ enable
126
+ e rev+'This is '+simportant('elegant => simportant()')+'.'
127
+ e rev+'The colour for symlinks is: '+simportant('Colours.colour_for_symlinks')
128
+ pp colour_for_symlinks
129
+ e rev+'A classical Hello World! example, and the colour-code for it.'
130
+ efancy 'Hello World!'
131
+ pp sfancy('Hello World!')
132
+ e 'Next removing some escape sequences:'
133
+ e
134
+ e remove_escape_sequences(" \e[1;31mhello world\e[0;0m # <-- "+
135
+ "This here is not coloured and it also does not have "+
136
+ "escape-sequences either.")
137
+ e
138
+ e 'Next testing whether Colours.yellow() works:'
139
+ e
140
+ e " hello #{Colours.yellow('world!')}#{rev}"
141
+ e
142
+ e 'Next testing Colours.eparse():'
143
+ e
144
+ eparse ' hello # world!'
145
+ e
146
+ e 'Next testing Colours.ecomment():'
147
+ e
148
+ ecomment ' hello # world!'
149
+ e
150
+ end
151
+
152
+ end
153
+
154
+ if __FILE__ == $PROGRAM_NAME
155
+ include Colours
156
+ Colours.test
157
+ end
@@ -0,0 +1,35 @@
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
+ require 'colours/revert/revert.rb'
9
+
10
+ module Colours
11
+
12
+ # ========================================================================= #
13
+ # === Colours.bold
14
+ #
15
+ # Usage example:
16
+ #
17
+ # puts ' ok | '+Colours.bold('Hello world!')+' | ok'
18
+ #
19
+ # ========================================================================= #
20
+ def self.bold(
21
+ show_this_text = 'This must be bold.'
22
+ )
23
+ "\x1b[1m#{show_this_text}#{REVERT}"
24
+ end; self.instance_eval { alias return_bold bold } # === Colours.return_bold
25
+
26
+ end
27
+
28
+ if __FILE__ == $PROGRAM_NAME
29
+ if ARGV.empty?
30
+ puts Colours.bold('Hello world!')
31
+ puts 'Hello world!'
32
+ else
33
+ puts Colours.bold(ARGV.join(' ').strip)
34
+ end
35
+ end # colours_bold hello there how do you do
@@ -0,0 +1,36 @@
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
+ require 'colours/revert/revert.rb'
8
+ require 'colours/toplevel_methods/bold.rb'
9
+ require 'colours/toplevel_methods/italic.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours.bold_and_italic
15
+ #
16
+ # Usage example:
17
+ # puts Colours.bold_and_italic 'Hello world!'
18
+ # ========================================================================= #
19
+ def self.bold_and_italic(
20
+ i = 'This must be bold.'
21
+ )
22
+ if i.is_a? Array
23
+ i = i.join(' ')
24
+ end
25
+ italic(bold(i))
26
+ end
27
+
28
+ end
29
+
30
+ if __FILE__ == $PROGRAM_NAME
31
+ if ARGV.empty?
32
+ puts Colours.bold_and_italic('Hello world!')+' All is fine.'
33
+ else
34
+ puts Colours.bold_and_italic(ARGV)
35
+ end
36
+ end # bold_and_italic 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
+ require 'colours/rainbow_colours/print_rainbow_line.rb'
8
+
9
+ module Colours
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,19 @@
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)
13
+ if block_given?
14
+ yield
15
+ end
16
+ puts '=' * i
17
+ end
18
+
19
+ end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/col.rb'
6
+ # =========================================================================== #
7
+ require 'colours/colour_methods/sfile.rb'
8
+ require 'colours/colour_methods/sdir.rb'
9
+ require 'colours/colour_methods/ssymlink.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours.col (col tag)
15
+ #
16
+ # Careful - this method may collide with other methods named col().
17
+ #
18
+ # Usage examples:
19
+ #
20
+ # Colours.col '/Depot/j/geojgirjh'
21
+ # Colours.col '/Users/x/AUDIO/'
22
+ # Colours.col '/Users/x/AUDIO/Westbam_Sunshine.mp3'
23
+ #
24
+ # ========================================================================= #
25
+ def self.col(
26
+ i,
27
+ optional_arg_not_in_use_right_now = ''
28
+ )
29
+ if File.exist? i
30
+ ftype = File.ftype(i)
31
+ # e 'The ftype is: '+ftype # <- This could be used for debugging.
32
+ case ftype
33
+ # ===================================================================== #
34
+ # === file
35
+ # ===================================================================== #
36
+ when 'file'
37
+ return sfile(i)
38
+ # ===================================================================== #
39
+ # === directory
40
+ # ===================================================================== #
41
+ when 'directory'
42
+ return sdir(i)
43
+ # ===================================================================== #
44
+ # === link
45
+ # ===================================================================== #
46
+ when 'link'
47
+ return ssymlink(i)
48
+ else
49
+ e "module Colours: We do not know the filetype `#{ftype}`"
50
+ end
51
+ else # Else return the input a bit changed.
52
+ return sfile(i) # We modify it because that is better.
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/e.rb'
6
+ # =========================================================================== #
7
+ require 'colours/constants/newline.rb'
8
+ require 'colours/revert/revert.rb'
9
+
10
+ module Colours
11
+
12
+ # ========================================================================= #
13
+ # === ef
14
+ # ========================================================================= #
15
+ def ef(i)
16
+ e(i, false) # The variant without newlines.
17
+ end
18
+
19
+ # ========================================================================= #
20
+ # === Colours.e
21
+ #
22
+ # This is essentially just a fancified wrapper over puts.
23
+ #
24
+ # Usage examples:
25
+ # Colours.e 'hello world'
26
+ # Colours.e "hi \n there\n is everything fine? \n\n"
27
+ # ========================================================================= #
28
+ def self.e(
29
+ i = N,
30
+ append_newline = true
31
+ )
32
+ i = i.join(' ') if i.is_a? Array
33
+ _ = "#{rev}#{i.to_s.dup}".dup # Work with a copy here.
34
+ _.chomp! # So that we won't have more than one newline initially.
35
+ _ << N if append_newline # This should be the last modification before calling print.
36
+ print _ # And print the result finally.
37
+ end
38
+
39
+ # ========================================================================= #
40
+ # === e (e tag)
41
+ #
42
+ # This is just a wrapper towards the above method called Colours.e()
43
+ #
44
+ # If the second argument `make_newline` is true then we will append a
45
+ # newline. This is the default behaviour.
46
+ #
47
+ # This method just delegates to the module method Colours.e()
48
+ # ========================================================================= #
49
+ def e(
50
+ i = N, append_newline = true
51
+ ) # This is the main point of Colours.
52
+ ::Colours.e(i, append_newline) # Point towards the class method of e().
53
+ end; alias ci e # === ci
54
+
55
+ end
56
+
57
+ if __FILE__ == $PROGRAM_NAME
58
+ if ARGV.empty?
59
+ Colours.e('Hello World!')
60
+ else
61
+ Colours.e(ARGV)
62
+ end
63
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/esystem.rb'
6
+ # =========================================================================== #
7
+ require 'colours/toplevel_methods/e.rb'
8
+
9
+ module Colours
10
+
11
+ # ========================================================================= #
12
+ # === esystem
13
+ # ========================================================================= #
14
+ def self.esystem(i)
15
+ e i
16
+ system i
17
+ end
18
+
19
+ end
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/fancy_parse.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/methods_related_to_html_colours.rb'
12
+ require 'colours/toplevel_methods/underline.rb'
13
+
14
+ # ========================================================================= #
15
+ # === Colours.fancy_parse
16
+ #
17
+ # This method can be used to parse a line containing special tags,
18
+ # such as <i> or <teal>, and replace them with the corresponding
19
+ # ASCII code for the commandline. The second example, e. g. <teal>,
20
+ # is known as a HTML colour tag (htmlcolour).
21
+ #
22
+ # The idea for this method is to simply use it to quickly colourize
23
+ # some arbitrary text.
24
+ #
25
+ # The method will only return the resulting, sanitizing String;
26
+ # if you wish to display this on the terminal/commandline then
27
+ # you will have to use puts or print on your own.
28
+ #
29
+ # Usage examples:
30
+ #
31
+ # Colours.fancy_parse '<i>hey</i> <teal>there</teal>'
32
+ # puts Colours.fancy_parse '<i>hey</i> <teal>there</teal> ok'
33
+ #
34
+ # ========================================================================= #
35
+ def self.fancy_parse(
36
+ i = '',
37
+ use_this_colour = :default_colour
38
+ )
39
+ if i.is_a? Array
40
+ i = i.join
41
+ end
42
+ i = i.dup # Work on a copy.
43
+ # ======================================================================= #
44
+ # === Handle italic tags, aka <i>
45
+ # ======================================================================= #
46
+ if i.include?('<i>') and
47
+ i.include?('</i>')
48
+ use_this_regex = /<i>([A-Za-zöäüÖÄÜ\s-]+)<\/i>/ # See: https://rubular.com/r/U35iBGeQRQLFxe
49
+ i.gsub!(
50
+ use_this_regex,
51
+ return_italic('\1')
52
+ )
53
+ end
54
+ # ======================================================================= #
55
+ # === Handle bold tags, aka <b>
56
+ # ======================================================================= #
57
+ if i.include?('<b>') and
58
+ i.include?('</b>')
59
+ use_this_regex = /<b>(.+)<\/b>/
60
+ i.gsub!(
61
+ use_this_regex,
62
+ return_bold('\1')
63
+ )
64
+ end
65
+ # ======================================================================= #
66
+ # Finally, handle all HTML colours in the given line.
67
+ # ======================================================================= #
68
+ i = replace_all_html_colours_in_this_line(i, use_this_colour)
69
+ return i
70
+ end
71
+
72
+ end
73
+
74
+ if __FILE__ == $PROGRAM_NAME
75
+ result = Colours.fancy_parse(ARGV)
76
+ puts result
77
+ # pp result # <- This line is just for simple debugging.
78
+ end # fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
79
+ # fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
80
+ # fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
81
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal>"
82
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal> <b>how do you do</b>"
83
+ # fancy_parse "<tomato><b>Hello world.</b></tomato>"
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/html_colourize.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ require 'colours/rgb/rgb.rb'
10
+ require 'colours/revert/revert.rb'
11
+
12
+ # ========================================================================= #
13
+ # === Colours.html_colourize
14
+ #
15
+ # This method will simply return the colour-code + text.
16
+ #
17
+ # The third argument, called `append_revert`, can be used to determine
18
+ # whether we will append the revert code to the generated output String
19
+ # or whether we will not. By default we will, but there are examples
20
+ # where we may wish to assemble our own colour string, and in these
21
+ # cases we do not yet know which text is to be shown - hence, this
22
+ # must become an optional argument.
23
+ #
24
+ # A block can be passed to this method. If the block has, as content,
25
+ # the Symbol :omit_end then the end-part of the ANSI code will not
26
+ # be used.
27
+ #
28
+ # Usage examples:
29
+ #
30
+ # x = Colours.colourize('slateblue', 'Hello world!'); pp x
31
+ # y = Colours.colourize('slateblue', 'Hello world!') { :omit_end }; pp y
32
+ #
33
+ # ========================================================================= #
34
+ def self.html_colourize(
35
+ colour_to_use = return_random_html_colour,
36
+ this_text = nil,
37
+ append_revert = true,
38
+ &block
39
+ )
40
+ if block_given?
41
+ yielded = yield
42
+ case yielded
43
+ when :omit_end
44
+ append_revert = false
45
+ end
46
+ end
47
+ if this_text.nil?
48
+ this_text = colour_to_use.to_s.dup
49
+ end
50
+ if append_revert
51
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}#{revert}"
52
+ else
53
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}"
54
+ end
55
+ end; self.instance_eval { alias colourize html_colourize } # === Colours.colourize
56
+ self.instance_eval { alias kde_colour html_colourize } # === Colours.kde_colour
57
+ self.instance_eval { alias konsole_colours html_colourize } # === Colours.konsole_colours
58
+
59
+ end
60
+
61
+ if __FILE__ == $PROGRAM_NAME
62
+ puts Colours.html_colourize('slateblue', 'Hello world 1!')
63
+ puts Colours.html_colourize(:crimson, 'Hello world 2!')
64
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/is_on_roebe.rb'
6
+ # =========================================================================== #
7
+ module Colours
8
+
9
+ # ========================================================================= #
10
+ # === Colours.is_on_roebe?
11
+ # ========================================================================= #
12
+ def self.is_on_roebe?
13
+ ENV['IS_ROEBE'].to_s == '1'
14
+ end
15
+
16
+ end