colours 0.5.48
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.
- checksums.yaml +7 -0
- data/LICENCE.md +22 -0
- data/README.md +867 -0
- data/bin/colours +7 -0
- data/bin/html_colour_to_hex_value +7 -0
- data/bin/html_colourize +7 -0
- data/bin/print_rainbow_line +7 -0
- data/bin/rainbow_colours +7 -0
- data/colours.gemspec +75 -0
- data/doc/COLOUR_CODES_CHART.md +28 -0
- data/doc/HOW_TO_PICK_YOUR_OWN_COLOURS.md +29 -0
- data/doc/README.gen +850 -0
- data/lib/colours.rb +5 -0
- data/lib/colours/256_colours/support_for_256_colours.rb +180 -0
- data/lib/colours/autoalias_e.rb +10 -0
- data/lib/colours/autogenerated/README.md +2 -0
- data/lib/colours/autogenerated/support_for_256_colours.rb +2235 -0
- data/lib/colours/autogenerated/support_for_html_colours.rb +1778 -0
- data/lib/colours/autogenerated/toplevel_basic_colour_methods.rb +6366 -0
- data/lib/colours/autoinclude.rb +14 -0
- data/lib/colours/base/base.rb +23 -0
- data/lib/colours/basic_colours/README.md +4 -0
- data/lib/colours/basic_colours/basic_colours.rb +279 -0
- data/lib/colours/colour_methods/README.md +11 -0
- data/lib/colours/colour_methods/default_colour.rb +66 -0
- data/lib/colours/colour_methods/sargument.rb +70 -0
- data/lib/colours/colour_methods/scomments.rb +105 -0
- data/lib/colours/colour_methods/sdir.rb +66 -0
- data/lib/colours/colour_methods/sfancy.rb +84 -0
- data/lib/colours/colour_methods/sfile.rb +71 -0
- data/lib/colours/colour_methods/simportant.rb +92 -0
- data/lib/colours/colour_methods/snormal.rb +66 -0
- data/lib/colours/colour_methods/ssymlink.rb +102 -0
- data/lib/colours/colour_methods/swarn.rb +76 -0
- data/lib/colours/colour_table/README.md +3 -0
- data/lib/colours/colour_table/colour_table.rb +275 -0
- data/lib/colours/colours_e_autoinclude.rb +9 -0
- data/lib/colours/commandline/README.md +2 -0
- data/lib/colours/commandline/commandline.rb +44 -0
- data/lib/colours/commandline/menu.rb +111 -0
- data/lib/colours/constants/colour_constants.rb +299 -0
- data/lib/colours/constants/file_constants.rb +72 -0
- data/lib/colours/constants/hash_simple_colours.rb +146 -0
- data/lib/colours/constants/misc.rb +59 -0
- data/lib/colours/constants/newline.rb +14 -0
- data/lib/colours/constants/registered_colour_methods.rb +53 -0
- data/lib/colours/e.rb +5 -0
- data/lib/colours/e/README.md +13 -0
- data/lib/colours/e/autoinclude.rb +11 -0
- data/lib/colours/e/e.rb +35 -0
- data/lib/colours/eparse/eparse.rb +77 -0
- data/lib/colours/everything/autoinclude.rb +11 -0
- data/lib/colours/html_colours/README.md +1 -0
- data/lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb +22 -0
- data/lib/colours/html_colours/hash_html_colours.rb +63 -0
- data/lib/colours/html_colours/html_colourize.rb +48 -0
- data/lib/colours/html_colours/is_this_html_colour_included.rb +64 -0
- data/lib/colours/html_colours/misc.rb +186 -0
- data/lib/colours/html_colours/show_html_colours.rb +85 -0
- data/lib/colours/kde_colour_palette/kde_colour_palette.rb +128 -0
- data/lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb +219 -0
- data/lib/colours/module.rb +11 -0
- data/lib/colours/project/project_base_directory.rb +22 -0
- data/lib/colours/rainbow_colours/README.md +2 -0
- data/lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb +26 -0
- data/lib/colours/rainbow_colours/constants.rb +30 -0
- data/lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb +164 -0
- data/lib/colours/rainbow_colours/paint_detected_mode.rb +20 -0
- data/lib/colours/rainbow_colours/print_rainbow_line.rb +68 -0
- data/lib/colours/rainbow_colours/println_ani.rb +32 -0
- data/lib/colours/rainbow_colours/println_plain.rb +36 -0
- data/lib/colours/rainbow_colours/rainbow.rb +38 -0
- data/lib/colours/rainbow_colours/report_errors.rb +32 -0
- data/lib/colours/rainbow_colours/returnln_plain.rb +63 -0
- data/lib/colours/rainbow_colours/set_mode.rb +24 -0
- data/lib/colours/requires/require_all_colour_methods.rb +5 -0
- data/lib/colours/requires/require_commandline.rb +7 -0
- data/lib/colours/requires/require_eparse.rb +11 -0
- data/lib/colours/requires/require_rgb.rb +5 -0
- data/lib/colours/requires/require_sdir.rb +5 -0
- data/lib/colours/requires/require_sfile.rb +5 -0
- data/lib/colours/requires/require_the_256_colours_module.rb +16 -0
- data/lib/colours/requires/require_the_basic_colours.rb +7 -0
- data/lib/colours/requires/require_the_colour_methods.rb +34 -0
- data/lib/colours/requires/require_the_colour_table.rb +7 -0
- data/lib/colours/requires/require_the_colours_project.rb +52 -0
- data/lib/colours/requires/require_the_constants.rb +11 -0
- data/lib/colours/requires/require_the_html_colours.rb +11 -0
- data/lib/colours/requires/require_the_kde_colour_palette.rb +7 -0
- data/lib/colours/requires/require_the_toplevel_methods.rb +42 -0
- data/lib/colours/revert/revert.rb +106 -0
- data/lib/colours/rgb/rgb.rb +547 -0
- data/lib/colours/testing/README.md +2 -0
- data/lib/colours/testing/testing.rb +157 -0
- data/lib/colours/toplevel_methods/bold.rb +35 -0
- data/lib/colours/toplevel_methods/bold_and_italic.rb +36 -0
- data/lib/colours/toplevel_methods/cat.rb +39 -0
- data/lib/colours/toplevel_methods/clear_screen.rb +18 -0
- data/lib/colours/toplevel_methods/cliner.rb +19 -0
- data/lib/colours/toplevel_methods/col.rb +56 -0
- data/lib/colours/toplevel_methods/e.rb +63 -0
- data/lib/colours/toplevel_methods/esystem.rb +19 -0
- data/lib/colours/toplevel_methods/fancy_parse.rb +79 -0
- data/lib/colours/toplevel_methods/html_colourize.rb +64 -0
- data/lib/colours/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/colours/toplevel_methods/italic.rb +104 -0
- data/lib/colours/toplevel_methods/make_colour.rb +29 -0
- data/lib/colours/toplevel_methods/methods_related_to_html_colours.rb +325 -0
- data/lib/colours/toplevel_methods/misc.rb +95 -0
- data/lib/colours/toplevel_methods/open_this_file.rb +26 -0
- data/lib/colours/toplevel_methods/prefer_this_colour_schemata.rb +80 -0
- data/lib/colours/toplevel_methods/random_html_colour.rb +44 -0
- data/lib/colours/toplevel_methods/random_value.rb +37 -0
- data/lib/colours/toplevel_methods/remove_escape_sequence.rb +107 -0
- data/lib/colours/toplevel_methods/set_last_colour_used.rb +32 -0
- data/lib/colours/toplevel_methods/show_basic_colour_palette.rb +36 -0
- data/lib/colours/toplevel_methods/underline.rb +114 -0
- data/lib/colours/toplevel_methods/use_colours.rb +290 -0
- data/lib/colours/utility_scripts/README.md +2 -0
- data/lib/colours/utility_scripts/autogenerate.rb +291 -0
- data/lib/colours/version/version.rb +25 -0
- data/lib/colours/yaml/256_colours.yml +277 -0
- data/lib/colours/yaml/basic_colours.yml +23 -0
- data/lib/colours/yaml/html_colours.yml +835 -0
- data/lib/colours/yaml/kde_colour_palette.yml +183 -0
- data/lib/colours/yaml/prefer_this_colour_schemata.yml +15 -0
- data/lib/colours/yaml/use_these_values_for_the_colour_methods.yml +13 -0
- data/test/test.html +18 -0
- data/test/testing_256_colours_support.rb +29 -0
- data/test/testing_col.rb +10 -0
- data/test/testing_colours.rb +95 -0
- data/test/testing_colours_e.rb +13 -0
- data/test/testing_eparse.rb +13 -0
- data/test/testing_kde_colour_palette.rb +30 -0
- data/test/testing_konsole_submodule.rb +226 -0
- data/test/testing_map_symbol_to_corresponding_colour.rb +14 -0
- data/test/testing_rgb_to_hex.rb +32 -0
- data/test/testing_the_basic_colours_of_the_colours_project.rb +58 -0
- data/test/testing_the_colour_methods.rb +36 -0
- data/test/testing_the_constants_of_the_colours_project.rb +9 -0
- data/test/testing_the_html_colours_of_the_colours_project.rb +37 -0
- data/test/testing_whether_colours_will_be_used.rb +7 -0
- metadata +224 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/rainbow_colours/set_mode.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Colours
|
8
|
+
|
9
|
+
module RainbowColours
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === Colours::RainbowColours.set_mode
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.set_mode(truecolor)
|
15
|
+
begin
|
16
|
+
unless Object.const_defined? :Paint
|
17
|
+
require 'paint'
|
18
|
+
end
|
19
|
+
@paint_mode_detected ||= Paint.mode
|
20
|
+
Paint.mode = truecolor ? 0xffffff : @paint_mode_detected
|
21
|
+
rescue LoadError; end
|
22
|
+
end
|
23
|
+
|
24
|
+
end; end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_commandline.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/commandline/commandline.rb'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_eparse.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
|
8
|
+
# =========================================================================== #
|
9
|
+
# Add the .eparse() functionality:
|
10
|
+
# =========================================================================== #
|
11
|
+
require 'colours/eparse/eparse.rb'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# Note that this .rb file is normally NOT required the colours gem by
|
6
|
+
# default - it is only meant to be required manually.
|
7
|
+
# =========================================================================== #
|
8
|
+
# require 'colours/requires/require_the_256_colours_module.rb'
|
9
|
+
# =========================================================================== #
|
10
|
+
|
11
|
+
# =========================================================================== #
|
12
|
+
# Add support for the 256-colours:
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'colours/256_colours/support_for_256_colours.rb'
|
15
|
+
|
16
|
+
require 'colours/autogenerated/support_for_256_colours.rb'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_the_basic_colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/basic_colours/basic_colours.rb'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# The "colour-methods" are methods such as sdir(), swarn() and so forth.
|
6
|
+
#
|
7
|
+
# The file here specifies code that can be used to require these .rb
|
8
|
+
# files from the given colour_methods/ subdirectory of the colours
|
9
|
+
# project.
|
10
|
+
# =========================================================================== #
|
11
|
+
# require 'colours/requires/require_the_colour_methods.rb'
|
12
|
+
# =========================================================================== #
|
13
|
+
require 'colours/project/project_base_directory.rb'
|
14
|
+
|
15
|
+
module Colours
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === Colours.require_the_colour_methods
|
19
|
+
#
|
20
|
+
# This method will batch-require the .rb files that are found in the
|
21
|
+
# colour_methods/ subdirectory of the colours gem.
|
22
|
+
# ========================================================================= #
|
23
|
+
def self.require_the_colour_methods
|
24
|
+
target = "#{Colours::PROJECT_BASE_DIRECTORY}colour_methods/"
|
25
|
+
|
26
|
+
Dir["#{target}*.rb"].each {|this_file|
|
27
|
+
require target+File.basename(this_file)
|
28
|
+
}
|
29
|
+
|
30
|
+
end; self.instance_eval { alias default_string_methods require_the_colour_methods } # === Colours.default_string_methods
|
31
|
+
|
32
|
+
Colours.require_the_colour_methods # Also trigger the above method at once.
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_the_colour_table.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/colour_table/colour_table.rb'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'colours/project/project_base_directory.rb'
|
6
|
+
require 'colours/requires/require_the_constants.rb'
|
7
|
+
require 'colours/requires/require_the_basic_colours.rb'
|
8
|
+
require 'colours/requires/require_the_toplevel_methods.rb'
|
9
|
+
# =========================================================================== #
|
10
|
+
# Next require the colour-methods:
|
11
|
+
# =========================================================================== #
|
12
|
+
require 'colours/requires/require_the_colour_methods.rb'
|
13
|
+
# =========================================================================== #
|
14
|
+
# Next require the html-colours components of the colours project:
|
15
|
+
# =========================================================================== #
|
16
|
+
require 'colours/requires/require_the_html_colours.rb'
|
17
|
+
require 'colours/requires/require_eparse.rb'
|
18
|
+
require 'colours/requires/require_commandline.rb'
|
19
|
+
require 'colours/requires/require_the_colour_table.rb'
|
20
|
+
require 'colours/requires/require_rgb.rb'
|
21
|
+
require 'colours/requires/require_the_256_colours_module.rb'
|
22
|
+
require 'colours/requires/require_the_kde_colour_palette.rb'
|
23
|
+
require 'colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb'
|
24
|
+
# =========================================================================== #
|
25
|
+
# Require the big "symbol-mapper" next:
|
26
|
+
# =========================================================================== #
|
27
|
+
require 'colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb'
|
28
|
+
# =========================================================================== #
|
29
|
+
# Load up the testing-relevant code:
|
30
|
+
# =========================================================================== #
|
31
|
+
require 'colours/testing/testing.rb'
|
32
|
+
# =========================================================================== #
|
33
|
+
# Next, add the submodule at "Colours::E":
|
34
|
+
# =========================================================================== #
|
35
|
+
require 'colours/e/e.rb'
|
36
|
+
require 'colours/autogenerated/support_for_html_colours.rb'
|
37
|
+
require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
|
38
|
+
require 'colours/base/base.rb'
|
39
|
+
require 'colours/version/version.rb'
|
40
|
+
require 'colours/utility_scripts/autogenerate.rb'
|
41
|
+
|
42
|
+
module Colours
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# We have to put the ColourMethods into the toplevel namespace at once,
|
46
|
+
# so that methods such as slateblue() are defined.
|
47
|
+
# ========================================================================= #
|
48
|
+
extend ::Colours::AllColourMethods
|
49
|
+
|
50
|
+
include ::Colours::AllColourMethods
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'colours/constants/colour_constants.rb'
|
6
|
+
require 'colours/constants/file_constants.rb'
|
7
|
+
require 'colours/constants/hash_simple_colours.rb'
|
8
|
+
require 'colours/constants/misc.rb'
|
9
|
+
require 'colours/constants/newline.rb'
|
10
|
+
require 'colours/constants/registered_colour_methods.rb'
|
11
|
+
require 'colours/revert/revert.rb'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_the_html_colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
|
8
|
+
# =========================================================================== #
|
9
|
+
# Require the html-colours components of the colours project:
|
10
|
+
# =========================================================================== #
|
11
|
+
require 'colours/html_colours/misc.rb'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/requires/require_the_kde_colour_palette.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'colours/kde_colour_palette/kde_colour_palette.rb'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# This file will pull in all .rb files that reside in the
|
6
|
+
# colours/toplevel_methods/ subdirectory.
|
7
|
+
# =========================================================================== #
|
8
|
+
require 'colours/project/project_base_directory.rb'
|
9
|
+
|
10
|
+
require_these_files = Dir["#{Colours::PROJECT_BASE_DIRECTORY}toplevel_methods/*.rb"]
|
11
|
+
|
12
|
+
if require_these_files.empty?
|
13
|
+
# ===================================================================== #
|
14
|
+
# If we can not find any of the files then we will use a hardcoded
|
15
|
+
# approach, which follows next.
|
16
|
+
# ===================================================================== #
|
17
|
+
require_these_files = %w(
|
18
|
+
bold_and_italic.rb
|
19
|
+
bold.rb
|
20
|
+
cat.rb
|
21
|
+
clear_screen.rb
|
22
|
+
cliner.rb
|
23
|
+
col.rb
|
24
|
+
e.rb
|
25
|
+
html_colourize.rb
|
26
|
+
is_on_roebe.rb
|
27
|
+
italic.rb
|
28
|
+
make_colour.rb
|
29
|
+
misc.rb
|
30
|
+
prefer_this_colour_schemata.rb
|
31
|
+
random_html_colour.rb
|
32
|
+
random_value.rb
|
33
|
+
remove_escape_sequence.rb
|
34
|
+
show_basic_colour_palette.rb
|
35
|
+
underline.rb
|
36
|
+
use_colours.rb
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
require_these_files.each {|this_file|
|
41
|
+
require "colours/toplevel_methods/#{File.basename(this_file)}"
|
42
|
+
}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal = true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'colours/revert/revert.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Colours
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === Colours::ESC
|
11
|
+
#
|
12
|
+
# Escape sequences start with the character ESC (ASCII decimal 27/hex
|
13
|
+
# 0x1B/octal 033).
|
14
|
+
#
|
15
|
+
# The characters ESC and [ (left bracket) are called CSI, for "Control
|
16
|
+
# Sequence Initiator".
|
17
|
+
#
|
18
|
+
# Keep in mind that "\e" can be represented via "\u001b" in Ruby, too.
|
19
|
+
# ========================================================================= #
|
20
|
+
ESC = "\e["
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === Colours::COLOUR_NC
|
24
|
+
#
|
25
|
+
# Note that this will actually reset all attributes.
|
26
|
+
#
|
27
|
+
# The "\e[0m" sequence removes all attributes, including formatting
|
28
|
+
# and colours. It may be useful to add it to the end of each colour
|
29
|
+
# text - and this is what the Colours project is essentially doing.
|
30
|
+
#
|
31
|
+
# An alternative may be to assign REVERT to WHITE, but this seems
|
32
|
+
# to be incorrect according to the specification.
|
33
|
+
# ========================================================================= #
|
34
|
+
COLOUR_NC = "#{ESC}0m" # No Colour.
|
35
|
+
REVERT = COLOUR_NC # === REVERT
|
36
|
+
REV = COLOUR_NC # === REV
|
37
|
+
CLOSING_TAG = COLOUR_NC # === CLOSING_TAG (also represented as "#{ESC}0m")
|
38
|
+
RESET = COLOUR_NC # === RESET
|
39
|
+
RESET_TERMINAL = COLOUR_NC # === RESET_TERMINAL
|
40
|
+
CLEAR = COLOUR_NC # === CLEAR
|
41
|
+
COLOUR_RESET = COLOUR_NC # === COLOUR_RESET
|
42
|
+
DEFAULT_COLOUR = COLOUR_RESET # === DEFAULT_COLOUR
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === RESET_ALL_ATTRIBUTES
|
46
|
+
#
|
47
|
+
# This is essentially the same as COLOUR_NC / RESET.
|
48
|
+
# ========================================================================= #
|
49
|
+
RESET_ALL_ATTRIBUTES = "\x1b[0m"
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === @revert
|
53
|
+
# ========================================================================= #
|
54
|
+
@revert = "\e[0;37m"
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === Colours.set_revert
|
58
|
+
# ========================================================================= #
|
59
|
+
def self.set_revert(i = :default)
|
60
|
+
case i
|
61
|
+
when :default
|
62
|
+
i = REVERT
|
63
|
+
end
|
64
|
+
@revert = i
|
65
|
+
end
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === Colours.rev
|
69
|
+
#
|
70
|
+
# We use this method to revert to the old default, that is, the prior
|
71
|
+
# state for ANSI colours. It should be equivalent to: "\x1b[0m" e. g.
|
72
|
+
# REVERT = "\x1b[0m" # "\x1b[39;49m" <--- This here seems to fail for Konsole.underline, though.
|
73
|
+
#
|
74
|
+
# An alternative could be DEFAULT_COLOUR.
|
75
|
+
# ========================================================================= #
|
76
|
+
def self.rev
|
77
|
+
# REVERT # <- This used to be: "\e[0;37m"
|
78
|
+
@revert # This is light white. I prefer this colour actually.
|
79
|
+
end; self.instance_eval { alias revert rev } # === Colours.revert
|
80
|
+
self.instance_eval { alias revert? rev } # === Colours.revert?
|
81
|
+
self.instance_eval { alias restore? rev } # === Colours.restore?
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === rev
|
85
|
+
#
|
86
|
+
# Use this method to "revert" to the old default colour again, by
|
87
|
+
# delegating towards the Colours.rev() method defined above.
|
88
|
+
#
|
89
|
+
# From this point on, we use methods that can be toggled.
|
90
|
+
# ========================================================================= #
|
91
|
+
def rev(i = '')
|
92
|
+
::Colours.rev # This will refer to the Colours.rev() module method.
|
93
|
+
end; alias revert rev # === revert
|
94
|
+
# alias default_colour rev
|
95
|
+
|
96
|
+
# ========================================================================= #
|
97
|
+
# === restore?
|
98
|
+
#
|
99
|
+
# This will restore to the default again.
|
100
|
+
# ========================================================================= #
|
101
|
+
def restore?
|
102
|
+
Colours.restore?
|
103
|
+
end; alias revert restore? # === revert
|
104
|
+
alias rev? restore? # === rev?
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,547 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Colours::RGB
|
6
|
+
#
|
7
|
+
# The Colours::RBG class was used to convert from RGB values to hex
|
8
|
+
# format. However had these days it is not as widely used anymore
|
9
|
+
# within the colours project.
|
10
|
+
#
|
11
|
+
# Code in this .rb file here in general can be used for RGB-related
|
12
|
+
# functionality. A good example for what can be done with this is to
|
13
|
+
# convert a HTML colour, such as "slateblue", into its RGB
|
14
|
+
# representation.
|
15
|
+
# =========================================================================== #
|
16
|
+
# require 'colours/rgb/rgb.rb'
|
17
|
+
# =========================================================================== #
|
18
|
+
module Colours
|
19
|
+
|
20
|
+
class RGB # === Colours::RGB
|
21
|
+
|
22
|
+
require 'colours/constants/misc.rb' # For methods such as left?.
|
23
|
+
# require 'colours/html_colours/hash_html_colours.rb'
|
24
|
+
# require 'colours/html_colours/is_this_html_colour_included.rb'
|
25
|
+
# require 'colours/toplevel_methods/random_html_colour.rb'
|
26
|
+
# require 'colours/toplevel_methods/random_value.rb'
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === DEFAULT_VALUES
|
30
|
+
# ========================================================================= #
|
31
|
+
DEFAULT_VALUES = [255, 0, 0]
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === DEFAULT_VALUE
|
35
|
+
# ========================================================================= #
|
36
|
+
DEFAULT_VALUE = 0
|
37
|
+
|
38
|
+
# =========================================================================== #
|
39
|
+
# === initialize
|
40
|
+
#
|
41
|
+
# Keep in mind that the first argument could be something like:
|
42
|
+
#
|
43
|
+
# [106, 90, 205]
|
44
|
+
#
|
45
|
+
# In that case, we need to continue differently.
|
46
|
+
# =========================================================================== #
|
47
|
+
def initialize(
|
48
|
+
original_input = ARGV,
|
49
|
+
run_already = true
|
50
|
+
)
|
51
|
+
reset
|
52
|
+
set_commandline_arguments(
|
53
|
+
original_input
|
54
|
+
)
|
55
|
+
run if run_already
|
56
|
+
end
|
57
|
+
|
58
|
+
# =========================================================================== #
|
59
|
+
# === set_commandline_arguments
|
60
|
+
# =========================================================================== #
|
61
|
+
def set_commandline_arguments(i)
|
62
|
+
@commandline_arguments = [i].flatten.compact
|
63
|
+
end
|
64
|
+
|
65
|
+
# =========================================================================== #
|
66
|
+
# === reset
|
67
|
+
# =========================================================================== #
|
68
|
+
def reset
|
69
|
+
@r, @g, @b = 0, 0, 0 # Use default values for RGB.
|
70
|
+
end
|
71
|
+
|
72
|
+
# ========================================================================= #
|
73
|
+
# === b?
|
74
|
+
# ========================================================================= #
|
75
|
+
def b?
|
76
|
+
@b
|
77
|
+
end; alias b b? # === b
|
78
|
+
|
79
|
+
# ========================================================================= #
|
80
|
+
# === g?
|
81
|
+
# ========================================================================= #
|
82
|
+
def g?
|
83
|
+
@g
|
84
|
+
end; alias g g? # === g
|
85
|
+
|
86
|
+
# ========================================================================= #
|
87
|
+
# === hexstring?
|
88
|
+
# ========================================================================= #
|
89
|
+
def hexstring?
|
90
|
+
@hexstring
|
91
|
+
end; alias hexstring hexstring? # === hexstring
|
92
|
+
|
93
|
+
# ========================================================================= #
|
94
|
+
# === r?
|
95
|
+
# ========================================================================= #
|
96
|
+
def r?
|
97
|
+
@r
|
98
|
+
end; alias r r? # === r
|
99
|
+
|
100
|
+
# ========================================================================= #
|
101
|
+
# === determine_rgb_values_from_the_commandline_arguments
|
102
|
+
# ========================================================================= #
|
103
|
+
def determine_rgb_values_from_the_commandline_arguments
|
104
|
+
_ = @commandline_arguments
|
105
|
+
first = _.first
|
106
|
+
if first.is_? Array
|
107
|
+
set_r(first[0])
|
108
|
+
set_g(first[1])
|
109
|
+
set_b(first[2])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# ========================================================================= #
|
114
|
+
# === rgb
|
115
|
+
# ========================================================================= #
|
116
|
+
def rgb
|
117
|
+
[ @r, @g, @b ]
|
118
|
+
end
|
119
|
+
|
120
|
+
# ========================================================================= #
|
121
|
+
# === check_validity_of
|
122
|
+
#
|
123
|
+
# We check if the input is higher than 255, in which case we give back
|
124
|
+
# an ArgumentError.
|
125
|
+
# ========================================================================= #
|
126
|
+
def check_validity_of(i)
|
127
|
+
if i.to_i > 255
|
128
|
+
raise ArgumentError,
|
129
|
+
'Error: RGB values can not be higher than 255.'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# ========================================================================= #
|
134
|
+
# === do_the_conversion
|
135
|
+
# ========================================================================= #
|
136
|
+
def do_the_conversion
|
137
|
+
@hexstring = '#%02x%02x%02x'.upcase % rgb()
|
138
|
+
return @hexstring
|
139
|
+
end; alias update_hexstring do_the_conversion # === update_hexstring
|
140
|
+
|
141
|
+
# ========================================================================= #
|
142
|
+
# === set_rgb
|
143
|
+
# ========================================================================= #
|
144
|
+
def set_rgb(r,g,b)
|
145
|
+
set_r(r)
|
146
|
+
set_g(g)
|
147
|
+
set_b(b)
|
148
|
+
end
|
149
|
+
|
150
|
+
# ========================================================================= #
|
151
|
+
# === set_r
|
152
|
+
# ========================================================================= #
|
153
|
+
def set_r(i = DEFAULT_VALUES[0])
|
154
|
+
i = i.to_i
|
155
|
+
check_validity_of(i)
|
156
|
+
@r = i
|
157
|
+
end
|
158
|
+
|
159
|
+
# ========================================================================= #
|
160
|
+
# === set_g
|
161
|
+
# ========================================================================= #
|
162
|
+
def set_g(i = nil)
|
163
|
+
i = DEFAULT_VALUE if i.nil?
|
164
|
+
i = i.to_i
|
165
|
+
check_validity_of(i)
|
166
|
+
@g = i
|
167
|
+
end
|
168
|
+
|
169
|
+
# ========================================================================= #
|
170
|
+
# === set_b
|
171
|
+
# ========================================================================= #
|
172
|
+
def set_b(i = nil)
|
173
|
+
i = DEFAULT_VALUE if i.nil?
|
174
|
+
i = i.to_i
|
175
|
+
check_validity_of(i)
|
176
|
+
@b = i
|
177
|
+
end
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === lighten
|
181
|
+
#
|
182
|
+
# This lightens up a colour.
|
183
|
+
# RgbToHex.new('#ffffff').lighten # => "#232323"
|
184
|
+
# ========================================================================= #
|
185
|
+
def lighten
|
186
|
+
add(35) # Hardcoded to add +35 to each of R, G and B.
|
187
|
+
end
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === add
|
191
|
+
#
|
192
|
+
# This method can be used to lighten a R,G,B colour in general. We
|
193
|
+
# also use another method for this, though, called .lighten().
|
194
|
+
# ========================================================================= #
|
195
|
+
def add(i = 1)
|
196
|
+
i = i.to_i
|
197
|
+
@r += i
|
198
|
+
@g += i
|
199
|
+
@b += i
|
200
|
+
update_hexstring
|
201
|
+
end
|
202
|
+
|
203
|
+
# =========================================================================== #
|
204
|
+
# === run
|
205
|
+
# =========================================================================== #
|
206
|
+
def run
|
207
|
+
determine_rgb_values_from_the_commandline_arguments
|
208
|
+
do_the_conversion
|
209
|
+
end
|
210
|
+
|
211
|
+
# ========================================================================= #
|
212
|
+
# === RgbToHex[]
|
213
|
+
#
|
214
|
+
# Easier access to the conversion facility.
|
215
|
+
#
|
216
|
+
# Usage example:
|
217
|
+
# RgbToHex[22,33,44] # => "#16212C"
|
218
|
+
# ========================================================================= #
|
219
|
+
def self.[](r = 255, g = 0, b = 0)
|
220
|
+
_ = RgbToHex.new(r,g,b)
|
221
|
+
return '#%02x%02x%02x'.upcase % _.rgb
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
# =========================================================================== #
|
227
|
+
# === Colours.convert_this_rgb_value_into_a_html_colour
|
228
|
+
#
|
229
|
+
# This method will convert a given RGB value (input assumed to be an Array)
|
230
|
+
# into the corresponding HTML colour.
|
231
|
+
#
|
232
|
+
# Note that the first input argument, called `i`, can also be read as
|
233
|
+
# R (aka red). So the whole input line becomes "r, g, b", which makes
|
234
|
+
# this quite trivial to remember.
|
235
|
+
# =========================================================================== #
|
236
|
+
def self.convert_this_rgb_value_into_a_html_colour(i, g = nil, b = nil)
|
237
|
+
if i.is_a?(Numeric) and g and b
|
238
|
+
i = [i, g, b] # Re-compose the given input in this case, as only one Array was provided.
|
239
|
+
end
|
240
|
+
_ = Colours.hash_html_colours?
|
241
|
+
possible_matches = _.select {|key, inner_array|
|
242
|
+
(i[0] == inner_array[0]) and
|
243
|
+
(i[1] == inner_array[1]) and
|
244
|
+
(i[2] == inner_array[2])
|
245
|
+
}
|
246
|
+
possible_matches.keys.first
|
247
|
+
end
|
248
|
+
|
249
|
+
# =========================================================================== #
|
250
|
+
# === Colours.convert_this_html_colour_into_an_array_of_rgb_values
|
251
|
+
#
|
252
|
+
# This method will take a String as input, a HTML colour such as 'slateblue',
|
253
|
+
# and proceed to return an Array containing three entries (R, G, B) as
|
254
|
+
# its value.
|
255
|
+
#
|
256
|
+
# For RGB colours we specify the code like this:
|
257
|
+
#
|
258
|
+
# 38;2;$R;$G;$B
|
259
|
+
#
|
260
|
+
# Thus:
|
261
|
+
#
|
262
|
+
# \e[38;2;R;G;Bm
|
263
|
+
#
|
264
|
+
# =========================================================================== #
|
265
|
+
def self.convert_this_html_colour_into_an_array_of_rgb_values(
|
266
|
+
html_colour = :random
|
267
|
+
)
|
268
|
+
case html_colour
|
269
|
+
when :random
|
270
|
+
html_colour = return_random_html_colour
|
271
|
+
end
|
272
|
+
if Colours.include_this_html_colour? html_colour
|
273
|
+
pointer = Colours.hash_html_colours?[html_colour.to_s] # <- Must be an input-String.
|
274
|
+
[ pointer[0], pointer[1], pointer[2] ] # <- Build the Array here.
|
275
|
+
else # else it is not included
|
276
|
+
nil
|
277
|
+
end
|
278
|
+
end; self.instance_eval { alias convert_html_colour_to_rgb_array convert_this_html_colour_into_an_array_of_rgb_values } # === Colours.convert_html_colour_to_rgb_array
|
279
|
+
|
280
|
+
# =========================================================================== #
|
281
|
+
# === Colours.return_random_rgb
|
282
|
+
# =========================================================================== #
|
283
|
+
def self.return_random_rgb
|
284
|
+
[random_value?, random_value?, random_value?]
|
285
|
+
end; self.instance_eval { alias return_rgb_as_array return_random_rgb } # === Colours.return_rgb_as_array
|
286
|
+
|
287
|
+
# =========================================================================== #
|
288
|
+
# === return_random_rgb
|
289
|
+
# =========================================================================== #
|
290
|
+
def return_random_rgb
|
291
|
+
Colours.return_random_rgb
|
292
|
+
end; alias return_rgb_as_array return_random_rgb # === return_rgb_as_array
|
293
|
+
|
294
|
+
# =========================================================================== #
|
295
|
+
# === rgb_value_as_escape_code_string
|
296
|
+
# =========================================================================== #
|
297
|
+
def rgb_value_as_escape_code_string(
|
298
|
+
array = [
|
299
|
+
random_value?,
|
300
|
+
random_value?,
|
301
|
+
random_value?
|
302
|
+
],
|
303
|
+
g = nil,
|
304
|
+
b = nil
|
305
|
+
)
|
306
|
+
end; alias build_this_rgb_string rgb_value_as_escape_code_string # === build_this_rgb_string
|
307
|
+
alias rgb_value_as_string rgb_value_as_escape_code_string # === rgb_value_as_string
|
308
|
+
alias rgb rgb_value_as_escape_code_string # === rgb
|
309
|
+
alias rgb_format rgb_value_as_escape_code_string # === rgb_format
|
310
|
+
alias rgb_as_string rgb_value_as_escape_code_string # === rgb_as_string
|
311
|
+
alias colour_to_rgb_value rgb_value_as_escape_code_string # === colour_to_rgb_value
|
312
|
+
|
313
|
+
# =========================================================================== #
|
314
|
+
# === convert_this_rgb_value_to_that_hexadecimal_representation
|
315
|
+
# =========================================================================== #
|
316
|
+
def convert_this_rgb_value_to_that_hexadecimal_representation(
|
317
|
+
r, g = nil, b = nil
|
318
|
+
)
|
319
|
+
Colours.convert_this_rgb_value_to_that_hexadecimal_representation(r, g, b)
|
320
|
+
end; alias rgb_to_hex convert_this_rgb_value_to_that_hexadecimal_representation # === rgb_to_hex
|
321
|
+
alias to_hex convert_this_rgb_value_to_that_hexadecimal_representation # === to_hex
|
322
|
+
|
323
|
+
# =========================================================================== #
|
324
|
+
# === Colours.random_html_colour_with_this_text
|
325
|
+
#
|
326
|
+
# The first argument is the text that we wish to display.
|
327
|
+
#
|
328
|
+
# Usage example:
|
329
|
+
#
|
330
|
+
# puts Colours.random_html_colour_with_this_text 'foo bar'
|
331
|
+
#
|
332
|
+
# =========================================================================== #
|
333
|
+
def self.random_html_colour_with_this_text(
|
334
|
+
use_this_text = ''
|
335
|
+
)
|
336
|
+
"#{rgb_value_as_escape_code_string}#{use_this_text}#{restore?}"
|
337
|
+
end
|
338
|
+
|
339
|
+
# =========================================================================== #
|
340
|
+
# === Colours.rgb_print
|
341
|
+
#
|
342
|
+
# The first argument to this method should be an Array.
|
343
|
+
#
|
344
|
+
# We will print here. If you need a newline appended, you have to do
|
345
|
+
# so on your own, by appending a \n onto the text variable given to
|
346
|
+
# this method - or use Colours.rgb_puts() instead.
|
347
|
+
#
|
348
|
+
# Specific usage examples:
|
349
|
+
# Colours.rgb_print ["100", "247", "63"], 'Hello '
|
350
|
+
# Colours.rgb_print ["100", "247", "25"], 'World!'
|
351
|
+
# =========================================================================== #
|
352
|
+
def self.rgb_print(
|
353
|
+
array = %w( 100 247 63 ),
|
354
|
+
text = 'Hello world!'
|
355
|
+
)
|
356
|
+
print "#{rgb_value_as_escape_code_string(array)}#{text}#{REVERT}"
|
357
|
+
end
|
358
|
+
|
359
|
+
# =========================================================================== #
|
360
|
+
# === Colours.rgb_puts
|
361
|
+
#
|
362
|
+
# First argument should be an Array.
|
363
|
+
#
|
364
|
+
# We will use puts here.
|
365
|
+
#
|
366
|
+
# Specific usage examples:
|
367
|
+
# Colours.rgb_puts ["100", "247", "63"], 'Hello '
|
368
|
+
# Colours.rgb_puts ["100", "247", "25"], 'World!'
|
369
|
+
# =========================================================================== #
|
370
|
+
def self.rgb_puts(
|
371
|
+
array = %w( 100 247 63 ),
|
372
|
+
text = 'Hello world!'
|
373
|
+
)
|
374
|
+
rgb_print(array, "#{text}\n")
|
375
|
+
end
|
376
|
+
|
377
|
+
# =========================================================================== #
|
378
|
+
# === Colours.return_this_text_in_random_colour
|
379
|
+
#
|
380
|
+
# Invocation example:
|
381
|
+
# puts Colours.return_this_text_in_random_colour('Hello World!')
|
382
|
+
# =========================================================================== #
|
383
|
+
def self.return_this_text_in_random_colour(
|
384
|
+
show_this_text = ''
|
385
|
+
)
|
386
|
+
use_this_colour = ::Colours.random_colour?
|
387
|
+
"#{rgb(use_this_colour)}#{show_this_text}#{restore?}"
|
388
|
+
end; self.instance_eval { alias return_this_in_random_colour return_this_text_in_random_colour } # === Colours.return_this_in_random_colour
|
389
|
+
|
390
|
+
# =========================================================================== #
|
391
|
+
# === Colours.write_this_in_random_colour
|
392
|
+
#
|
393
|
+
# Usage example:
|
394
|
+
# Colours.write_this_in_random_colour 'hi there'
|
395
|
+
# =========================================================================== #
|
396
|
+
def self.write_this_in_random_colour(
|
397
|
+
i = ''
|
398
|
+
)
|
399
|
+
e return_this_text_in_random_colour(i)
|
400
|
+
end; self.instance_eval { alias output_in_a_random_colour write_this_in_random_colour } # === Colours.write_this_in_random_colour
|
401
|
+
|
402
|
+
# =========================================================================== #
|
403
|
+
# === Colours.convert_this_rgb_value_to_that_hexadecimal_representation
|
404
|
+
#
|
405
|
+
# This method will convert RGB values to their hexadecimal (hex)
|
406
|
+
# representation.
|
407
|
+
#
|
408
|
+
# Invocation example:
|
409
|
+
#
|
410
|
+
# Colours.convert_this_rgb_value_to_that_hexadecimal_representation([240, 248, 255]) # => "F0F8FF"
|
411
|
+
# Colours.rgb_to_hex(255,0,0) # => "FF0000"
|
412
|
+
# Colours.rgb_to_hex('255255255')
|
413
|
+
# Colours.rgb_to_hex(:slateblue)
|
414
|
+
#
|
415
|
+
# =========================================================================== #
|
416
|
+
def self.convert_this_rgb_value_to_that_hexadecimal_representation(
|
417
|
+
r, g = nil, b = nil
|
418
|
+
)
|
419
|
+
hash = Colours.hash_html_colours?
|
420
|
+
if r.is_a?(Symbol) and g.nil? and b.nil? and
|
421
|
+
is_this_a_html_colour?(r)
|
422
|
+
return hash[r.to_s][3]
|
423
|
+
end
|
424
|
+
if r.is_a?(String) and !r.include?('#') and g.nil? and b.nil?
|
425
|
+
# ======================================================================= #
|
426
|
+
# In this case assume input such as '255255255'
|
427
|
+
# ======================================================================= #
|
428
|
+
splitted = r.split(/(...)/).reject(&:empty?)
|
429
|
+
r, g, b = splitted
|
430
|
+
end
|
431
|
+
if r.is_a?(Array) and (r.size > 1) and g.nil? and b.nil?
|
432
|
+
# ======================================================================= #
|
433
|
+
# In this case the user supplied only a single Array as input.
|
434
|
+
# ======================================================================= #
|
435
|
+
this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r)
|
436
|
+
else
|
437
|
+
this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r, g, b)
|
438
|
+
end
|
439
|
+
if this_html_colour
|
440
|
+
hash[this_html_colour][3]
|
441
|
+
else
|
442
|
+
nil
|
443
|
+
end
|
444
|
+
end; self.instance_eval { alias rgb_to_hex convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.rgb_to_hex
|
445
|
+
self.instance_eval { alias to_hex convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.to_hex
|
446
|
+
self.instance_eval { alias return_hexvalue_of_this_colour convert_this_rgb_value_to_that_hexadecimal_representation } # === Colours.return_hexvalue_of_this_colour
|
447
|
+
|
448
|
+
# =========================================================================== #
|
449
|
+
# === Colours.html_colour_to_rgb_value
|
450
|
+
#
|
451
|
+
# This method will return a String, representing the RGB values.
|
452
|
+
#
|
453
|
+
# It will, other than that, not make any other modifications; in particular
|
454
|
+
# it will NOT append a trailing "m" token.
|
455
|
+
#
|
456
|
+
# By default the R, G, B values will be separated via a ';' token. If
|
457
|
+
# you don't want this then modify it e. g. via: .tr(';',',').
|
458
|
+
#
|
459
|
+
# Usage examples:
|
460
|
+
#
|
461
|
+
# Colours.html_colour_to_rgb_value('slateblue') # => "106;90;205"
|
462
|
+
# Colours.html_colour_to_rgb_value('crimson') # => "220;20;60"
|
463
|
+
# Colours.html_colour_to_rgb(:steelblue) # => "70;130;180"
|
464
|
+
#
|
465
|
+
# =========================================================================== #
|
466
|
+
def self.html_colour_to_rgb_value(
|
467
|
+
this_html_colour = 'slateblue'
|
468
|
+
)
|
469
|
+
_ = Colours.convert_this_html_colour_into_an_array_of_rgb_values(this_html_colour.to_sym)
|
470
|
+
return "#{_[0]};#{_[1]};#{_[2]}"
|
471
|
+
end; self.instance_eval { alias colour_to_rgb_value html_colour_to_rgb_value } # === Colours.colour_to_rgb_value
|
472
|
+
self.instance_eval { alias convert_html_colour_to_rgb_value html_colour_to_rgb_value } # === Colours.convert_html_colour_to_rgb_value
|
473
|
+
self.instance_eval { alias html_colour_to_stringified_rgb_values html_colour_to_rgb_value } # === Colours.html_colour_to_stringified_rgb_values
|
474
|
+
self.instance_eval { alias html_colour_to_rgb html_colour_to_rgb_value } # === Colours.html_colour_to_rgb
|
475
|
+
|
476
|
+
# =========================================================================== #
|
477
|
+
# === Colours.rgb_value_as_escape_code_string
|
478
|
+
#
|
479
|
+
# This method will take a R,G,B value and show us a String representation
|
480
|
+
# =========================================================================== #
|
481
|
+
def self.rgb_value_as_escape_code_string(
|
482
|
+
array = [
|
483
|
+
random_value?,
|
484
|
+
random_value?,
|
485
|
+
random_value?
|
486
|
+
],
|
487
|
+
g = nil,
|
488
|
+
b = nil
|
489
|
+
)
|
490
|
+
if array.is_a? Symbol
|
491
|
+
array = array.to_s
|
492
|
+
end
|
493
|
+
if array.is_a?(Array) and (array.size == 3)
|
494
|
+
r = array[0]
|
495
|
+
g = array[1]
|
496
|
+
b = array[2]
|
497
|
+
elsif array.is_a?(String) and g.nil? and b.nil?
|
498
|
+
# ======================================================================= #
|
499
|
+
# In this case we will assume a HTML colour. We thus have to
|
500
|
+
# determine its rgb value.
|
501
|
+
# ======================================================================= #
|
502
|
+
if ::Colours.is_this_html_colour_included?(array)
|
503
|
+
set_last_colour_used(array)
|
504
|
+
r, g, b = Colours.convert_this_html_colour_into_an_array_of_rgb_values(array)
|
505
|
+
else
|
506
|
+
puts 'The input is not a HTML colour:'
|
507
|
+
pp array
|
508
|
+
end
|
509
|
+
end
|
510
|
+
# =========================================================================== #
|
511
|
+
# The String that we build up in this method will have the ANSI escape
|
512
|
+
# code on the left side.
|
513
|
+
# =========================================================================== #
|
514
|
+
return "#{left?}#{r};#{g};#{b}m"
|
515
|
+
end; self.instance_eval { alias build_this_rgb_string rgb_value_as_escape_code_string } # === Colours.build_this_rgb_string
|
516
|
+
self.instance_eval { alias rgb_value_as_string rgb_value_as_escape_code_string } # === Colours.rgb_value_as_string
|
517
|
+
self.instance_eval { alias rgb rgb_value_as_escape_code_string } # === Colours.rgb
|
518
|
+
self.instance_eval { alias rgb_format rgb_value_as_escape_code_string } # === Colours.rgb_format
|
519
|
+
self.instance_eval { alias rgb_as_string rgb_value_as_escape_code_string } # === Colours.rgb_as_string
|
520
|
+
self.instance_eval { alias colour_to_rgb_value rgb_value_as_escape_code_string } # === Colours.colour_to_rgb_value
|
521
|
+
|
522
|
+
end
|
523
|
+
|
524
|
+
if __FILE__ == $PROGRAM_NAME
|
525
|
+
alias e puts
|
526
|
+
array = [240, 248, 255]
|
527
|
+
# ========================================================================= #
|
528
|
+
# === Testing the RGB-functionality of the Colours project next.
|
529
|
+
# ========================================================================= #
|
530
|
+
e 'Testing the RGB-functionality of the Colours project next.'
|
531
|
+
pp Colours.convert_this_html_colour_into_an_array_of_rgb_values
|
532
|
+
_ = 'royalblue'; e _+':'
|
533
|
+
pp Colours.convert_this_html_colour_into_an_array_of_rgb_values _
|
534
|
+
pp '[240, 248, 255] -> '+
|
535
|
+
Colours.convert_this_rgb_value_into_a_html_colour(array)
|
536
|
+
pp Colours.rgb_value_as_escape_code_string
|
537
|
+
pp Colours.colour_to_rgb_value('slateblue')
|
538
|
+
pp Colours.colour_to_rgb_value('crimson')
|
539
|
+
pp Colours.convert_this_rgb_value_to_that_hexadecimal_representation(array)
|
540
|
+
e
|
541
|
+
e Colours.rgb(122,56,141)+'Hello world!'
|
542
|
+
e Colours.colour_to_rgb_value('slateblue')
|
543
|
+
e Colours.rgb('slateblue')
|
544
|
+
e 'R;G;B value: '
|
545
|
+
pp Colours.colour_to_rgb_value('slateblue')
|
546
|
+
e
|
547
|
+
end
|