colours 0.5.41

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.

Potentially problematic release.


This version of colours might be problematic. Click here for more details.

Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +22 -0
  3. data/README.md +862 -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/colours.gemspec +75 -0
  10. data/doc/COLOUR_CODES_CHART.md +28 -0
  11. data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
  12. data/doc/README.gen +845 -0
  13. data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
  14. data/lib/colours/autoalias_e.rb +10 -0
  15. data/lib/colours/autogenerated/README.md +2 -0
  16. data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
  17. data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
  18. data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
  19. data/lib/colours/autoinclude.rb +14 -0
  20. data/lib/colours/base/base.rb +23 -0
  21. data/lib/colours/basic_colours/README.md +4 -0
  22. data/lib/colours/basic_colours/basic_colours.rb +279 -0
  23. data/lib/colours/colour_methods/README.md +11 -0
  24. data/lib/colours/colour_methods/default_colour.rb +66 -0
  25. data/lib/colours/colour_methods/sargument.rb +70 -0
  26. data/lib/colours/colour_methods/scomments.rb +105 -0
  27. data/lib/colours/colour_methods/sdir.rb +66 -0
  28. data/lib/colours/colour_methods/sfancy.rb +84 -0
  29. data/lib/colours/colour_methods/sfile.rb +71 -0
  30. data/lib/colours/colour_methods/simportant.rb +92 -0
  31. data/lib/colours/colour_methods/snormal.rb +66 -0
  32. data/lib/colours/colour_methods/ssymlink.rb +102 -0
  33. data/lib/colours/colour_methods/swarn.rb +76 -0
  34. data/lib/colours/colour_table/README.md +3 -0
  35. data/lib/colours/colour_table/colour_table.rb +275 -0
  36. data/lib/colours/colours_e_autoinclude.rb +9 -0
  37. data/lib/colours/commandline/README.md +2 -0
  38. data/lib/colours/commandline/commandline.rb +44 -0
  39. data/lib/colours/commandline/menu.rb +111 -0
  40. data/lib/colours/constants/colour_constants.rb +299 -0
  41. data/lib/colours/constants/file_constants.rb +72 -0
  42. data/lib/colours/constants/hash_simple_colours.rb +146 -0
  43. data/lib/colours/constants/misc.rb +59 -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 +77 -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/hash_html_colours.rb +63 -0
  55. data/lib/colours/html_colours/html_colourize.rb +48 -0
  56. data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
  57. data/lib/colours/html_colours/misc.rb +186 -0
  58. data/lib/colours/html_colours/show_html_colours.rb +85 -0
  59. data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
  60. data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
  61. data/lib/colours/module.rb +11 -0
  62. data/lib/colours/project/project_base_directory.rb +22 -0
  63. data/lib/colours/rainbow_colours/README.md +2 -0
  64. data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
  65. data/lib/colours/rainbow_colours/constants.rb +30 -0
  66. data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
  67. data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
  68. data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
  69. data/lib/colours/rainbow_colours/println_ani.rb +32 -0
  70. data/lib/colours/rainbow_colours/println_plain.rb +36 -0
  71. data/lib/colours/rainbow_colours/rainbow.rb +38 -0
  72. data/lib/colours/rainbow_colours/report_errors.rb +32 -0
  73. data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
  74. data/lib/colours/rainbow_colours/set_mode.rb +24 -0
  75. data/lib/colours/requires/require_all_colour_methods.rb +5 -0
  76. data/lib/colours/requires/require_commandline.rb +7 -0
  77. data/lib/colours/requires/require_eparse.rb +11 -0
  78. data/lib/colours/requires/require_rgb.rb +5 -0
  79. data/lib/colours/requires/require_sdir.rb +5 -0
  80. data/lib/colours/requires/require_sfile.rb +5 -0
  81. data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
  82. data/lib/colours/requires/require_the_basic_colours.rb +7 -0
  83. data/lib/colours/requires/require_the_colour_methods.rb +34 -0
  84. data/lib/colours/requires/require_the_colour_table.rb +7 -0
  85. data/lib/colours/requires/require_the_colours_project.rb +52 -0
  86. data/lib/colours/requires/require_the_constants.rb +11 -0
  87. data/lib/colours/requires/require_the_html_colours.rb +11 -0
  88. data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
  89. data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
  90. data/lib/colours/revert/revert.rb +106 -0
  91. data/lib/colours/rgb/rgb.rb +538 -0
  92. data/lib/colours/testing/README.md +2 -0
  93. data/lib/colours/testing/testing.rb +157 -0
  94. data/lib/colours/toplevel_methods/bold.rb +35 -0
  95. data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
  96. data/lib/colours/toplevel_methods/cat.rb +39 -0
  97. data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
  98. data/lib/colours/toplevel_methods/cliner.rb +19 -0
  99. data/lib/colours/toplevel_methods/col.rb +56 -0
  100. data/lib/colours/toplevel_methods/e.rb +63 -0
  101. data/lib/colours/toplevel_methods/esystem.rb +19 -0
  102. data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
  103. data/lib/colours/toplevel_methods/html_colourize.rb +65 -0
  104. data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
  105. data/lib/colours/toplevel_methods/italic.rb +104 -0
  106. data/lib/colours/toplevel_methods/make_colour.rb +29 -0
  107. data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +314 -0
  108. data/lib/colours/toplevel_methods/misc.rb +95 -0
  109. data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
  110. data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
  111. data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
  112. data/lib/colours/toplevel_methods/random_value.rb +37 -0
  113. data/lib/colours/toplevel_methods/remove_escape_sequence.rb +107 -0
  114. data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
  115. data/lib/colours/toplevel_methods/underline.rb +114 -0
  116. data/lib/colours/toplevel_methods/use_colours.rb +311 -0
  117. data/lib/colours/utility_scripts/README.md +2 -0
  118. data/lib/colours/utility_scripts/autogenerate.rb +291 -0
  119. data/lib/colours/version/version.rb +25 -0
  120. data/lib/colours/yaml/256_colours.yml +277 -0
  121. data/lib/colours/yaml/basic_colours.yml +23 -0
  122. data/lib/colours/yaml/html_colours.yml +835 -0
  123. data/lib/colours/yaml/kde_colour_palette.yml +183 -0
  124. data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
  125. data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
  126. data/lib/colours.rb +5 -0
  127. data/test/test.html +18 -0
  128. data/test/testing_256_colours_support.rb +29 -0
  129. data/test/testing_col.rb +10 -0
  130. data/test/testing_colours.rb +95 -0
  131. data/test/testing_colours_e.rb +13 -0
  132. data/test/testing_eparse.rb +13 -0
  133. data/test/testing_kde_colour_palette.rb +30 -0
  134. data/test/testing_konsole_submodule.rb +226 -0
  135. data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
  136. data/test/testing_rgb_to_hex.rb +32 -0
  137. data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
  138. data/test/testing_the_colour_methods.rb +36 -0
  139. data/test/testing_the_constants_of_the_colours_project.rb +9 -0
  140. data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
  141. data/test/testing_whether_colours_will_be_used.rb +7 -0
  142. metadata +224 -0
@@ -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,79 @@
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; if
26
+ # you wish to display this on the terminal/commandline then you
27
+ # will have to use puts or print on your own.
28
+ #
29
+ # Usage example:
30
+ #
31
+ # Colours.fancy_parse '<i>hey</i> <teal>there</teal>'
32
+ #
33
+ # ========================================================================= #
34
+ def self.fancy_parse(i = '')
35
+ if i.is_a? Array
36
+ i = i.join
37
+ end
38
+ i = i.dup # Work on a copy.
39
+ # ======================================================================= #
40
+ # === Handle italic tags, aka <i>
41
+ # ======================================================================= #
42
+ if i.include?('<i>') and
43
+ i.include?('</i>')
44
+ use_this_regex = /<i>(.+)<\/i>/
45
+ i.gsub!(
46
+ use_this_regex,
47
+ return_italic('\1')
48
+ )
49
+ end
50
+ # ======================================================================= #
51
+ # === Handle bold tags, aka <b>
52
+ # ======================================================================= #
53
+ if i.include?('<b>') and
54
+ i.include?('</b>')
55
+ use_this_regex = /<b>(.+)<\/b>/
56
+ i.gsub!(
57
+ use_this_regex,
58
+ return_bold('\1')
59
+ )
60
+ end
61
+ # ======================================================================= #
62
+ # Finally, handle all HTML colours in the given line.
63
+ # ======================================================================= #
64
+ i = replace_all_html_colours_in_this_line(i)
65
+ i
66
+ end
67
+
68
+ end
69
+
70
+ if __FILE__ == $PROGRAM_NAME
71
+ result = Colours.fancy_parse(ARGV)
72
+ puts result
73
+ # pp result # <- This line is just for simple debugging.
74
+ end # fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
75
+ # fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
76
+ # fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
77
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal>"
78
+ # fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal> <b>how do you do</b>"
79
+ # fancy_parse "<tomato><b>Hello world.</b></tomato>"
@@ -0,0 +1,65 @@
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
+ require 'colours/rgb/rgb.rb'
8
+ require 'colours/toplevel_methods/use_colours.rb'
9
+ require 'colours/revert/revert.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours.html_colourize
15
+ #
16
+ # This method will simply return the colour-code + text.
17
+ #
18
+ # The third argument, called `append_revert`, can be used to determine
19
+ # whether we will append the revert code to the generated output String
20
+ # or whether we will not. By default we will, but there are examples
21
+ # where we may wish to assemble our own colour string, and in these
22
+ # cases we do not yet know which text is to be shown - hence, this
23
+ # must become an optional argument.
24
+ #
25
+ # A block can be passed to this method. If the block has, as content,
26
+ # the Symbol :omit_end then the end-part of the ANSI code will not
27
+ # be used.
28
+ #
29
+ # Usage examples:
30
+ #
31
+ # x = Colours.colourize('slateblue', 'Hello world!'); pp x
32
+ # y = Colours.colourize('slateblue', 'Hello world!') { :omit_end }; pp y
33
+ #
34
+ # ========================================================================= #
35
+ def self.html_colourize(
36
+ colour_to_use = return_random_html_colour,
37
+ this_text = nil,
38
+ append_revert = true,
39
+ &block
40
+ )
41
+ if block_given?
42
+ yielded = yield
43
+ case yielded
44
+ when :omit_end
45
+ append_revert = false
46
+ end
47
+ end
48
+ if this_text.nil?
49
+ this_text = colour_to_use.to_s.dup
50
+ end
51
+ if append_revert
52
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}#{revert}"
53
+ else
54
+ "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}"
55
+ end
56
+ end; self.instance_eval { alias colourize html_colourize } # === Colours.colourize
57
+ self.instance_eval { alias kde_colour html_colourize } # === Colours.kde_colour
58
+ self.instance_eval { alias konsole_colours html_colourize } # === Colours.konsole_colours
59
+
60
+ end
61
+
62
+ if __FILE__ == $PROGRAM_NAME
63
+ puts Colours.html_colourize('slateblue', 'Hello world 1!')
64
+ puts Colours.html_colourize(:crimson, 'Hello world 2!')
65
+ 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
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/italic.rb'
6
+ # =========================================================================== #
7
+ require 'colours/revert/revert.rb'
8
+ require 'colours/toplevel_methods/e.rb'
9
+ require 'colours/rgb/rgb.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === ITALIC_CODE
15
+ #
16
+ # If you wish to test italic output quickly on the terminal, then you
17
+ # can use something like this:
18
+ #
19
+ # echo -e "\e[3mone two three\e[23m"
20
+ #
21
+ # ========================================================================= #
22
+ ITALIC_CODE = '3'
23
+
24
+ # ========================================================================= #
25
+ # === Colours.return_italic
26
+ #
27
+ # To test this, try:
28
+ # Colours.italic('Hello world!')
29
+ # ========================================================================= #
30
+ def self.return_italic(
31
+ show_this_text = 'This must be italic.',
32
+ make_newline = false
33
+ )
34
+ result = "\x1b".dup
35
+ result << '['
36
+ result << ITALIC_CODE
37
+ if block_given?
38
+ # ===================================================================== #
39
+ # Right now we assume that this must be a colour.
40
+ # ===================================================================== #
41
+ result << ";38;2;"
42
+ result << html_colour_to_stringified_rgb_values(yield)
43
+ end
44
+ result << 'm'
45
+ if make_newline
46
+ show_this_text = "#{show_this_text}\n"
47
+ end
48
+ result << show_this_text
49
+ result << REVERT
50
+ result
51
+ end; self.instance_eval { alias string_italic return_italic } # === Colours.string_italic
52
+
53
+ # ========================================================================= #
54
+ # === Colours.italic
55
+ #
56
+ # This method will "puts" the result of applying italic to a string,
57
+ # on the console/terminal. If you wish to do the output on your own
58
+ # then you have to use the method Colours.return_italic or its
59
+ # alias called Colours.string_italic.
60
+ #
61
+ # To test this, try:
62
+ # Colours.italic('Hello world!')
63
+ # ========================================================================= #
64
+ def self.italic(
65
+ i = '',
66
+ make_newline = false,
67
+ &block
68
+ )
69
+ e return_italic(i, make_newline, &block)
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === italic
74
+ # ========================================================================= #
75
+ def italic(
76
+ i = '',
77
+ make_newline = false
78
+ )
79
+ ::Colours.italic(i, make_newline)
80
+ end
81
+
82
+ end
83
+
84
+ if __FILE__ == $PROGRAM_NAME
85
+ alias e puts
86
+ txt = 'Hello world!'
87
+ if ARGV.empty?
88
+ require 'colours/requires/require_all_colour_methods.rb'
89
+ COLOURS = Colours::AllColourMethods
90
+ system 'clear'
91
+ Colours.italic(txt)
92
+ e COLOURS.palegreen('italic in palegreen:')
93
+ print ' '; puts Colours.string_italic(txt) { :palegreen }
94
+ e COLOURS.slateblue('italic in slateblue:')
95
+ print ' '; puts Colours.string_italic(txt) { :slateblue }
96
+ e COLOURS.orange('italic in orange:')
97
+ print ' '; puts Colours.string_italic(txt) { :orange }
98
+ e COLOURS.crimson('italic in crimson:')
99
+ print ' '; puts Colours.string_italic(txt) { :crimson }
100
+ else
101
+ print ' '; puts Colours.string_italic(ARGV.join(' ').strip)
102
+ print ' '; puts Colours.string_italic(ARGV.join(' ').strip) { :crimson }
103
+ end
104
+ end # italic
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'colours/toplevel_methods/make_colour.rb'
6
+ # =========================================================================== #
7
+ require 'colours/constants/colour_constants.rb'
8
+ require 'colours/constants/misc.rb'
9
+ require 'colours/toplevel_methods/e.rb'
10
+
11
+ module Colours
12
+
13
+ # ========================================================================= #
14
+ # === Colours.make_colour
15
+ #
16
+ # This is used primarily for testing.
17
+ # ========================================================================= #
18
+ def self.make_colour(
19
+ what_colour_to_use
20
+ )
21
+ i = what_colour_to_use # Copy.
22
+ constant = i.to_s.upcase
23
+ name_of_colour = const_get(constant)
24
+ string = '%-34s' % ("#{name_of_colour} Test with #{constant}.")
25
+ string << IS_A_TEST+'('+name_of_colour.inspect.delete('"')+')'
26
+ e(string)
27
+ end
28
+
29
+ end