Module: Colours

Extended by:
AllColourMethods
Includes:
AllColourMethods, E
Defined in:
lib/colours/e/e.rb,
lib/colours/module.rb,
lib/colours/rgb/rgb.rb,
lib/colours/base/base.rb,
lib/colours/class/class.rb,
lib/colours/eparse/eparse.rb,
lib/colours/revert/revert.rb,
lib/colours/constants/misc.rb,
lib/colours/testing/testing.rb,
lib/colours/version/version.rb,
lib/colours/commandline/menu.rb,
lib/colours/constants/newline.rb,
lib/colours/html_colours/misc.rb,
lib/colours/toplevel_methods/e.rb,
lib/colours/colour_methods/sdir.rb,
lib/colours/colour_methods/sfile.rb,
lib/colours/colour_methods/swarn.rb,
lib/colours/toplevel_methods/cat.rb,
lib/colours/toplevel_methods/col.rb,
lib/colours/colour_methods/sfancy.rb,
lib/colours/toplevel_methods/bold.rb,
lib/colours/toplevel_methods/misc.rb,
lib/colours/colour_methods/snormal.rb,
lib/colours/colour_methods/ssymlink.rb,
lib/colours/commandline/commandline.rb,
lib/colours/rainbow_colours/rainbow.rb,
lib/colours/toplevel_methods/cliner.rb,
lib/colours/toplevel_methods/italic.rb,
lib/colours/colour_methods/sargument.rb,
lib/colours/colour_methods/scomments.rb,
lib/colours/constants/file_constants.rb,
lib/colours/rainbow_colours/set_mode.rb,
lib/colours/toplevel_methods/esystem.rb,
lib/colours/colour_methods/simportant.rb,
lib/colours/colour_table/colour_table.rb,
lib/colours/rainbow_colours/constants.rb,
lib/colours/constants/colour_constants.rb,
lib/colours/toplevel_methods/underline.rb,
lib/colours/basic_colours/basic_colours.rb,
lib/colours/html_colours/html_colourize.rb,
lib/colours/rainbow_colours/println_ani.rb,
lib/colours/toplevel_methods/fancy_parse.rb,
lib/colours/toplevel_methods/is_on_roebe.rb,
lib/colours/toplevel_methods/make_colour.rb,
lib/colours/toplevel_methods/use_colours.rb,
lib/colours/utility_scripts/autogenerate.rb,
lib/colours/colour_methods/default_colour.rb,
lib/colours/constants/hash_simple_colours.rb,
lib/colours/rainbow_colours/println_plain.rb,
lib/colours/rainbow_colours/report_errors.rb,
lib/colours/toplevel_methods/clear_screen.rb,
lib/colours/toplevel_methods/random_value.rb,
lib/colours/html_colours/hash_html_colours.rb,
lib/colours/html_colours/show_html_colours.rb,
lib/colours/project/project_base_directory.rb,
lib/colours/rainbow_colours/returnln_plain.rb,
lib/colours/toplevel_methods/html_colourize.rb,
lib/colours/toplevel_methods/open_this_file.rb,
lib/colours/toplevel_methods/bold_and_italic.rb,
lib/colours/rainbow_colours/print_rainbow_line.rb,
lib/colours/256_colours/support_for_256_colours.rb,
lib/colours/constants/registered_colour_methods.rb,
lib/colours/rainbow_colours/paint_detected_mode.rb,
lib/colours/requires/require_the_colour_methods.rb,
lib/colours/toplevel_methods/random_html_colour.rb,
lib/colours/requires/require_the_colours_project.rb,
lib/colours/autogenerated/support_for_256_colours.rb,
lib/colours/kde_colour_palette/kde_colour_palette.rb,
lib/colours/toplevel_methods/set_last_colour_used.rb,
lib/colours/autogenerated/support_for_html_colours.rb,
lib/colours/toplevel_methods/remove_escape_sequence.rb,
lib/colours/html_colours/is_this_html_colour_included.rb,
lib/colours/toplevel_methods/show_basic_colour_palette.rb,
lib/colours/autogenerated/toplevel_basic_colour_methods.rb,
lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb,
lib/colours/toplevel_methods/prefer_this_colour_schemata.rb,
lib/colours/toplevel_methods/methods_related_to_html_colours.rb,
lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb,
lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb,
lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb

Overview

#

require 'colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb'

#

Defined Under Namespace

Modules: AllColourMethods, BasicColours, E, HtmlColours, RainbowColours, SupportFor256Colours, SupportForHTMLColours Classes: Base, Colour, Colours, RGB

Constant Summary collapse

ESC =
#

Colours::ESC

Escape sequences start with the character ESC (ASCII decimal 27/hex 0x1B/octal 033).

The characters ESC and [ (left bracket) are called CSI, for “Control Sequence Initiator”.

Keep in mind that “e” can be represented via “u001b” in Ruby, too.

#
"\e["
COLOUR_NC =
#

Colours::COLOUR_NC

Note that this will actually reset all attributes.

The “e[0m” sequence removes all attributes, including formatting and colours. It may be useful to add it to the end of each colour text - and this is what the Colours project is essentially doing.

An alternative may be to assign REVERT to WHITE, but this seems to be incorrect according to the specification.

#
"#{ESC}0m"
REVERT =

REVERT

COLOUR_NC
REV =

REV

COLOUR_NC
CLOSING_TAG =

CLOSING_TAG (also represented as “#ESC0m”)

COLOUR_NC
RESET =

RESET

COLOUR_NC
RESET_TERMINAL =

RESET_TERMINAL

COLOUR_NC
CLEAR =

CLEAR

COLOUR_NC
COLOUR_RESET =

COLOUR_RESET

COLOUR_NC
DEFAULT_COLOUR =

DEFAULT_COLOUR

COLOUR_RESET
RESET_ALL_ATTRIBUTES =
#

RESET_ALL_ATTRIBUTES

This is essentially the same as COLOUR_NC / RESET.

#
"\x1b[0m"
HOME_DIRECTORY_OF_USER_X =
#

HOME_DIRECTORY_OF_USER_X

#
'/home/x/'
DEFAULT_TEXT =
#

Colours::DEFAULT_TEXT

#
'Hello World!'
IS_A_TEST =
#

Colours::IS_A_TEST

#
' This is just a simple colour test.'
TEST_FILE =
#

Colours::TEST_FILE

#
"#{HOME_DIRECTORY_OF_USER_X}DATA/PROGRAMMING_LANGUAGES/RUBY/src/colours/test/testing_konsole_submodule.rb"
LEFT =
#

LEFT

Leading on the left side, for RGB value setting. This is the beginning of a special instruction. Note that “e[38” should be equal to “x1b”, but IRB reports that this is not the case so.

Examples on the www show usage such as this:

printf "\x1b[${bg};2;${red};${green};${blue}m\n"
printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
#
"\e[38;2;".dup
VERSION =
#

VERSION

#
'0.6.12'
LAST_UPDATE =
#

LAST_UPDATE

#
'15.09.2022'
URL_TO_THE_DOCUMENTATION =
#

URL_TO_THE_DOCUMENTATION

#
"https://www.rubydoc.info/gems/#{self.to_s.downcase}/#{VERSION}"
N =
#

N

#
"\n"
ITALIC_CODE =
#

ITALIC_CODE

If you wish to test italic output quickly on the terminal, then you can use something like this:

echo -e "\e[3mone two three\e[23m"
#
'3'
FILE_HTML_COLOURS =
#

Colours::FILE_HTML_COLOURS

#
"#{PROJECT_BASE_DIRECTORY}yaml/html_colours.yml"
FILE_KDE_COLOUR_PALETTE =
#

Colours::FILE_KDE_COLOUR_PALETTE

#
"#{PROJECT_BASE_DIRECTORY}yaml/kde_colour_palette.yml"
FILE_256_COLOURS =
#

Colours::FILE_256_COLOURS

#
"#{PROJECT_BASE_DIRECTORY}yaml/256_colours.yml"
FILE_BASIC_COLOURS =
#

Colours::FILE_BASIC_COLOURS

#
"#{PROJECT_BASE_DIRECTORY}yaml/basic_colours.yml"
FILE_USE_THESE_VALUES_FOR_THE_COLOUR_METHODS =
#

Colours::FILE_USE_THESE_VALUES_FOR_THE_COLOUR_METHODS

#
"#{PROJECT_BASE_DIRECTORY}yaml/use_these_values_for_the_colour_methods.yml"
FILE_PREFER_THIS_COLOUR_SCHEMATA =
#

Colours::FILE_PREFER_THIS_COLOUR_SCHEMATA

#
"#{PROJECT_BASE_DIRECTORY}yaml/prefer_this_colour_schemata.yml"
HASH_NEW_COLOURS =
#

HASH_NEW_COLOURS

This is the new hash, which we can transition-into when necessary.

It is only rarely used these days, though (as of the year 2018).

If you want to use these colours, you can use this simpler API:

Colourss.set_method_to_colour_table :new_colours
#
{
  default_colour: :green,        
  sargument:      :bold_brown,    # === sarg()
  scomments:      :bold_blue,     # === scomments()
  sdir:           :bold_green,    # === sdir()
  sfancy:         :bold_yellow,   # === sfancy()
  sfile:          :brown,         # === sfile()
  simportant:     :pink,          # === simportant()
  ssymlink:       :teal,          # === ssymlink()
  swarn:          :bold_red,      # === swarn
  snormal:        :light_grey     # === snormal()
}
REDRAW_THE_PROMPT =
#

REDRAW_THE_PROMPT

The following constant is necessary in order for the background colour to apply to the whole line and in order for the foreground colour to apply to the cursor.

#
"\e[K"
BLACK_ON_WHITE_BACKGROUND =
#

Colours::BLACK_ON_WHITE_BACKGROUND

Usage example:

puts Colours::BLACK_ON_WHITE_BACKGROUND+'Hello world!'+Colours::RESET
#
"#{ESC}0;30;47m"
BLACK_ON_WHITE_BG =

BLACK_ON_WHITE_BG

BLACK_ON_WHITE_BACKGROUND
COLOUR_YELLOW =
#

COLOUR_YELLOW

#
"#{ESC}0;33m"
BROWN =

BROWN

COLOUR_YELLOW
YEL =

YEL

COLOUR_YELLOW
YELLOW =

YELLOW

COLOUR_YELLOW
BOLD_BROWN =

BOLD_BROWN

COLOUR_YELLOW
COLOUR_LIGHT_MAGENTA =
#

COLOUR_LIGHT_MAGENTA

This is not the “normal” magenta, but the light variant; also called light purple.

#
"#{ESC}1;35m"
LIGHT_PURPLE =

LIGHT_PURPLE

COLOUR_LIGHT_MAGENTA
COLOUR_LIGHT_PURPLE =

COLOUR_LIGHT_PURPLE

COLOUR_LIGHT_MAGENTA
PINK =

PINK

COLOUR_LIGHT_MAGENTA
COLOUR_PINK =

COLOUR_PINK

COLOUR_LIGHT_MAGENTA
BRIGHT_PINK =

BRIGHT_PINK

COLOUR_LIGHT_MAGENTA
BRIGHT_MAGENTA =

BRIGHT_MAGENTA

COLOUR_LIGHT_MAGENTA
COLOUR_LIGHT_RED =
#

COLOUR_LIGHT_RED

#
"#{ESC}1;31m"
LIGHT_RED =

LIGHT_RED

COLOUR_LIGHT_RED
BOLD_RED =

BOLD_RED

COLOUR_LIGHT_RED
COLOUR_BOLD_RED =

COLOUR_BOLD_RED

COLOUR_LIGHT_RED
BRIGHT_RED =

BRIGHT_RED

COLOUR_LIGHT_RED
BOLDRED =

BOLDRED

COLOUR_LIGHT_RED
REDB =

REDB

COLOUR_LIGHT_RED
BRED =

BRED

COLOUR_LIGHT_RED
COLOUR_RED =
#

COLOUR_RED (red tag)

#
"#{ESC}0;31m"
RED =

RED

COLOUR_RED
CRED =

CRED

COLOUR_RED
COLOUR_GREEN =
#

COLOUR_GREEN

#
"#{ESC}0;32m"
GREEN =

GREEN

COLOUR_GREEN
CGREEN =

CGREEN

COLOUR_GREEN
DARKGREEN =

DARKGREEN

COLOUR_GREEN
COLOUR_BLUE =
#

COLOUR_BLUE

#
"#{ESC}0;34m"
BLUE =

BLUE

COLOUR_BLUE
COLOUR_LIGHT_GREEN =
#

COLOUR_LIGHT_GREEN

#
"#{ESC}1;32m"
BOLD_GREEN =

BOLD_GREEN

COLOUR_LIGHT_GREEN
COLOUR_BOLD_GREEN =

COLOUR_BOLD_GREEN

COLOUR_LIGHT_GREEN
BRIGHT_GREEN =

BRIGHT_GREEN

COLOUR_LIGHT_GREEN
LIGHTGREEN =

LIGHTGREEN

COLOUR_LIGHT_GREEN
BGREEN =

BGREEN

COLOUR_LIGHT_GREEN
COLOUR_MAGENTA =
#

COLOUR_MAGENTA

#
"#{ESC}0;35m"
PURPLE =

PURPLE

COLOUR_MAGENTA
COLOUR_PURPLE =

COLOUR_PURPLE

COLOUR_MAGENTA
MAGENTA =

MAGENTA

COLOUR_MAGENTA
COLOUR_LIGHT_BLUE =
#

COLOUR_LIGHT_BLUE

#
"#{ESC}1;34m"
BOLD_BLUE =

BOLD_BLUE

COLOUR_LIGHT_BLUE
COLOUR_BOLD_BLUE =

COLOUR_BOLD_BLUE

COLOUR_LIGHT_BLUE
BRIGHT_BLUE =

BRIGHT_BLUE

COLOUR_LIGHT_BLUE
LIGHT_BLUE =

LIGHT_BLUE

COLOUR_LIGHT_BLUE
LIGHTBLUE =

LIGHTBLUE

COLOUR_LIGHT_BLUE
BBLUE =

BBLUE

COLOUR_LIGHT_BLUE
BOLDBLUE =

BOLDBLUE

COLOUR_LIGHT_BLUE
COLOUR_BROWN =
#

COLOUR_BROWN

#
"#{ESC}1;33m"
BOLD_YELLOW =

BOLD_YELLOW

COLOUR_BROWN
GOLD =

GOLD

COLOUR_BROWN
BRIGHT_BROWN =

BRIGHT_BROWN

COLOUR_BROWN
BRIGHT_YELLOW =

BRIGHT_YELLOW

COLOUR_BROWN
BOLDYELLOW =

BOLDYELLOW

COLOUR_BROWN
BYEL =

BYEL

COLOUR_BROWN
BYELLOW =

BYELLOW

COLOUR_BROWN
COLOUR_BOLD_YELLOW =

COLOUR_BOLD_YELLOW

COLOUR_BROWN
COLOUR_LIGHT_CYAN =
#

COLOUR_LIGHT_CYAN

#
"#{ESC}1;36m"
BOLD_CYAN =

BOLD_CYAN

COLOUR_LIGHT_CYAN
COLOUR_BOLD_TEAL =

COLOUR_BOLD_TEAL

COLOUR_LIGHT_CYAN
BRIGHT_CYAN =

BRIGHT_CYAN

COLOUR_LIGHT_CYAN
BRIGHT_TEAL =

BRIGHT_TEAL

COLOUR_LIGHT_CYAN
CYANB =

CYANB

COLOUR_LIGHT_CYAN
BOLD_TEAL =

BOLD_TEAL

COLOUR_LIGHT_CYAN
COLOUR_CYAN =
#

COLOUR_CYAN

This is also called TEAL, sort of.

#
"#{ESC}0;36m"
TEAL =

TEAL

COLOUR_CYAN
CYAN =

CYAN

COLOUR_CYAN
COLOUR_TEAL =

COLOUR_TEAL

COLOUR_CYAN
COLOUR_BLACK =
#

COLOUR_BLACK

#
"#{ESC}0;30m"
COLOUR_GRAY =

COLOUR_GRAY

COLOUR_BLACK
BLACK =

BLACK

COLOUR_BLACK
REGEX_REMOVE_ANSI_ESCAPE_CHARACTERS =
#

REGEX_REMOVE_ANSI_ESCAPE_CHARACTERS

This regex can be used to get rid of (some) AnsiEscape characters.

#
/\033\[.*?m/
REMOVE_ANSI_ESCAPE_CHARACTERS =

REMOVE_ANSI_ESCAPE_CHARACTERS

REGEX_REMOVE_ANSI_ESCAPE_CHARACTERS
COLOUR_LIGHT_GRAY =
#

COLOUR_LIGHT_GRAY

#
"#{ESC}0;37m"
WHITE =

WHITE

COLOUR_LIGHT_GRAY
COLOUR_LIGHT_GREY =

COLOUR_LIGHT_GREY

COLOUR_LIGHT_GRAY
COLOUR_WHITE =
#

COLOUR_WHITE

#
"#{ESC}1;37m"
BOLD_WHITE =

BOLD_WHITE

COLOUR_WHITE
BRIGHT_WHITE =

BRIGHT_WHITE

COLOUR_WHITE
BWHITE =

BWHITE

COLOUR_WHITE
COLOUR_BOLD_WHITE =

COLOUR_BOLD_WHITE

COLOUR_WHITE
COLOUR_DARK_GRAY =
#

COLOUR_DARK_GRAY

This is also called “black bold”.

#
"#{ESC}1;30m"
GREY =

GREY

COLOUR_DARK_GRAY
GRAY =

GRAY

COLOUR_DARK_GRAY
CGREY =

CGREY

COLOUR_DARK_GRAY
BRIGHT_BLACK =

BRIGHT_BLACK

COLOUR_DARK_GRAY
BOLD_BLACK =

BOLD_BLACK

COLOUR_DARK_GRAY
ARRAY_REGISTERED_ANSI_COLOURS =
#

ARRAY_REGISTERED_ANSI_COLOURS

#
[

  COLOUR_BLACK,
  COLOUR_RED,
  COLOUR_GREEN,
  COLOUR_YELLOW,
  COLOUR_BLUE,
  COLOUR_MAGENTA,
  COLOUR_TEAL,
  COLOUR_LIGHT_GREY,

  COLOUR_BOLD_RED,
  COLOUR_BOLD_GREEN,
  COLOUR_BOLD_YELLOW,
  COLOUR_BOLD_BLUE,
  COLOUR_PINK,
  COLOUR_BOLD_TEAL,
  COLOUR_BOLD_WHITE,

  COLOUR_RESET

]
UNDERLINE_CODE =
#

UNDERLINE_CODE

To quickly test the underline-functionality, you can try:

echo -e "\e[4mone two three\e[23m"
#
'4'
GENERIC_RUBY_HEADER =
#

GENERIC_RUBY_HEADER

#
"#!/usr/bin/ruby -w
# Encoding: UTF-8
# frozen_string_literal: true
# =========================================================================== #"
HASH_SIMPLE_COLOURS =
#

Colours::HASH_SIMPLE_COLOURS

This hash will only store one name for the corresponding colour code.

#
{
  black:         '0;30',
  red:           '0;31',
  green:         '0;32',
  yellow:        '0;33',
  blue:          '0;34',
  magenta:       '0;35',
  cyan:          '0;36',
  light_gray:    '0;37',
  # ======================================================================= #
  # Next, the secondary-colours:
  # ======================================================================= #
  dark_gray:     '1;30',
  light_red:     '1;31',
  light_green:   '1;32',
  brown:         '1;33',
  light_blue:    '1;34',
  light_magenta: '1;35',
  light_cyan:    '1;36',
  white:         '1;37'
}
MAIN_COLOURS =
#

Colours::MAIN_COLOURS

The main colours come next.

Eight main colours are currently defined, according to:

http://en.wikipedia.org/wiki/ANSI_escape_code#Colors

The range is:

Intensity:     0    1    2      3     4      5      6    7
Normal:     Black  Red Green Yellow  Blue  Magenta Cyan White

Yellow, in my opinion, looks more like brown.

#
%i(
  black red green yellow blue magenta teal white
)
SECONDARY_COLOURS =
#

Colours::SECONDARY_COLOURS

The secondary Colours.

Colours which are not part of the MAIN_COLOURS Array.

The secondary colours are:

Bright Black
Bright Red
Bright Green
Bright Yellow
Bright Blue
Bright Magenta
Bright Cyan
Bright White
#
[
  :bright_black,
  :bright_red,
  :bright_green,
  :bright_yellow,
  :bright_blue,
  :bright_magenta,
  :bright_cyan,
  :bright_white
]
ALL_COLOURS =
#

ALL_COLOURS

Simply combine the two Arrays, MAIN_COLOURS and SECONDARY_COLOURS, into one aggregate Array.

#
MAIN_COLOURS +
SECONDARY_COLOURS
PROJECT_BASE_DIRECTORY =
#

Colours::PROJECT_BASE_DIRECTORY

#
File.absolute_path("#{__dir__}/..")+'/'
REGISTERED_COLOUR_METHODS =
#

Colours::REGISTERED_COLOUR_METHODS

These methods constitute the registered colour methods.

These have a corresponding method, such as snormal() or sdir() or sfile().

snormal() stands for the “normal” colour, aka the “default colour”.

#
%i(
  snormal
  sargument
  scomments
  ssymlink
  sdir
  sfile
  sfancy
  simportant
  swarn
)
REGISTERED_COLOUR_METHODS_ALIASES =
#

REGISTERED_COLOUR_METHODS_ALIASES

This Array should hold all aliases to the main colour-methods, such as simportant() or sargument().

#
%i(
  argument
  ssym
  simp
  sarg
  normal
  comments
  symlink
  dir
  file
  fancy
  important
  warn
)
KDE_COLOUR_PALETTE =
{}
USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR =
#

USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR

Here we specify the default colour to be used, in order to revert to the prior colour in use. This can be modified by the user, in order to conform to other colours if said user wishes to do so.

#
:grey
REGEX_FOR_HTML_COLOURS =
#

REGEX_FOR_HTML_COLOURS

This regex supports the use case where we can match against HTML colours. (The name is a bit of a misnomer, though.)

For the following regex, see this entry at rubular:

https://rubular.com/r/o5r4DneMTGOsbX
#
/<([()a-zA-Z0-9²→\n]+?)>/

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AllColourMethods

aliceblue, aliceblue, antiquewhite, antiquewhite, aqua, aqua, aquamarine, aquamarine, aquamarine1, aquamarine1, aquamarine3, aquamarine3, azure, azure, beige, beige, bisque, bisque, black, black, blanchedalmond, blanchedalmond, blue, blue, blue1, blue1, blue3, blue3, blueviolet, blueviolet, brown, brown, burlywood, burlywood, cadetblue, cadetblue, chartreuse, chartreuse, chartreuse1, chartreuse1, chartreuse2, chartreuse2, chartreuse3, chartreuse3, chartreuse4, chartreuse4, chocolate, chocolate, coral, coral, cornflowerblue, cornflowerblue, cornsilk, cornsilk, cornsilk1, cornsilk1, crimson, crimson, cyan, cyan, cyan1, cyan1, cyan2, cyan2, cyan3, cyan3, dark_gray, darkblue, darkblue, darkcyan, darkcyan, darkgoldenrod, darkgoldenrod, darkgray, darkgray, darkgreen, darkgreen, darkgrey, darkgrey, darkkhaki, darkkhaki, darkmagenta, darkmagenta, darkolivegreen, darkolivegreen, darkolivegreen1, darkolivegreen1, darkolivegreen2, darkolivegreen2, darkolivegreen3, darkolivegreen3, darkorange, darkorange, darkorange3, darkorange3, darkorchid, darkorchid, darkred, darkred, darksalmon, darksalmon, darkseagreen, darkseagreen, darkseagreen1, darkseagreen1, darkseagreen2, darkseagreen2, darkseagreen3, darkseagreen3, darkseagreen4, darkseagreen4, darkslateblue, darkslateblue, darkslategray, darkslategray, darkslategray1, darkslategray1, darkslategray2, darkslategray2, darkslategray3, darkslategray3, darkslategrey, darkslategrey, darkturquoise, darkturquoise, darkviolet, darkviolet, deeppink, deeppink, deeppink1, deeppink1, deeppink2, deeppink2, deeppink3, deeppink3, deeppink4, deeppink4, deepskyblue, deepskyblue, deepskyblue1, deepskyblue1, deepskyblue2, deepskyblue2, deepskyblue3, deepskyblue3, deepskyblue4, deepskyblue4, dimgray, dimgray, dimgrey, dimgrey, dodgerblue, dodgerblue, dodgerblue1, dodgerblue1, dodgerblue2, dodgerblue2, dodgerblue3, dodgerblue3, ealiceblue, eantiquewhite, eaqua, eaquamarine, eaquamarine1, eaquamarine3, eazure, ebeige, ebisque, eblack, eblanchedalmond, eblue, eblue1, eblue3, eblueviolet, ebrown, eburlywood, ecadetblue, echartreuse, echartreuse1, echartreuse2, echartreuse3, echartreuse4, echocolate, ecoral, ecornflowerblue, ecornsilk, ecornsilk1, ecrimson, ecyan, ecyan1, ecyan2, ecyan3, edarkblue, edarkcyan, edarkgoldenrod, edarkgray, edarkgreen, edarkgrey, edarkkhaki, edarkmagenta, edarkolivegreen, edarkolivegreen1, edarkolivegreen2, edarkolivegreen3, edarkorange, edarkorange3, edarkorchid, edarkred, edarksalmon, edarkseagreen, edarkseagreen1, edarkseagreen2, edarkseagreen3, edarkseagreen4, edarkslateblue, edarkslategray, edarkslategray1, edarkslategray2, edarkslategray3, edarkslategrey, edarkturquoise, edarkviolet, edeeppink, edeeppink1, edeeppink2, edeeppink3, edeeppink4, edeepskyblue, edeepskyblue1, edeepskyblue2, edeepskyblue3, edeepskyblue4, edimgray, edimgrey, edodgerblue, edodgerblue1, edodgerblue2, edodgerblue3, efirebrick, efloralwhite, eforestgreen, efuchsia, egainsboro, eghostwhite, egold, egold1, egold3, egoldenrod, egray, egreen, egreen1, egreen3, egreen4, egreenyellow, egrey, egrey0, egrey100, egrey11, egrey15, egrey19, egrey23, egrey27, egrey3, egrey30, egrey35, egrey37, egrey39, egrey42, egrey46, egrey50, egrey53, egrey54, egrey58, egrey62, egrey63, egrey66, egrey69, egrey7, egrey70, egrey74, egrey78, egrey82, egrey84, egrey85, egrey89, egrey93, ehoneydew, ehoneydew2, ehotpink, ehotpink2, ehotpink3, eindianred, eindianred1, eindigo, eivory, ekhaki, ekhaki1, ekhaki3, elavender, elavenderblush, elawngreen, elemonchiffon, elightblue, elightcoral, elightcyan, elightcyan1, elightcyan3, elightgoldenrod1, elightgoldenrod2, elightgoldenrod3, elightgoldenrodyellow, elightgray, elightgreen, elightgrey, elightmagenta, elightpink, elightpink1, elightpink3, elightpink4, elightred, elightsalmon, elightsalmon1, elightsalmon3, elightseagreen, elightskyblue, elightskyblue1, elightskyblue3, elightslateblue, elightslategray, elightslategrey, elightsteelblue, elightsteelblue1, elightsteelblue3, elightyellow, elightyellow3, elime, elimegreen, elinen, emagenta, emagenta1, emagenta2, emagenta3, emaroon, emediumaquamarine, emediumblue, emediumorchid, emediumorchid1, emediumorchid3, emediumpurple, emediumpurple1, emediumpurple2, emediumpurple3, emediumpurple4, emediumseagreen, emediumslateblue, emediumspringgreen, emediumturquoise, emediumvioletred, emidnightblue, emintcream, emistyrose, emistyrose1, emistyrose3, emoccasin, enavajowhite, enavajowhite1, enavajowhite3, enavy, enavyblue, eoldlace, eolive, eolivedrab, eorange, eorange1, eorange3, eorange4, eorangered, eorangered1, eorchid, eorchid1, eorchid2, epalegoldenrod, epalegreen, epalegreen1, epalegreen3, epaleturquoise, epaleturquoise1, epaleturquoise4, epalevioletred, epalevioletred1, epapayawhip, epeachpuff, eperu, epink, epink1, epink3, eplum, eplum1, eplum2, eplum3, eplum4, epowderblue, epurple, epurple3, epurple4, ered, ered1, ered3, erosybrown, eroyalblue, eroyalblue1, esaddlebrown, esalmon, esalmon1, esandybrown, eseagreen, eseagreen1, eseagreen2, eseagreen3, eseashell, esienna, esilver, eskyblue, eskyblue1, eskyblue2, eskyblue3, eslateblue, eslateblue1, eslateblue3, eslategray, eslategrey, esnow, espringgreen, espringgreen1, espringgreen2, espringgreen3, espringgreen4, esteelblue, esteelblue1, esteelblue3, etan, eteal, ethistle, ethistle1, ethistle3, etomato, eturquoise, eturquoise2, eturquoise4, eviolet, ewheat, ewheat1, ewheat4, ewhite, ewhitesmoke, eyellow, eyellow1, eyellow2, eyellow3, eyellow4, eyellowgreen, firebrick, firebrick, floralwhite, floralwhite, forestgreen, forestgreen, fuchsia, fuchsia, gainsboro, gainsboro, ghostwhite, ghostwhite, gold, gold, gold1, gold1, gold3, gold3, goldenrod, goldenrod, gray, gray, green, green, green1, green1, green3, green3, green4, green4, greenyellow, greenyellow, grey, grey, grey0, grey0, grey100, grey100, grey11, grey11, grey15, grey15, grey19, grey19, grey23, grey23, grey27, grey27, grey3, grey3, grey30, grey30, grey35, grey35, grey37, grey37, grey39, grey39, grey42, grey42, grey46, grey46, grey50, grey50, grey53, grey53, grey54, grey54, grey58, grey58, grey62, grey62, grey63, grey63, grey66, grey66, grey69, grey69, grey7, grey7, grey70, grey70, grey74, grey74, grey78, grey78, grey82, grey82, grey84, grey84, grey85, grey85, grey89, grey89, grey93, grey93, honeydew, honeydew, honeydew2, honeydew2, hotpink, hotpink, hotpink2, hotpink2, hotpink3, hotpink3, indianred, indianred, indianred1, indianred1, indigo, indigo, ivory, ivory, khaki, khaki, khaki1, khaki1, khaki3, khaki3, konsole_colour_aliceblue, konsole_colour_antiquewhite, konsole_colour_aqua, konsole_colour_aquamarine, konsole_colour_aquamarine1, konsole_colour_aquamarine3, konsole_colour_azure, konsole_colour_beige, konsole_colour_bisque, konsole_colour_black, konsole_colour_blanchedalmond, konsole_colour_blue, konsole_colour_blue1, konsole_colour_blue3, konsole_colour_blueviolet, konsole_colour_brown, konsole_colour_burlywood, konsole_colour_cadetblue, konsole_colour_chartreuse, konsole_colour_chartreuse1, konsole_colour_chartreuse2, konsole_colour_chartreuse3, konsole_colour_chartreuse4, konsole_colour_chocolate, konsole_colour_coral, konsole_colour_cornflowerblue, konsole_colour_cornsilk, konsole_colour_cornsilk1, konsole_colour_crimson, konsole_colour_cyan, konsole_colour_cyan1, konsole_colour_cyan2, konsole_colour_cyan3, konsole_colour_darkblue, konsole_colour_darkcyan, konsole_colour_darkgoldenrod, konsole_colour_darkgray, konsole_colour_darkgreen, konsole_colour_darkgrey, konsole_colour_darkkhaki, konsole_colour_darkmagenta, konsole_colour_darkolivegreen, konsole_colour_darkolivegreen1, konsole_colour_darkolivegreen2, konsole_colour_darkolivegreen3, konsole_colour_darkorange, konsole_colour_darkorange3, konsole_colour_darkorchid, konsole_colour_darkred, konsole_colour_darksalmon, konsole_colour_darkseagreen, konsole_colour_darkseagreen1, konsole_colour_darkseagreen2, konsole_colour_darkseagreen3, konsole_colour_darkseagreen4, konsole_colour_darkslateblue, konsole_colour_darkslategray, konsole_colour_darkslategray1, konsole_colour_darkslategray2, konsole_colour_darkslategray3, konsole_colour_darkslategrey, konsole_colour_darkturquoise, konsole_colour_darkviolet, konsole_colour_deeppink, konsole_colour_deeppink1, konsole_colour_deeppink2, konsole_colour_deeppink3, konsole_colour_deeppink4, konsole_colour_deepskyblue, konsole_colour_deepskyblue1, konsole_colour_deepskyblue2, konsole_colour_deepskyblue3, konsole_colour_deepskyblue4, konsole_colour_dimgray, konsole_colour_dimgrey, konsole_colour_dodgerblue, konsole_colour_dodgerblue1, konsole_colour_dodgerblue2, konsole_colour_dodgerblue3, konsole_colour_firebrick, konsole_colour_floralwhite, konsole_colour_forestgreen, konsole_colour_fuchsia, konsole_colour_gainsboro, konsole_colour_ghostwhite, konsole_colour_gold, konsole_colour_gold1, konsole_colour_gold3, konsole_colour_goldenrod, konsole_colour_gray, konsole_colour_green, konsole_colour_green1, konsole_colour_green3, konsole_colour_green4, konsole_colour_greenyellow, konsole_colour_grey, konsole_colour_grey0, konsole_colour_grey100, konsole_colour_grey11, konsole_colour_grey15, konsole_colour_grey19, konsole_colour_grey23, konsole_colour_grey27, konsole_colour_grey3, konsole_colour_grey30, konsole_colour_grey35, konsole_colour_grey37, konsole_colour_grey39, konsole_colour_grey42, konsole_colour_grey46, konsole_colour_grey50, konsole_colour_grey53, konsole_colour_grey54, konsole_colour_grey58, konsole_colour_grey62, konsole_colour_grey63, konsole_colour_grey66, konsole_colour_grey69, konsole_colour_grey7, konsole_colour_grey70, konsole_colour_grey74, konsole_colour_grey78, konsole_colour_grey82, konsole_colour_grey84, konsole_colour_grey85, konsole_colour_grey89, konsole_colour_grey93, konsole_colour_honeydew, konsole_colour_honeydew2, konsole_colour_hotpink, konsole_colour_hotpink2, konsole_colour_hotpink3, konsole_colour_indianred, konsole_colour_indianred1, konsole_colour_indigo, konsole_colour_ivory, konsole_colour_khaki, konsole_colour_khaki1, konsole_colour_khaki3, konsole_colour_lavender, konsole_colour_lavenderblush, konsole_colour_lawngreen, konsole_colour_lemonchiffon, konsole_colour_lightblue, konsole_colour_lightcoral, konsole_colour_lightcyan, konsole_colour_lightcyan1, konsole_colour_lightcyan3, konsole_colour_lightgoldenrod1, konsole_colour_lightgoldenrod2, konsole_colour_lightgoldenrod3, konsole_colour_lightgoldenrodyellow, konsole_colour_lightgray, konsole_colour_lightgreen, konsole_colour_lightgrey, konsole_colour_lightmagenta, konsole_colour_lightpink, konsole_colour_lightpink1, konsole_colour_lightpink3, konsole_colour_lightpink4, konsole_colour_lightred, konsole_colour_lightsalmon, konsole_colour_lightsalmon1, konsole_colour_lightsalmon3, konsole_colour_lightseagreen, konsole_colour_lightskyblue, konsole_colour_lightskyblue1, konsole_colour_lightskyblue3, konsole_colour_lightslateblue, konsole_colour_lightslategray, konsole_colour_lightslategrey, konsole_colour_lightsteelblue, konsole_colour_lightsteelblue1, konsole_colour_lightsteelblue3, konsole_colour_lightyellow, konsole_colour_lightyellow3, konsole_colour_lime, konsole_colour_limegreen, konsole_colour_linen, konsole_colour_magenta, konsole_colour_magenta1, konsole_colour_magenta2, konsole_colour_magenta3, konsole_colour_maroon, konsole_colour_mediumaquamarine, konsole_colour_mediumblue, konsole_colour_mediumorchid, konsole_colour_mediumorchid1, konsole_colour_mediumorchid3, konsole_colour_mediumpurple, konsole_colour_mediumpurple1, konsole_colour_mediumpurple2, konsole_colour_mediumpurple3, konsole_colour_mediumpurple4, konsole_colour_mediumseagreen, konsole_colour_mediumslateblue, konsole_colour_mediumspringgreen, konsole_colour_mediumturquoise, konsole_colour_mediumvioletred, konsole_colour_midnightblue, konsole_colour_mintcream, konsole_colour_mistyrose, konsole_colour_mistyrose1, konsole_colour_mistyrose3, konsole_colour_moccasin, konsole_colour_navajowhite, konsole_colour_navajowhite1, konsole_colour_navajowhite3, konsole_colour_navy, konsole_colour_navyblue, konsole_colour_oldlace, konsole_colour_olive, konsole_colour_olivedrab, konsole_colour_orange, konsole_colour_orange1, konsole_colour_orange3, konsole_colour_orange4, konsole_colour_orangered, konsole_colour_orangered1, konsole_colour_orchid, konsole_colour_orchid1, konsole_colour_orchid2, konsole_colour_palegoldenrod, konsole_colour_palegreen, konsole_colour_palegreen1, konsole_colour_palegreen3, konsole_colour_paleturquoise, konsole_colour_paleturquoise1, konsole_colour_paleturquoise4, konsole_colour_palevioletred, konsole_colour_palevioletred1, konsole_colour_papayawhip, konsole_colour_peachpuff, konsole_colour_peru, konsole_colour_pink, konsole_colour_pink1, konsole_colour_pink3, konsole_colour_plum, konsole_colour_plum1, konsole_colour_plum2, konsole_colour_plum3, konsole_colour_plum4, konsole_colour_powderblue, konsole_colour_purple, konsole_colour_purple3, konsole_colour_purple4, konsole_colour_red, konsole_colour_red1, konsole_colour_red3, konsole_colour_rosybrown, konsole_colour_royalblue, konsole_colour_royalblue1, konsole_colour_saddlebrown, konsole_colour_salmon, konsole_colour_salmon1, konsole_colour_sandybrown, konsole_colour_seagreen, konsole_colour_seagreen1, konsole_colour_seagreen2, konsole_colour_seagreen3, konsole_colour_seashell, konsole_colour_sienna, konsole_colour_silver, konsole_colour_skyblue, konsole_colour_skyblue1, konsole_colour_skyblue2, konsole_colour_skyblue3, konsole_colour_slateblue, konsole_colour_slateblue1, konsole_colour_slateblue3, konsole_colour_slategray, konsole_colour_slategrey, konsole_colour_snow, konsole_colour_springgreen, konsole_colour_springgreen1, konsole_colour_springgreen2, konsole_colour_springgreen3, konsole_colour_springgreen4, konsole_colour_steelblue, konsole_colour_steelblue1, konsole_colour_steelblue3, konsole_colour_tan, konsole_colour_teal, konsole_colour_thistle, konsole_colour_thistle1, konsole_colour_thistle3, konsole_colour_tomato, konsole_colour_turquoise, konsole_colour_turquoise2, konsole_colour_turquoise4, konsole_colour_violet, konsole_colour_wheat, konsole_colour_wheat1, konsole_colour_wheat4, konsole_colour_white, konsole_colour_whitesmoke, konsole_colour_yellow, konsole_colour_yellow1, konsole_colour_yellow2, konsole_colour_yellow3, konsole_colour_yellow4, konsole_colour_yellowgreen, lavender, lavender, lavenderblush, lavenderblush, lawngreen, lawngreen, lemonchiffon, lemonchiffon, light_blue, light_cyan, light_gray, light_green, lightblue, lightblue, lightcoral, lightcoral, lightcyan, lightcyan, lightcyan1, lightcyan1, lightcyan3, lightcyan3, lightgoldenrod1, lightgoldenrod1, lightgoldenrod2, lightgoldenrod2, lightgoldenrod3, lightgoldenrod3, lightgoldenrodyellow, lightgoldenrodyellow, lightgray, lightgray, lightgreen, lightgreen, lightgrey, lightgrey, lightmagenta, lightmagenta, lightpink, lightpink, lightpink1, lightpink1, lightpink3, lightpink3, lightpink4, lightpink4, lightred, lightred, lightsalmon, lightsalmon, lightsalmon1, lightsalmon1, lightsalmon3, lightsalmon3, lightseagreen, lightseagreen, lightskyblue, lightskyblue, lightskyblue1, lightskyblue1, lightskyblue3, lightskyblue3, lightslateblue, lightslateblue, lightslategray, lightslategray, lightslategrey, lightslategrey, lightsteelblue, lightsteelblue, lightsteelblue1, lightsteelblue1, lightsteelblue3, lightsteelblue3, lightyellow, lightyellow, lightyellow3, lightyellow3, lime, lime, limegreen, limegreen, linen, linen, magenta, magenta, magenta1, magenta1, magenta2, magenta2, magenta3, magenta3, maroon, maroon, mediumaquamarine, mediumaquamarine, mediumblue, mediumblue, mediumorchid, mediumorchid, mediumorchid1, mediumorchid1, mediumorchid3, mediumorchid3, mediumpurple, mediumpurple, mediumpurple1, mediumpurple1, mediumpurple2, mediumpurple2, mediumpurple3, mediumpurple3, mediumpurple4, mediumpurple4, mediumseagreen, mediumseagreen, mediumslateblue, mediumslateblue, mediumspringgreen, mediumspringgreen, mediumturquoise, mediumturquoise, mediumvioletred, mediumvioletred, midnightblue, midnightblue, mintcream, mintcream, mistyrose, mistyrose, mistyrose1, mistyrose1, mistyrose3, mistyrose3, moccasin, moccasin, navajowhite, navajowhite, navajowhite1, navajowhite1, navajowhite3, navajowhite3, navy, navy, navyblue, navyblue, oldlace, oldlace, olive, olive, olivedrab, olivedrab, orange, orange, orange1, orange1, orange3, orange3, orange4, orange4, orangered, orangered, orangered1, orangered1, orchid, orchid, orchid1, orchid1, orchid2, orchid2, palegoldenrod, palegoldenrod, palegreen, palegreen, palegreen1, palegreen1, palegreen3, palegreen3, paleturquoise, paleturquoise, paleturquoise1, paleturquoise1, paleturquoise4, paleturquoise4, palevioletred, palevioletred, palevioletred1, palevioletred1, papayawhip, papayawhip, peachpuff, peachpuff, peru, peru, pink, pink, pink1, pink1, pink3, pink3, plum, plum, plum1, plum1, plum2, plum2, plum3, plum3, plum4, plum4, powderblue, powderblue, purple, purple, purple3, purple3, purple4, purple4, red, red, red1, red1, red3, red3, rosybrown, rosybrown, royalblue, royalblue, royalblue1, royalblue1, saddlebrown, saddlebrown, salmon, salmon, salmon1, salmon1, sandybrown, sandybrown, seagreen, seagreen, seagreen1, seagreen1, seagreen2, seagreen2, seagreen3, seagreen3, seashell, seashell, sienna, sienna, silver, silver, skyblue, skyblue, skyblue1, skyblue1, skyblue2, skyblue2, skyblue3, skyblue3, slateblue, slateblue, slateblue1, slateblue1, slateblue3, slateblue3, slategray, slategray, slategrey, slategrey, snow, snow, springgreen, springgreen, springgreen1, springgreen1, springgreen2, springgreen2, springgreen3, springgreen3, springgreen4, springgreen4, steelblue, steelblue, steelblue1, steelblue1, steelblue3, steelblue3, tan, tan, teal, teal, thistle, thistle, thistle1, thistle1, thistle3, thistle3, tomato, tomato, turquoise, turquoise, turquoise2, turquoise2, turquoise4, turquoise4, violet, violet, wheat, wheat, wheat1, wheat1, wheat4, wheat4, white, white, whitesmoke, whitesmoke, yellow, yellow, yellow1, yellow1, yellow2, yellow2, yellow3, yellow3, yellow4, yellow4, yellowgreen, yellowgreen

Class Method Details

.add_html_colours_onto_the_toplevel_namespaceObject

#

Colours.add_html_colours_onto_the_toplevel_namespace

#

18
19
20
# File 'lib/colours/html_colours/add_html_colours_onto_the_toplevel_namespace.rb', line 18

def self.add_html_colours_onto_the_toplevel_namespace
  extend Colours::SupportForHTMLColours
end

.autogenerate_the_module_for_the_256_coloursObject

#

Colours.autogenerate_the_module_for_the_256_colours

This method will autogenerate the module that will support the 256 colours.

#

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/colours/utility_scripts/autogenerate.rb', line 96

def self.autogenerate_the_module_for_the_256_colours
  _ = ''.dup
  _ << GENERIC_RUBY_HEADER+"
# require 'colours/autogenerated/support_for_256_colours.rb'
# =========================================================================== #
"
  _ << "require 'colours/256_colours/support_for_256_colours.rb'\n\n"
  _ << "module Colours\n\n"
  _ << "module SupportFor256Colours # include Colours::SupportFor256Colours\n\n".dup
  comment_line = '  # '+('='*73)+' #'+N
  @dataset_for_the_256_colours.each {|name_of_the_colour, id|
    use_this_name = name_of_the_colour.downcase
    _ << comment_line
    _ << '  # === Colours::SupportFor256Colours.'+use_this_name+N
    _ << comment_line
    _ << "  def self.#{use_this_name}(i = '')#{N}"
    _ << "    if Colours.use_colours?\n"
    _ << "      Colours.return_this_256_colour(__method__, i)\n"
    _ << "    else\n"
    _ << "      i\n"
    _ << "    end\n"
    _ << "  end; def #{use_this_name}(i = ''); SupportFor256Colours.#{use_this_name}(i); end#{N}#{N}"
  }
  _ << 'end; end'
  what = _
  # ======================================================================= #
  # This is only useful on my home system really:
  # ======================================================================= #
  into = HOME_DIRECTORY_OF_USER_X+'DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\
         'colours/lib/colours/autogenerated/support_for_256_colours.rb'
  puts 'Storing into:'
  puts
  puts '  '+into
  puts
  require 'save_file'
  SaveFile.write_what_into(what, into)
end

.autogenerate_the_module_for_the_html_colours(into = HOME_DIRECTORY_OF_USER_X+'DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\ 'colours/lib/colours/autogenerated/support_for_html_colours.rb') ⇒ Object

#

Colours.autogenerate_the_module_for_the_html_colours

This method will autogenerate the module that will support the html colours.

#

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/colours/utility_scripts/autogenerate.rb', line 140

def self.autogenerate_the_module_for_the_html_colours(
    into = HOME_DIRECTORY_OF_USER_X+'DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\
           'colours/lib/colours/autogenerated/support_for_html_colours.rb'
  )
  _ = ''.dup
  _ << GENERIC_RUBY_HEADER+"
# require 'colours/autogenerated/support_for_html_colours.rb'
# =========================================================================== #
"
  _ << "require 'colours/toplevel_methods/html_colourize.rb'\n"
  _ << "require 'colours/toplevel_methods/use_colours.rb'\n\n"
  _ << "module Colours\n\n"
  _ << "module SupportForHTMLColours # include Colours::SupportForHTMLColours\n\n".dup
  comment_line = '  # '+('='*73)+' #'+N
  available_html_colours?.each {|name_of_the_html_colour|
    _ << comment_line
    _ << '  # === Colours::SupportForHTMLColours.'+name_of_the_html_colour+N
    _ << comment_line
    _ << "  def self.#{name_of_the_html_colour}(i = '', &block)\n"
    _ << "    if Colours.use_html_colours?\n"
    _ << "      Colours.html_colourize(__method__, i, &block)\n"
    _ << "    else\n"
    _ << "      i\n"
    _ << "    end\n"
    _ << "  end; def #{name_of_the_html_colour}(i = '', &block); SupportForHTMLColours.#{name_of_the_html_colour}(i, &block); end#{N}"
    # ===================================================================== #
    # Next, due to several reasons, we add a prepended "konsole_colour_"
    # as name to this method.
    # ===================================================================== #
    _ << "       def konsole_colour_#{name_of_the_html_colour}(i = '', &block); SupportForHTMLColours.#{name_of_the_html_colour}(i, &block); end#{N}#{N}"
  }
  _ << 'end; end'
  what = _
  # ======================================================================= #
  # This is only useful on my home system really:
  # ======================================================================= #
  puts 'Storing into:'
  puts
  puts '  '+into
  puts
  require 'save_file'
  SaveFile.write_what_into(what, into)
end

.autogenerate_toplevel_basic_colour_methods(into = HOME_DIRECTORY_OF_USER_X+'DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\ 'colours/lib/colours/autogenerated/toplevel_basic_colour_methods.rb') ⇒ Object

#

Colours.autogenerate_toplevel_basic_colour_methods

The code in this method will autogenerate the toplevel colour methods, such as Colours.yellow().

The code needs to respect several settings. For example, whether colours are used or not. Additionally, for methods such as Colours.yellow(), we need to find out whether we use the basic colours, the 256-colours or the HTML colours, and call the corresponding method in these cases.

#

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/colours/utility_scripts/autogenerate.rb', line 195

def self.autogenerate_toplevel_basic_colour_methods(
    into = HOME_DIRECTORY_OF_USER_X+'DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\
           'colours/lib/colours/autogenerated/toplevel_basic_colour_methods.rb'
  )
  comment_line = "  # ======================================================================== \n"
  store_this_string = ''.dup
  header = <<-EOF
#{GENERIC_RUBY_HEADER}
# This file contains the code that will call the corresponding colour method
# depending on which colour-mode the user prefers.
# =========================================================================== #
# require 'colours/autogenerated/toplevel_basic_colour_methods.rb'
# =========================================================================== #
require 'colours/toplevel_methods/use_colours.rb'
require 'colours/basic_colours/basic_colours.rb'
require 'colours/256_colours/support_for_256_colours.rb'
require 'colours/autogenerated/support_for_html_colours.rb'

module Colours

module AllColourMethods # include Colours::AllColourMethods

EOF

  store_this_string << header
  # ======================================================================= #
  # First define the methods for the basic colours:
  # ======================================================================= #
  array = return_a_unique_array_containing_all_available_colours
  array.each {|this_basic_colour| # <- e. g. "yellow".
    this_basic_colour = this_basic_colour.dup
    if this_basic_colour.include?(' ') and
       array.include?(this_basic_colour.delete(' '))
      # =================================================================== #
      # === This must be an alias
      #
      # In this case we will also add an alias containing the '_' part.
      # We will only add this as an alias for include-actions, though.
      # (This may change at a later point in the future - not sure yet.)
      # =================================================================== #
      store_this_string << "       def #{this_basic_colour.tr(' ','_')}(i = ''); AllColourMethods.#{this_basic_colour.delete(' ')}(i); end\n"
    else
      name_of_the_method = this_basic_colour.downcase.delete(' ').dup
      store_this_string << comment_line
      store_this_string << "  # === Colours::AllColourMethods.#{name_of_the_method}\n"
      store_this_string << comment_line
      store_this_string << "  def self.#{name_of_the_method}(i = '', &block)\n"
      store_this_string << "    if Colours.use_colours?\n"
      # =================================================================== #
      # Ok, so we determine what to do with this colour-method:
      # =================================================================== #
      store_this_string << "      if Colours.is_this_a_html_colour?(__method__)\n"
      store_this_string << "        Colours::SupportForHTMLColours.#{name_of_the_method}(i, &block)\n"
      store_this_string << "      elsif Colours.is_this_a_256_colour?(__method__)\n"
      store_this_string << "        Colours::SupportFor256Colours.#{name_of_the_method}(i, &block)\n"
      store_this_string << "      else\n"
      store_this_string << "        Colours::BasicColours.#{name_of_the_method}(i, &block)\n"
      store_this_string << "      end\n"
      store_this_string << "    else\n"
      store_this_string << "      i\n"
      store_this_string << "    end\n"
      store_this_string << "  end; def #{name_of_the_method}(i = '', &block); AllColourMethods.#{name_of_the_method}(i, &block); end\n"
      # =================================================================== #
      # Next, due to several reasons, we add a prepended "konsole_colour_"
      # as name to this method.
      # =================================================================== #
      store_this_string << "       def konsole_colour_#{name_of_the_method}(i = ''); AllColourMethods.#{name_of_the_method}(i); end\n"
      store_this_string << "       def konsole_#{name_of_the_method}(i = ''); AllColourMethods.#{name_of_the_method}(i); end\n"
      store_this_string << "       self.instance_eval { alias konsole_colour_#{name_of_the_method} #{name_of_the_method} } # === Colours::AllColourMethods.konsole_colour_#{name_of_the_method}\n"
      store_this_string << "       def Colours.e#{name_of_the_method}(i = ''); puts AllColourMethods.#{name_of_the_method}(i); end\n"
      store_this_string << "       def e#{name_of_the_method}(i = ''); puts AllColourMethods.#{name_of_the_method}(i); end\n"
      store_this_string << "       alias ekonsole_colour_#{name_of_the_method} e#{name_of_the_method}\n"
      store_this_string << "\n"
    end
  }
  store_this_string << "end; end\n"
  what = store_this_string .dup
  # ======================================================================= #
  # This is only useful on my home system really:
  # ======================================================================= #
  puts 'Storing into the file:'
  puts
  puts "  #{into}"
  puts
  require 'save_file'
  File.delete(into) if File.exist? into # Get rid of the old file.
  SaveFile.write_what_into(what, into)
end

.available_file_constantsObject

#

Colours.available_file_constants

#

61
62
63
64
65
66
# File 'lib/colours/constants/file_constants.rb', line 61

def self.available_file_constants
  [
    FILE_HTML_COLOURS,
    FILE_KDE_COLOUR_PALETTE
  ]
end

.available_html_colours?Boolean

#

Colours.available_html_colours?

#

Returns:

  • (Boolean)

138
139
140
# File 'lib/colours/html_colours/misc.rb', line 138

def self.available_html_colours?
  ::Colours::HtmlColours.available_html_colours?
end

.available_main_colours?Boolean

#

Colours.available_main_colours?

Feedback which main colours are available.

#

Returns:

  • (Boolean)

61
62
63
# File 'lib/colours/constants/hash_simple_colours.rb', line 61

def self.available_main_colours?
  MAIN_COLOURS
end

.bold(show_this_text = 'This must be bold.') ⇒ Object

#

Colours.bold

Usage example:

puts ' ok | '+Colours.bold('Hello world!')+' | ok'
#

20
21
22
23
24
# File 'lib/colours/toplevel_methods/bold.rb', line 20

def self.bold(
    show_this_text = 'This must be bold.'
  )
  "\x1b[1m#{show_this_text}#{REVERT}"
end

.bold_and_italic(i = 'This must be bold.') ⇒ Object

#

Colours.bold_and_italic

Usage example:

puts Colours.bold_and_italic 'Hello world!'
#

19
20
21
22
23
24
25
26
# File 'lib/colours/toplevel_methods/bold_and_italic.rb', line 19

def self.bold_and_italic(
    i = 'This must be bold.'
  )
  if i.is_a? Array
    i = i.join(' ')
  end
  italic(bold(i))
end

.cat(file_descriptor, hash_options = {}) ⇒ Object

#

Colours.cat

The first argument may be ARGF. It ought to respond to .each anyway.

Note that .cat) will delegate towards print_line().

#

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/colours/toplevel_methods/cat.rb', line 18

def self.cat(
    file_descriptor, hash_options = {}
  )
  print "\e[?25l" if hash_options[:animate] # Print this if we animate (enabling psychedelics).
  # ======================================================================= #
  # Iterate over the file_descriptor passed.
  # ======================================================================= #
  file_descriptor.each { |line|
    hash_options[:os] += 1 # Increase the output-count.
    # ===================================================================== #
    # Next, colourize the line. This depends on the method called
    # print_rainbow_line().
    # ===================================================================== #
    RainbowColours.print_rainbow_line(
      line, hash_options
    ) # Delegate towards print_line.
  }
ensure
  print "\e[?25h" if hash_options[:animate]
end

.clear_screenObject

#

Colours.clear_screen

Simply perform 'clear' here.

#

14
15
16
# File 'lib/colours/toplevel_methods/clear_screen.rb', line 14

def self.clear_screen
  system 'clear'
end

.cliner(i = 78) ⇒ Object

#

Colours.cliner

#

12
13
14
15
16
17
# File 'lib/colours/toplevel_methods/cliner.rb', line 12

def self.cliner(i = 78)
  if block_given?
    yield
  end
  puts '=' * i
end

.col(i, optional_arg_not_in_use_right_now = '') ⇒ Object

#

Colours.col (col tag)

Careful - this method may collide with other methods named col().

Usage examples:

Colours.col '/Depot/j/geojgirjh'
Colours.col '/Users/x/AUDIO/'
Colours.col '/Users/x/AUDIO/Westbam_Sunshine.mp3'
#

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/colours/toplevel_methods/col.rb', line 25

def self.col(
    i,
    optional_arg_not_in_use_right_now = ''
  )
  if File.exist? i
    ftype = File.ftype(i)
    # e 'The ftype is: '+ftype # <- This could be used for debugging.
    case ftype
    # ===================================================================== #
    # === file
    # ===================================================================== #
    when 'file'
      return sfile(i)
    # ===================================================================== #
    # === directory
    # ===================================================================== #
    when 'directory'
      return sdir(i)
    # ===================================================================== #
    # === link
    # ===================================================================== #
    when 'link'
      return ssymlink(i)
    else
      e "module Colours: We do not know the filetype `#{ftype}`"
    end
  else # Else return the input a bit changed.
    return sfile(i) # We modify it because that is better.
  end
end
#

This method will simply return the colour for symlinks.

#

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/colours/colour_methods/ssymlink.rb', line 48

def self.colour_for_symlinks
  result = ''.dup
  if @use_colours
    if @use_html_colours
      result = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[:ssymlink])
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      result = SupportFor256Colours.send(use_this_colour)
    else
      result = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"
    end
  end
  result
end

.colour_table?Boolean

#

Colours.colour_table?

This method will feedback the available colour-table.

To invoke this method, try the following code:

pp Colours.colours?
#

Returns:

  • (Boolean)

266
267
268
# File 'lib/colours/colour_table/colour_table.rb', line 266

def self.colour_table?
  @colour_table
end

.colour_to_rgb(i = :slateblue) ⇒ Object

#

Colours.colour_to_rgb

#

131
132
133
# File 'lib/colours/html_colours/misc.rb', line 131

def self.colour_to_rgb(i = :slateblue)
  ::Colours::HtmlColours.colour_to_rgb(i)
end

.commandline?Boolean

#

Colours.commandline?

#

Returns:

  • (Boolean)

24
25
26
# File 'lib/colours/commandline/commandline.rb', line 24

def self.commandline?
  @commandline
end

.convert_hex_code_to_RGBA_array(i, default_alpha_value = 1.0) ⇒ Object

#

Colours.convert_hex_code_to_RGBA_array

RGBA stands for “red, green, blue, alpha”. Alpha indicates how opaque each pixel is.

The usual values for the alpha parameter, aka the last parameter, is a number between 0.0 (which means “fully transparent”) and the number 1.0 (which means “not transparent at all”).

Note that this method is similar to Colours.convert_hex_to_rgb(hex), but it has a fourth argument, aka A (for Alpha), on top of the RGB values.

Usage example:

Colours.convert_hex_code_to_RGBA_array('#baf185') # => [186, 241, 133]
#

148
149
150
151
152
153
154
# File 'lib/colours/toplevel_methods/misc.rb', line 148

def self.convert_hex_code_to_RGBA_array(
    i, default_alpha_value = 1.0
  )
  rgba_array = convert_hex_to_rgb(i)
  rgba_array << default_alpha_value
  return rgba_array
end

.convert_hex_to_rgb(hex) ⇒ Object

#

Colours.convert_hex_to_rgb

This method will convert e. g. #baf185 to [186, 241, 133]. Thus it will return an Array, denoting the R, G, B values.

How to do this conversion on your own?

(1) Get the 2 left digits of the hex color code and convert
    to decimal value to get the red color level.
(2) Get the 2 middle digits of the hex color code and
    convert to decimal value to get the green color level.
(3) Get the 2 right digits of the hex color code and
    convert to decimal value to get the blue color level.

Usage example:

Colours.convert_hex_to_rgb('#baf185') # => [186, 241, 133]
#

115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/colours/toplevel_methods/misc.rb', line 115

def self.convert_hex_to_rgb(hex)
  if hex.is_a? Array
    hex = hex.first
  end
  hex = hex.to_s.dup
  hex.delete!('#') if hex.include? '#'
  array = [] # We will return this Array.
  r = hex[0,2].to_i(16)
  g = hex[2,2].to_i(16)
  b = hex[4,2].to_i(16)
  array << r << g << b
  return array
end

.convert_this_html_colour_into_an_array_of_rgb_values(html_colour = :random) ⇒ Object

#

Colours.convert_this_html_colour_into_an_array_of_rgb_values

This method will take a String as input, a HTML colour such as 'slateblue', and proceed to return an Array containing three entries (R, G, B) as its value.

For RGB colours we specify the code like this:

38;2;$R;$G;$B

Thus:

\e[38;2;R;G;Bm
#

265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/colours/rgb/rgb.rb', line 265

def self.convert_this_html_colour_into_an_array_of_rgb_values(
    html_colour = :random
  )
  case html_colour
  when :random
    html_colour = return_random_html_colour
  end
  if Colours.include_this_html_colour? html_colour
    pointer = Colours.hash_html_colours?[html_colour.to_s] # <- Must be an input-String.
    [ pointer[0], pointer[1], pointer[2] ] # <- Build the Array here.
  else # else it is not included
    nil
  end
end

.convert_this_rgb_value_into_a_html_colour(i, g = nil, b = nil) ⇒ Object

#

Colours.convert_this_rgb_value_into_a_html_colour

This method will convert a given RGB value (input assumed to be an Array) into the corresponding HTML colour.

Note that the first input argument, called `i`, can also be read as R (aka red). So the whole input line becomes “r, g, b”, which makes this quite trivial to remember.

#

236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/colours/rgb/rgb.rb', line 236

def self.convert_this_rgb_value_into_a_html_colour(i, g = nil, b = nil)
  if i.is_a?(Numeric) and g and b
    i = [i, g, b] # Re-compose the given input in this case, as only one Array was provided.
  end
  _ = Colours.hash_html_colours?
  possible_matches = _.select {|key, inner_array|
    (i[0] == inner_array[0]) and
    (i[1] == inner_array[1]) and
    (i[2] == inner_array[2])
  }
  possible_matches.keys.first
end

.convert_this_rgb_value_to_that_hexadecimal_representation(r, g = nil, b = nil) ⇒ Object

#

Colours.convert_this_rgb_value_to_that_hexadecimal_representation

This method will convert RGB values to their hexadecimal (hex) representation.

Invocation example:

Colours.convert_this_rgb_value_to_that_hexadecimal_representation([240, 248, 255]) # => "F0F8FF"
Colours.rgb_to_hex(255,0,0) # => "FF0000"
Colours.rgb_to_hex('255255255')
Colours.rgb_to_hex(:slateblue)
#

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/colours/rgb/rgb.rb', line 416

def self.convert_this_rgb_value_to_that_hexadecimal_representation(
    r, g = nil, b = nil
  )
  hash = Colours.hash_html_colours?
  if r.is_a?(Symbol) and g.nil? and b.nil? and
     is_this_a_html_colour?(r)
    return hash[r.to_s][3]
  end
  if r.is_a?(String) and !r.include?('#') and g.nil? and b.nil?
    # ======================================================================= #
    # In this case assume input such as '255255255'
    # ======================================================================= #
    splitted = r.split(/(...)/).reject(&:empty?)
    r, g, b = splitted
  end
  if r.is_a?(Array) and (r.size > 1) and g.nil? and b.nil?
    # ======================================================================= #
    # In this case the user supplied only a single Array as input.
    # ======================================================================= #
    this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r)
  else
    this_html_colour = Colours.convert_this_rgb_value_into_a_html_colour(r, g, b)
  end
  if this_html_colour
    hash[this_html_colour][3]
  else
    nil
  end
end

.default_colour(i = '', make_newline = false) ⇒ Object

#

Colours.default_colour

Invocation example:

puts Colours.default_colour('Hello world!')
#

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/colours/colour_methods/default_colour.rb', line 23

def self.default_colour(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if make_newline
      i = "#{i}#{N}"
    end
    if @use_html_colours
      i = SupportForHTMLColours.send(@colour_table[__method__.to_sym], i)
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])  
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.disable_colours(be_verbose = false) ⇒ Object

#

Colours.disable_colours

This method can be used to disable the colours on the Colours namespace.

#

74
75
76
77
78
79
# File 'lib/colours/toplevel_methods/use_colours.rb', line 74

def self.disable_colours(
    be_verbose = false
  )
  puts 'Disabling colours next.' if be_verbose
  @use_colours = false
end

.disable_konsole_coloursObject

#

Colours.disable_konsole_colours

Disable the KDE-Konsole colours.

#

54
55
56
# File 'lib/colours/toplevel_methods/use_colours.rb', line 54

def self.disable_konsole_colours
  @use_html_colours = false
end

.display_this_256_colour(id = 9, use_this_text = "Hello world!\n", &block) ⇒ Object

#

Colours.display_this_256_colour

The first argument should be a number from 0 to 255.

You can also batch-output all colours, by using something like:

Colours.display_this_256_colour('0-255',"Hello world, in a batch!\n")

Generic usage example:

Colours.display_this_256_colour(33, 'yo there') { :newline }
#

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 97

def self.display_this_256_colour(
    id            = 9,
    use_this_text = "Hello world!\n",
    &block
  )
  if block_given?
    yielded = yield
    case yielded
    when :newline
      use_this_text = use_this_text.dup if use_this_text.frozen?
      use_this_text << "\n"
    end
  end
  if id.is_a?(String) and id.include?('-')
    # ===================================================================== #
    # Assume pseudo-range input.
    # ===================================================================== #
    splitted = id.split('-')
    range = (splitted.first.to_i .. splitted.last.to_i).to_a
    range.each {|this_range_id|
      display_this_256_colour(this_range_id, use_this_text, &block)
    }
  else
    print return_this_256_colour(id, use_this_text)
  end
end

.does_include?(i = :slateblue) ⇒ Boolean

#

Colours.does_include?

Usage examples:

Colours.does_include? 'slateblue'
Colours.is_this_html_colour_included? 'royalblue' # => true
Colours.is_this_html_colour_included? 'megawhite' # => false
#

Returns:

  • (Boolean)

51
52
53
54
# File 'lib/colours/html_colours/is_this_html_colour_included.rb', line 51

def self.does_include?(i = :slateblue)
  i = i.to_sym unless i.is_a? Symbol
  ::Colours::HtmlColours.does_include?(i)
end

.does_this_line_include_a_html_colour?(line) ⇒ Boolean

#

Colours.does_this_line_include_a_html_colour?

This method can be used to determine whether the given input-string contains a valid HTML colour or whether it does not.

Returns: a boolean.

Invocation examples:

Colours.does_this_line_include_a_html_colour? "<green>yo there</green> <orange>getline() function</orange>" # => true
Colours.does_this_line_include_a_html_colour? "foo bar" # => false
#

Returns:

  • (Boolean)

87
88
89
90
91
92
93
# File 'lib/colours/toplevel_methods/misc.rb', line 87

def self.does_this_line_include_a_html_colour?(
    line
  )
  Colours.html_colours?.any? {|entry|
    line.include? entry
  }
end

.does_this_string_include_a_html_colour?(i) ⇒ Boolean

#

Colours.does_this_string_include_a_html_colour?

#

Returns:

  • (Boolean)

136
137
138
139
140
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 136

def self.does_this_string_include_a_html_colour?(i)
  result = (i =~ REGEX_FOR_HTML_COLOURS)
  result = false if result.nil?
  result
end

.does_this_string_include_a_html_number?(i) ⇒ Boolean

#

Colours.does_this_string_include_a_html_number?

This method will return true if the string includes tags such as <one> or <two> and so forth.

#

Returns:

  • (Boolean)

148
149
150
151
152
153
154
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 148

def self.does_this_string_include_a_html_number?(i)
  i.include?('<one>')   or
  i.include?('<two>')   or
  i.include?('<three>') or
  i.include?('<four>')  or
  i.include?('<five>')
end

.e(i = N, append_newline = true) ⇒ Object

#

Colours.e

This is essentially just a fancified wrapper over puts.

Usage examples:

Colours.e 'hello world'
Colours.e "hi \n there\n is everything fine? \n\n"
#

28
29
30
31
32
33
34
35
36
37
# File 'lib/colours/toplevel_methods/e.rb', line 28

def self.e(
    i              = N,
    append_newline = true
  )
  i = i.join(' ') if i.is_a? Array
  _ = "#{rev}#{i.to_s.dup}".dup # Work with a copy here.
  _.chomp! # So that we won't have more than one newline initially.
  _ << N if append_newline # This should be the last modification before calling print.
  print _ # And print the result finally.
end

.ecomment(i, optional_split_at_this_character = '#') ⇒ Object

#

Colours.ecomment

This method here was added on Nov 2013.

In April 2014, the ability to split at any arbitrary character was added, which can be controlled via the second argument given to that method.

#

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/colours/colour_methods/scomments.rb', line 57

def self.ecomment(
    i,
    optional_split_at_this_character = '#' # <- Specify which character to split at.
  )
  _ = i.to_s
  if optional_split_at_this_character.is_a? Hash
    if optional_split_at_this_character.has_key? :token
      optional_split_at_this_character = optional_split_at_this_character.delete :token
    end
  end
  optional_split_at_this_character = optional_split_at_this_character.to_s
  # ======================================================================= #
  # === If we can find a token to split at
  # ======================================================================= #
  if _.include? optional_split_at_this_character
    use_this_regex = /#(.+)/ # See: http://rubular.com/r/oRUg7lw4oE
    colour_for_comments = map_colour_to_constant(scomments?)
    _ = _.dup if _.frozen?
    _.gsub!(use_this_regex,
      colour_for_comments+optional_split_at_this_character.to_s+'\\1'+rev)
  end
  e _
end

.efancy(i = '', make_newline = false) ⇒ Object

#

Colours.efancy

This simply will output the result from sfancy(), defined above.

#

47
48
49
50
51
52
# File 'lib/colours/colour_methods/sfancy.rb', line 47

def self.efancy(
    i            = '',
    make_newline = false
  )
  e sfancy(i, make_newline)
end

.eimp(i = '', make_newline = false) ⇒ Object

#

Colours.eimp

#

70
71
72
73
74
75
# File 'lib/colours/colour_methods/simportant.rb', line 70

def self.eimp(
    i            = '',
    make_newline = false
  )
  e simp(i, make_newline)
end

.eliminate_html(i, use_this_colour_for_the_default_colour = :default, use_this_as_replacement_hash = :default_hash) ⇒ Object

#

Colours.eliminate_html

This method simply combines two other methods, without any further checks inside of this method. The method will thus remove entries such as <one> or <steelblue>.

#

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 189

def self.eliminate_html(
    i,
    use_this_colour_for_the_default_colour = :default,
    use_this_as_replacement_hash           = :default_hash
  )
  i = i.dup
  i = Colours.replace_number_words_with_the_corresponding_html_colour(
    i,
    use_this_colour_for_the_default_colour,
    use_this_as_replacement_hash
  )
  i = i.dup
  i = Colours.replace_html_colours_in_this_string(
    i,
    use_this_colour_for_the_default_colour
  )
  return i.dup
end

.enable_colours(be_verbose = false) ⇒ Object

#

Colours.enable_colours

Use this method to enable colours for the whole Colours namespace.

#

86
87
88
89
90
91
# File 'lib/colours/toplevel_methods/use_colours.rb', line 86

def self.enable_colours(
    be_verbose = false
  )
  puts 'Enabling colours next.' if be_verbose
  @use_colours = true # Defined below.
end

.enable_html_coloursObject

#

Colours.enable_html_colours

Use this method to specifically enable konsole-colours.

#

45
46
47
# File 'lib/colours/toplevel_methods/use_colours.rb', line 45

def self.enable_html_colours
  @use_html_colours = true
end

.eparse(i = '') ⇒ Object

#

Colours.eparse

This method primarily exists because we can easily split a string if it has a '#' token. The part that comes after the '#' token is assumed to be a comment or an explanation.

#

19
20
21
# File 'lib/colours/eparse/eparse.rb', line 19

def self.eparse(i = '')
  Colours.e(rparse(i))
end
#
#

81
82
83
84
85
86
# File 'lib/colours/colour_methods/ssymlink.rb', line 81

def self.esymlink(
    i            = '',
    make_newline = false
  )
  e Colours.ssymlink(i, make_newline)
end

.esystem(i) ⇒ Object

#

esystem

#

14
15
16
17
# File 'lib/colours/toplevel_methods/esystem.rb', line 14

def self.esystem(i)
  e i
  system i
end

.ewarn(i = '', make_newline = false) ⇒ Object

#

Colours.ewarn

#

55
56
57
58
59
60
# File 'lib/colours/colour_methods/swarn.rb', line 55

def self.ewarn(
    i            = '',
    make_newline = false
  )
  e swarn(i, make_newline)
end

.fancy_parse(i = '', use_this_colour = :default_colour) ⇒ Object

#

Colours.fancy_parse

This method can be used to parse a line containing special tags, such as <i> or <teal>, and replace them with the corresponding ASCII code for the commandline. The second example, e. g. <teal>, is known as a HTML colour tag (htmlcolour).

The idea for this method is to simply use it to quickly colourize some arbitrary text.

The method will only return the resulting, sanitizing String; if you wish to display this on the terminal/commandline then you will have to use puts or print on your own.

Usage examples:

Colours.fancy_parse '<i>hey</i> <teal>there</teal>'
puts Colours.fancy_parse '<i>hey</i> <teal>there</teal> ok'
#

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/colours/toplevel_methods/fancy_parse.rb', line 35

def self.fancy_parse(
    i               = '',
    use_this_colour = :default_colour
  )
  if i.is_a? Array
    i = i.join
  end
  i = i.dup # Work on a copy.
  # ======================================================================= #
  # === Handle italic tags, aka <i>
  # ======================================================================= #
  if i.include?('<i>') and
     i.include?('</i>')
    use_this_regex = /<i>([A-Za-zöäüÖÄÜ\s-]+)<\/i>/ # See: https://rubular.com/r/U35iBGeQRQLFxe
    i.gsub!(
      use_this_regex,
      return_italic('\1')
    )
  end
  # ======================================================================= #
  # === Handle bold tags, aka <b>
  # ======================================================================= #
  if i.include?('<b>') and
     i.include?('</b>')
    use_this_regex = /<b>(.+)<\/b>/
    i.gsub!(
      use_this_regex,
      return_bold('\1')
    )
  end
  # ======================================================================= #
  # Finally, handle all HTML colours in the given line.
  # ======================================================================= #
  i = replace_all_html_colours_in_this_line(i, use_this_colour)
  return i
end

.file_html_colours_to_rgb?Boolean

#

Colours.file_html_colours_to_rgb?

Easier toplevel-getter method to determine where the file for the html-colours-to-rgb conversion resides.

#

Returns:

  • (Boolean)

54
55
56
# File 'lib/colours/constants/file_constants.rb', line 54

def self.file_html_colours_to_rgb?
  "#{PROJECT_BASE_DIRECTORY}yaml/html_colours.yml"
end

.generate_shell_file_containing_the_html_colours(generate_the_shell_file_into_this_directory = Dir.pwd) ⇒ Object

#

Colours.generate_shell_file_containing_the_html_colours

This method will generate a shell file into the current directory by default.

The code in that file will generate a shell script that holds all the HTML-colours, via UPCASED names.

These entries will then look like this:

SADDLEBROWN:  "\e[38;2;139;69;19m"
PERU:         "\e[38;2;205;133;63m"
CHOCOLATE:    "\e[38;2;210;105;30m"
#

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/colours/utility_scripts/autogenerate.rb', line 58

def self.generate_shell_file_containing_the_html_colours(
    generate_the_shell_file_into_this_directory = Dir.pwd
  )
  require 'save_file/module'
  unless generate_the_shell_file_into_this_directory.end_with? '/'
    if generate_the_shell_file_into_this_directory.frozen?
      generate_the_shell_file_into_this_directory = generate_the_shell_file_into_this_directory.dup
    end
    generate_the_shell_file_into_this_directory << '/'
  end
  result = ''.dup
  result << "# This is a shell file that contains the HTML colours\n"
  ::Colours.html_colours?.each {|this_colour|
    colour_code_to_use = ::Colours.html_colourize(this_colour.to_sym,'',false).inspect
    result << "export #{this_colour.upcase}=#{colour_code_to_use}\n"
  }
  generate_the_shell_file_into_this_directory << 'shell_file_containing_the_html_colours.sh'
  into = generate_the_shell_file_into_this_directory
  e "Now creating a shell file at `#{into}`."
  SaveFile.write_what_into(result, into)
  # ======================================================================= #
  # Generate files on my home system as well:
  # ======================================================================= #
  if is_on_roebe?
    into = '/home/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\
           'roebe/lib/roebe/shell_scripts/'+
           File.basename(generate_the_shell_file_into_this_directory)
    puts "And also saving into `#{into}`."
    SaveFile.write_what_into(result, into)
  end
end

.hash_html_colours?Boolean

#

Colours.hash_html_colours?

#

Returns:

  • (Boolean)

55
56
57
# File 'lib/colours/html_colours/hash_html_colours.rb', line 55

def self.hash_html_colours?
  ::Colours::HtmlColours.hash_html_colours?
end

.html_colour_to_hex_value(this_html_colour, return_with_hash_key = true) ⇒ Object

#

Colours.html_colour_to_hex_value

#

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 159

def self.html_colour_to_hex_value(
    this_html_colour,
    return_with_hash_key = true
  )
  if this_html_colour.is_a? Array
    this_html_colour = this_html_colour.first
  end
  _ = file_html_colours_to_rgb?
  if File.exist? _
    dataset = YAML.load_file(_)
    if dataset.has_key? this_html_colour
      _ = dataset[this_html_colour].last
      if return_with_hash_key
        _ = _.dup if _.frozen?
        _ = _.to_s unless _.is_a? String
        _[0,0] = '#' if _.respond_to? :[]=
      end
      return _
    end
  end
  return this_html_colour
end

.html_colour_to_rgb_value(this_html_colour = 'slateblue') ⇒ Object

#

Colours.html_colour_to_rgb_value

This method will return a String, representing the RGB values.

It will, other than that, not make any other modifications; in particular it will NOT append a trailing “m” token.

By default the R, G, B values will be separated via a ';' token. If you don't want this then modify it e. g. via: .tr(';',',').

Usage examples:

Colours.html_colour_to_rgb_value('slateblue') # => "106;90;205"
Colours.html_colour_to_rgb_value('crimson')   # => "220;20;60"
Colours.html_colour_to_rgb(:steelblue)        # => "70;130;180"
#

466
467
468
469
470
471
# File 'lib/colours/rgb/rgb.rb', line 466

def self.html_colour_to_rgb_value(
    this_html_colour = 'slateblue'
  )
  _ = Colours.convert_this_html_colour_into_an_array_of_rgb_values(this_html_colour.to_sym)
  return "#{_[0]};#{_[1]};#{_[2]}"
end

.html_colourize(colour_to_use = return_random_html_colour, this_text = nil, append_revert = true, &block) ⇒ Object

#

Colours.html_colourize

This method will simply return the colour-code + text.

The third argument, called `append_revert`, can be used to determine whether we will append the revert code to the generated output String or whether we will not. By default we will, but there are examples where we may wish to assemble our own colour string, and in these cases we do not yet know which text is to be shown - hence, this must become an optional argument.

A block can be passed to this method. If the block has, as content, the Symbol :omit_end then the end-part of the ANSI code will not be used.

Usage examples:

x = Colours.colourize('slateblue', 'Hello world!'); pp x
y = Colours.colourize('slateblue', 'Hello world!') { :omit_end }; pp y
#

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/colours/toplevel_methods/html_colourize.rb', line 34

def self.html_colourize(
    colour_to_use = return_random_html_colour,
    this_text     = nil,
    append_revert = true,
    &block
  )
  if block_given?
    yielded = yield
    case yielded
    when :omit_end
      append_revert = false
    end
  end
  if this_text.nil?
    this_text = colour_to_use.to_s.dup
  end
  if append_revert
    "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}#{revert}"
  else
    "#{rgb_value_as_escape_code_string(colour_to_use)}#{this_text}"
  end
end

.is_a_valid_colour?(i) ⇒ Boolean

#

Colours.is_a_valid_colour?

This method allows you to check if a given input-string is a valid colour.

A “valid” colour is one that the colours project supports.

For example, the string “lightblue” is a valid colour.

Usage example:

Colours.is_a_valid_colour? 'lightblue'
#

Returns:

  • (Boolean)

142
143
144
# File 'lib/colours/constants/hash_simple_colours.rb', line 142

def self.is_a_valid_colour?(i)
  ALL_COLOURS.include? i.to_sym
end

.is_on_roebe?Boolean

#

Colours.is_on_roebe?

#

Returns:

  • (Boolean)

12
13
14
# File 'lib/colours/toplevel_methods/is_on_roebe.rb', line 12

def self.is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end

.is_this_a_256_colour?(i) ⇒ Boolean

#

Colours.is_this_a_256_colour?

Invocation example:

Colours.is_this_a_256_colour? 'LightSteelBlue3'
#

Returns:

  • (Boolean)

170
171
172
173
174
175
176
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 170

def self.is_this_a_256_colour?(i)
  if @dataset_for_the_256_colours
    @dataset_for_the_256_colours.keys.map(&:downcase).include?(i.to_s.downcase)
  else
    false
  end
end

.italic(i = '', make_newline = false, &block) ⇒ Object

#

Colours.italic

This method will “puts” the result of applying italic to a string, on the console/terminal. If you wish to do the output on your own then you have to use the method Colours.return_italic or its alias called Colours.string_italic.

To test this, try:

Colours.italic('Hello world!')
#

66
67
68
69
70
71
72
# File 'lib/colours/toplevel_methods/italic.rb', line 66

def self.italic(
    i            = '', 
    make_newline = false,
    &block
  )
  e return_italic(i, make_newline, &block)
end

.left?Boolean

#

Colours.left?

#

Returns:

  • (Boolean)

48
49
50
# File 'lib/colours/constants/misc.rb', line 48

def self.left?
  LEFT
end

.make_colour(what_colour_to_use) ⇒ Object

#

Colours.make_colour

This is used primarily for testing.

#

18
19
20
21
22
23
24
25
26
27
# File 'lib/colours/toplevel_methods/make_colour.rb', line 18

def self.make_colour(
    what_colour_to_use
  )
  i = what_colour_to_use # Copy.
  constant = i.to_s.upcase
  name_of_colour = const_get(constant)
  string = '%-34s' % ("#{name_of_colour} Test with #{constant}.")
  string << IS_A_TEST+'('+name_of_colour.inspect.delete('"')+')'
  e(string)
end

.map_symbol_to_corresponding_colour(i) ⇒ Object

#

Colours.map_symbol_to_corresponding_colour (menu tag)

This method will accept a symbol as input, such as :bold_blue, and return the corresponding CONSTANT (or rather, the value this constant refers to). This allows us to “map” the respective symbol to the corresponding constant.

For example, the Symbol :bold_blue will correspond to the BOLD_BLUE constant. The Symbol :bold_green will correspond to the BOLD_GREEN constant (or COLOUR_BOLD_GREEN; there are some “aliases” on the constant-level as well). This constant thus represents the symbol at hand.

Take note that this method here has several aliases:

Colours.translate()
Colours.beautify()
Colours.convert()
Colours.parse()
Colours.map_colour_to_constant()

This is partially due to historic reasons; and partially simply

because some of them are shorter and hence easier to type.

Usage example for this method:

Colours.beautiful(:bold_blue)
#

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb', line 42

def self.map_symbol_to_corresponding_colour(i)
  if i.is_a? String # Handle Strings as well.
    # ===================================================================== #
    # === random
    # ===================================================================== #
    if i == 'random' # Fetch a random entry in this case.
      i = MAIN_COLOURS.sample
    end
    i = i.tr(' ','_').to_sym
  end
  case i # case tag
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       :si,
       :default_colour,
       :defaultcolour,
       :normal,
       nil
    return DEFAULT_COLOUR
  # ======================================================================= #
  # === :bold_green
  # ======================================================================= #
  when :bold_green,
       :boldgreen,
       :bright_green,
       :greenb,
       :lightgreen
    return BOLD_GREEN
  # ======================================================================= #
  # === :bold_brown
  # ======================================================================= #
  when :bold_brown,
       :bbrown,
       :gold,
       :saddlebrown
    return BOLD_BROWN
  # ======================================================================= #
  # === :white
  # ======================================================================= #
  when :white,
       :whitebonblack
    return WHITE
  # ======================================================================= #
  # === :red
  # ======================================================================= #
  when :red
    return RED
  # ======================================================================= #
  # === :light_grey
  # ======================================================================= #
  when :light_grey,
       :grey
    return COLOUR_LIGHT_GREY
  # ======================================================================= #
  # === :pink
  # ======================================================================= #
  when :pink,
       :bright_magenta
    return BRIGHT_MAGENTA
  # ======================================================================= #
  # === :bright_cyan
  # ======================================================================= #
  when :bright_cyan,
       :cyanb,
       :cyan
    return BOLD_CYAN
  # ======================================================================= #
  # === :brown
  # ======================================================================= #
  when :brown
    return BROWN
  # ======================================================================= #
  # === :yellow
  # ======================================================================= #
  when :yellow,
       :yel
    return YELLOW
  # ======================================================================= #
  # === :green
  # ======================================================================= #
  when :green,
       :greengreen
    return GREEN
  # ======================================================================= #
  # === :blue
  # ======================================================================= #
  when :blue
    return BLUE
  # ======================================================================= #
  # === :magenta
  # ======================================================================= #
  when :magenta
    return MAGENTA
  # ======================================================================= #
  # === :teal
  # ======================================================================= #
  when :teal
    return TEAL
  # ======================================================================= #
  # === :revert
  # ======================================================================= #
  when :revert,
       :reset,
       :clear
    return REVERT
  # ======================================================================= #
  # === :bold_red
  # ======================================================================= #
  when :bold_red,
       :boldred,
       :bright_red,
       :lightred,
       :redb
    return BOLD_RED
  # ======================================================================= #
  # === :lightblue
  # ======================================================================= #
  when :lightblue
    return LIGHTBLUE
  # ======================================================================= #
  # === :bold_yellow
  # ======================================================================= #
  when :bold_yellow,
       :boldyellow,
       :yelb,
       :bright_yellow,
       :byellow
    return BOLD_YELLOW
  # ======================================================================= #
  # === :bold_blue
  # ======================================================================= #
  when :bold_blue,
       :boldblue,
       :bright_blue,
       :blueb
    return BOLD_BLUE
  # ======================================================================= #
  # === :bold_white
  # ======================================================================= #
  when :bold_white,
       :boldwhite,
       :bright_white
    return BOLD_WHITE
  # ======================================================================= #
  # === :black
  # ======================================================================= #
  when :black,
       :bold_black,
       :boldblack,
       :bright_black
    return COLOUR_BLACK
  else
    puts "Unknown symbol given as input: #{i}"
    pp i
  end
  i # else return the input-argument again.
end

.map_this_symbol_to_that_256_colour(i) ⇒ Object

#

Colours.map_this_symbol_to_that_256_colour

This method will take input such as :bold_green and associate it with a corresponding 256-colour. Thus, the resulting Symbol that is found here should correspond to a method on module SupportFor256Colours.

#

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/colours/colour_table/colour_table.rb', line 110

def self.map_this_symbol_to_that_256_colour(i)
  case i
  when :boldgreen,
       :bold_green
    :chartreuse2
  when :teal
    :teal
  when :bold_yellow
    :yellow2
  when :gold
    :gold3
  when :bold_blue
    :lightslateblue
  when :bold_brown
    :darkred
  when :brown
    :maroon
  when :pink
    :hotpink3
  when :lightgrey,
       :light_grey
    :grey66
  when :bold_red
    :red1
  when :lightblue,
       :light_blue
    :deepskyblue3
  when :grey
    :grey53
  when :green
    :chartreuse4
  else
    puts "Not known input to method #{__method__.to_s}: #{i}"
  end
end

.map_this_symbol_to_that_html_colour(i) ⇒ Object

#

Colours.map_this_symbol_to_that_html_colour

The job of this method is to map entries such as :bold_green to a corresponding HTML colour.

#

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/colours/colour_table/colour_table.rb', line 80

def self.map_this_symbol_to_that_html_colour(i)
  if is_a_html_colour? i
    i
  else
    case i
    when :cyanb
      :lightseagreen
    when :light_grey
      :lightgray
    when :bold_blue
      :slateblue
    when :bold_red, :redb
      :crimson
    when :bold_yellow
      :goldenrod
    when :bold_green
      :seagreen
    else
      puts 'Unregistered input into the method '+__method__.to_s+': '+i.to_s
    end
  end
end
#

Colours.menu (menu tag)

To invoke this method, try:

colours --show_html_colours
colours file?
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/colours/commandline/menu.rb', line 21

def self.menu(
    i = @commandline
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === colours --generate_shell_file_containing_the_html_colours
    #
    # This entry point will autogenerate the shell-file that contains
    # the HTML colours (RGB colours).
    # ===================================================================== #
    when /^-?-?generate(-|_)?shell(-|_)?file(-|_)?containing(-|_)?the(-|_)?html(-|_)?colours$/i,
         /^-?-?create(-|_)?shell(-|_)?file$/i # === colours --create-shell-file
      generate_shell_file_containing_the_html_colours
    # ===================================================================== #
    # === colours --show-html_colours
    # ===================================================================== #
    when /^-?-?show(-|_)?html(-|_)?colours$/i,
         /^-?-?show(-|_)?all(-|_)?html(-|_)?colours$/i,
         /^-?-?show(-|_)?all(-|_)?colours$/i,
         /^-?-?html(-|_)?colours$/,
         'html_colours','htmlcolours','hcolours',
         'scolours','all','ALL','1','ALL_COLOURS',
         'colours?',
         'all_colours',
         'COLOURS',
         'html',
         '' # Show all colours here
      Colours.show_html_colours
      exit
    # ===================================================================== #
    # === colours --basics
    # ===================================================================== #
    when /^-?-?basics?$/i
      Colours.show_basic_colour_palette
      exit
    # ===================================================================== #
    # === colours --open
    # ===================================================================== #
    when 'OPEN',
         /^-?-?open$/
      open_this_file :then_exit
    # ===================================================================== #
    # === colours --file?
    # ===================================================================== #
    when /^-?-?file\??$/i,
         'file','file?'
      cliner {
        e 'We will next read in from the default file, from:'
        e
        e "  #{sfile(TEST_FILE)}"
        e
        read_and_display_this_file
      }
    # ===================================================================== #
    # === colours --project_base_directory?
    # ===================================================================== #
    when /^-?-?project(_|-)?base(_|-)?dir\??$/i,
         /^-?-?project(_|-)?base(_|-)?directory\??$/i,
         /^-?-?base(_|-)?dir\??$/i
      e PROJECT_BASE_DIRECTORY
    # ===================================================================== #
    # === colours --show-colour-palette
    # === colours --palette
    #
    # This entry point will show the basic colour palette.
    # ===================================================================== #
    when /^-?-?show(-|_)?colou?r(-|_)?palette$/i,
         /^-?-?show(-|_)?palette$/i,
         /^-?-?palette$/i
      show_colour_palette
    # ===================================================================== #
    # === colours --help
    # ===================================================================== #
    when /^-?-?help$/i
      show_help
    end
  end
end

.prefer_which_colour_schemata?Boolean

#

Colours.prefer_which_colour_schemata?

#

Returns:

  • (Boolean)

74
75
76
# File 'lib/colours/toplevel_methods/prefer_this_colour_schemata.rb', line 74

def self.prefer_which_colour_schemata?
  @prefer_this_colour_schemata[1].to_sym if @prefer_this_colour_schemata
end

.project_base_dir?Boolean

#

Colours.project_base_dir?

#

Returns:

  • (Boolean)

18
19
20
# File 'lib/colours/project/project_base_directory.rb', line 18

def self.project_base_dir?
  PROJECT_BASE_DIRECTORY
end

.random_colour?Boolean

#

Colours.random_colour?

Obtain a random sample, aka a random colour, from all the registered html colours.

#

Returns:

  • (Boolean)

119
120
121
# File 'lib/colours/html_colours/misc.rb', line 119

def self.random_colour?
  Colours::HtmlColours.random_colour?
end

.random_html_colourObject

#

Colours.random_html_colour

This method will simply return a (one) random HTML colour, in long format, e. g. “teal” or “slateblue”.

If you wish to have it colourized properly, you need to use another method.

Usage examples:

Colours.random_colour? # => "teal"
Colours.random_colour? # => "blueviolet"
#

26
27
28
# File 'lib/colours/toplevel_methods/random_html_colour.rb', line 26

def self.random_html_colour
  ::Colours::HtmlColours.random_colour?
end

.random_html_colour_with_this_text(use_this_text = '') ⇒ Object

#

Colours.random_html_colour_with_this_text

The first argument is the text that we wish to display.

Usage example:

puts Colours.random_html_colour_with_this_text 'foo bar'
#

333
334
335
336
337
# File 'lib/colours/rgb/rgb.rb', line 333

def self.random_html_colour_with_this_text(
      use_this_text = ''
    )
  "#{rgb_value_as_escape_code_string}#{use_this_text}#{restore?}"
end

.random_value?Boolean

#

Colours.random_value?

We will obtain a random value between 0 and 255, hence why we will use rand(256).

#

Returns:

  • (Boolean)

15
16
17
# File 'lib/colours/toplevel_methods/random_value.rb', line 15

def self.random_value?
  rand(256)
end

.read_and_display_this_file(i = TEST_FILE) ⇒ Object

#

Colours.read_and_display_this_file

This method accepts a file path - in other words, the input should be the location of a specific file on your filesystem - and then simply reads in the content of said file via File.readlines().

Content such as <slateblue> found in this file will be replaced with the respective R,G,B substring value.

In the test/ subdirectory there is an example file for this - have a look there for more information.

#

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/colours/toplevel_methods/misc.rb', line 47

def self.read_and_display_this_file(
    i = TEST_FILE
  )
  i = i.to_s
  if File.exist? i
    new_array = []
    data = File.readlines(i)
    data.each {|entry|
      # ======================================================================= #
      # Check whether the entry has a <> tag:
      # ======================================================================= #
      if entry.include?('<') and entry.include?('>') and 
         entry.include?('</>')
        # ================================================================= #
        # Ok, we may assume that something like <slateblue> is there.
        # ================================================================= #
        entry = sanitize_line(entry)
      end
      new_array << entry
    }
    e new_array # For now we will simply output that modified Array.
  else
    e "Notice: The file at `#{sfile(i)}` does not exist."
  end
end

.really_all_coloursObject

#

Colours.really_all_colours

This method will return an Array that may look like this:

[:black, :red, :green, :yellow, :blue, :magenta, :teal,
 :white, :bright_black, :bright_red, :bright_green,
 :bright_yellow, :bright_blue, :bright_magenta,
 :bright_cyan, :bright_white]
#

125
126
127
# File 'lib/colours/constants/hash_simple_colours.rb', line 125

def self.really_all_colours
  ALL_COLOURS # This is the conjoint Array.
end

.remove_escape_sequence(i = ARGV) ⇒ Object

#

Colours.remove_escape_sequence

The method Colours.remove_escape_sequence() will remove all Ansi Escape sequences from a given string.

#

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/colours/toplevel_methods/remove_escape_sequence.rb', line 18

def self.remove_escape_sequence(i = ARGV)
  if i.is_a? Array
    i = i.join("\n")
  end
  i = i.to_s.dup
  # ======================================================================= #
  # Iterate over the registered ansi-colours next.
  # ======================================================================= #
  ARRAY_REGISTERED_ANSI_COLOURS.each {|entry|
    if i.include? entry
      entry = Regexp.quote(entry)
      i.sub!(/#{entry}/, '')
    end
    # ===================================================================== #
    # Next, check for KDE konsole colours. We must use "" there, not ''.
    # ===================================================================== #
    if i.include?("\e[") and i =~ /\d+m/ # Such as: "\e[38;2;220;20;60m|"
      # =================================================================== #
      # The next regex will (hopefully) remove all escape-characters
      # from the given String.
      # =================================================================== #
      regex_for_html_colours = # Detect entries such as: \e[38;2;106;90;205m
        /(\e\[\d{2};\d{1};\d{3};\d{1,2};\d{3}m)/ # See: https://rubular.com/r/tG3XeOK5NPsfmI
      i.gsub!(regex_for_html_colours, '')
      # =================================================================== #
      # See: https://rubular.com/r/SdS28fAGSxIELn
      # =================================================================== #
      # /(\\e\[\d{1,2};?\d{1,2};?\d{0,3};?\d{0,3};?\d{1,2}m|\\e\[\d{0,2}m|\\e\[K|\\e\[\d{0,2};\d{0,2}m|(\\e\[.+\dm)|\\e\[0;37m)/
      [
        /\e\[\d{1,2};?\d{1,2};?\d{0,3};?\d{0,3};?\d{1,2}m/,
        /\\e\[\d{0,2}m|\\e\[K|\\e\[\d{0,2};\d{0,2}m/,
        /\\e\[.+\dm/,
        /\\e\[0;37m/
      ].each {|regex_to_use|
        i.gsub!(regex_to_use, '')
      }
    end
  }
  return i
end

.remove_trailing_end_from(i, remove_this_escape_sequence = Colours.revert?) ⇒ Object

#

Colours.remove_trailing_end_from

The second argument to this method can be the escape sequence that you wish to remove.

Invocation example:

x = Colours.remove_trailing_end_from("\e[38;2;70;130;180m\e[0;37m") # => "\e[38;2;70;130;180m"
#

73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/colours/toplevel_methods/remove_escape_sequence.rb', line 73

def self.remove_trailing_end_from(
    i,
    remove_this_escape_sequence = Colours.revert?
  )
  quoted = Regexp.quote(remove_this_escape_sequence)
  # ======================================================================= #
  # Anchor it at the end via $.
  # ======================================================================= #
  return i.sub(
    /#{quoted}$/, ''
  )
end

.replace_html_colours_in_this_string(i, use_this_colour_for_the_default_colour = :default, shall_we_revert_at_the_end_of_the_line = false) ⇒ Object

#

Colours.replace_html_colours_in_this_string

This method will replace all HTML colours in a given string, such as “<slateblue>test</slateblue>”, with the corresponding RGB colour variant for the commandline.

Typically this refers to a terminal such as the KDE Konsole, and a shell such as bash (although other shells are fine too, and many other terminals, such as the gnome-terminal, most likely will work fine as well - but it is optimized for the KDE Konsole).

This method should only be called after a prior check was done, to determine whether the given input String at hand does indeed include a valid HTML colour; otherwise it would be a bit pointless to invoke the method, if it is already known that the String at hand does not contain any HTML colour at all. In order to determine whether a String may include a valid HTML colour, the method called line_contains_a_valid_html_colour?() can be used.

Usage example:

Colours.replace_html_colours_in_this_string
Colours.replace_html_colours_in_this_string('- The <one>UID</one> of <royalblue>the</royalblue> user called <two>root</two> is ... ? <one>0</one>.', :lightgreen)
#

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 68

def self.replace_html_colours_in_this_string(
    i,
    use_this_colour_for_the_default_colour = :default, # ← This specifies the default colour.
    shall_we_revert_at_the_end_of_the_line = false
  )
  i = i.dup # We want to work on a copy.
  result = ''.dup # Our result-string.
  case use_this_colour_for_the_default_colour
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       :default_colour
    use_this_colour_for_the_default_colour = USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR
  end
  case shall_we_revert_at_the_end_of_the_line
  # ======================================================================= #
  # === :revert
  # ======================================================================= #
  when :revert
    shall_we_revert_at_the_end_of_the_line = true
  end
  result << ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
  result = result.dup
  # ======================================================================= #
  # This method will make use of two different regexes.
  # ======================================================================= #
  scanned_results = i.scan(
    REGEX_FOR_HTML_COLOURS
  ).flatten
  add_on_string = i.dup
  scanned_results.uniq.each {|this_colour|
    if is_this_a_valid_html_colour?(this_colour)
      # =================================================================== #
      # === Defining the Regex in use
      #
      # Note that the regex at rubular is not always updated. I only
      # needed it to check for the basic parts.
      #
      # Regex see:
      #
      #   https://rubular.com/r/0WJXdVznVjKRWH
      #
      # =================================================================== #
      use_this_regex =
        /<#{this_colour}>([\[\]\\{}\(\)\/!\-#*~:;≡=+a-zA-Z0-9←→₁₂₃₄₅₆₇₈₉⁰¹²³⁴⁵⁶⁷⁸⁹ÅäöüÄÖÜαβß&%°"',_\|\n\. ]+)<\/#{this_colour}>/
      # =================================================================== #
      # We must use .gsub!() because the colour-string may occur more 
      # than once. Unfortunately for longer Strings this becomes a bit
      # fragile.
      # =================================================================== #
      part1 = ::Colours::AllColourMethods.send(this_colour.to_sym, "\\1") { :omit_end }
      part2 = ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
      add_on_string.gsub!(use_this_regex, part1+part2).dup
    end
  }
  result << add_on_string
  if shall_we_revert_at_the_end_of_the_line
    result << ::Colours.revert
  end
  return result
end

.replace_number_words_with_the_corresponding_html_colour(i, use_this_as_replacement_hash = :default) ⇒ Object

#

Colours.replace_number_words_with_the_corresponding_html_colour

The input to this method should be the String that contains HTML numbers such as <one> or <two>.

This method can be customized a bit. One way to customize it is to pass the default colour to this method, as second argument. The default colour is (currently, in Oct 2020) grey.

The third argument is a Hash. This Hash can be used to denote the default colours for <one>, <two> and so forth. So if you want to change the colours, pass in your own Hash into this method.

Usage examples:

x = Colours.replace_number_words_with_the_corresponding_html_colour("- <teal>Asbestbedingte Erkrankungen</teal> haben eine <two>Latenzzeit</two> von etwa n Jahren? Etwa <steelblue>30 Jahren</steelblue>.")
x = "<one>Methämoglobin</one> ist <two>ungeeignet</two> für <three>den</three> Sauerstofftransport; die <two>roten Blutkörperchen</two>. Welches Enzymsystem ist dies?"
y = Colours.replace_number_words_with_the_corresponding_html_colour(x)

See also:

https://rubular.com/r/XUPQJFKlDs2OYP
#

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/colours/toplevel_methods/methods_related_to_html_colours.rb', line 235

def self.replace_number_words_with_the_corresponding_html_colour(
    i,
    use_this_as_replacement_hash = :default
  )
  # ======================================================================= #
  # Specify our "replacement-hash", that is colours used for e. g.
  # <one>, <two> or <three>.
  # ======================================================================= #
  case use_this_as_replacement_hash
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       :default_hash
    # ===================================================================== #
    # The following hash can be used as a default "replacement" Hash.
    # ===================================================================== #
    use_this_as_replacement_hash = {
      one:            :teal,
      two:            :lightseagreen,
      three:          :mediumseagreen, # ← Used to be 'peru' up until 23.11.2019.
      four:           :olivedrab,
      five:           :lightgreen,
      default_colour: USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR # Defined on top.
    }
  end
  # ======================================================================= #
  # === :default_colour
  # ======================================================================= #
  if use_this_as_replacement_hash.has_key? :default_colour
    use_this_colour_for_the_default_colour = use_this_as_replacement_hash[:default_colour]
  end
  # ======================================================================= #
  # === Enable support for <one>, <two>, <three>, <four> and <five> next.
  # ======================================================================= #
  if i.include?('<one>')   or
     i.include?('<two>')   or
     i.include?('<three>') or
     i.include?('<four>')  or
     i.include?('<five>')
    scanned_results = i.scan(
      REGEX_FOR_HTML_COLOURS
    ).flatten.uniq
    scanned_results.each {|this_numbered_word|
      # =================================================================== #
      # Since as of December 2021 we only accept Symbols here.
      # =================================================================== #
      this_numbered_word = this_numbered_word.to_sym
      if use_this_as_replacement_hash.has_key? this_numbered_word
        i = i.dup if i.frozen?
        replacement_colour = use_this_as_replacement_hash[this_numbered_word]
        use_this_regex =
          # =============================================================== #
          # See:
          #
          #   https://rubular.com/r/sDNQd81MtciMJL
          #
          # =============================================================== #
          /<#{this_numbered_word}>([-#~≥!\e=><;,→⁻⁺@^„“γαµ_₀₁₂₃₄₅₆₇₈₉²³⁴⁵⁶⁷⁸⁹äöüÄÖÜβß%&:≡°$A-Za-z0-9\n \?\\'\|\(\)\{\}\[\]\"\*\.\+]+)<\/#{this_numbered_word}>/
        # ================================================================= #
        # We must use .gsub!() because the colour-string may occur more
        # than once.
        # ================================================================= #
        i.gsub!(
          use_this_regex,
          ::Colours::AllColourMethods.send(replacement_colour.to_sym, "\\1")       { :omit_end }+
          ::Colours::AllColourMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
        )
        # i << ::Colours.revert
      end
    }
  end
  return i
end

.report_whether_colours_will_be_usedObject

#

Colours.report_whether_colours_will_be_used

#

121
122
123
124
125
126
127
# File 'lib/colours/toplevel_methods/use_colours.rb', line 121

def self.report_whether_colours_will_be_used
  if @use_colours
    puts 'Yes, colours will be used.'
  else
    puts 'Colours are currently disabled.'
  end
end

.require_the_colour_methodsObject

#

Colours.require_the_colour_methods

This method will batch-require the .rb files that are found in the colour_methods/ subdirectory of the colours gem.

#

23
24
25
26
27
28
29
30
# File 'lib/colours/requires/require_the_colour_methods.rb', line 23

def self.require_the_colour_methods
  target = "#{Colours::PROJECT_BASE_DIRECTORY}colour_methods/"

  Dir["#{target}*.rb"].each {|this_file|
    require target+File.basename(this_file)
  }

end

.return_a_unique_array_containing_all_available_coloursObject

#

Colours.return_a_unique_array_containing_all_available_colours

#

31
32
33
34
35
36
37
38
39
40
# File 'lib/colours/utility_scripts/autogenerate.rb', line 31

def self.return_a_unique_array_containing_all_available_colours
  array = []
  array << YAML.load_file(FILE_HTML_COLOURS).keys                # (1) First the HTML colours
  array << YAML.load_file(FILE_256_COLOURS).keys.map(&:downcase) # (2) Then the basic colours
  array << YAML.load_file(FILE_BASIC_COLOURS)                    # (3) And finally the basic colours
  array.flatten!
  array.uniq!
  array.map!(&:strip)
  array.sort
end

.return_italic(show_this_text = 'This must be italic.', make_newline = false) ⇒ Object

#

Colours.return_italic

To test this method, try:

Colours.italic('Hello world!')
#

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/colours/toplevel_methods/italic.rb', line 32

def self.return_italic(
    show_this_text = 'This must be italic.', 
    make_newline   = false
  )
  result = "\x1b".dup
  result << '['
  result << ITALIC_CODE
  if block_given?
    # ===================================================================== #
    # Right now we assume that this must be a colour.
    # ===================================================================== #
    result << ";38;2;"
    result << html_colour_to_stringified_rgb_values(yield)
  end
  result << 'm'
  if make_newline
    show_this_text = "#{show_this_text}\n"
  end
  result << show_this_text
  result << REVERT
  result
end

.return_random_rgbObject

#

Colours.return_random_rgb

#

283
284
285
# File 'lib/colours/rgb/rgb.rb', line 283

def self.return_random_rgb
  [random_value?, random_value?, random_value?]
end

.return_this_256_colour(id = 9, use_this_text = "Hello world!") ⇒ Object

#

Colours.return_this_256_colour

The first argument to this method should be a number from 0 to 255.

For example, 255 is also known as “Grey93” - a variant of grey.

It appears to work better if you use print() rather than puts() for whatever is returned here - perhaps due to the leading u001b part.

You can also input the colour variant, such as 'Grey93'.

Invocation example:

Colours.return_this_256_colour(255, "Hello world in grey!\n")
print Colours.return_this_256_colour(255, (Roebe.block_character*5)+"  Hello world in grey!  "+(Roebe.block_character*5)+" \n")
print Colours.return_this_256_colour('DarkTurquoise', (Roebe.block_character*5)+"  Hello world in DarkTurquoise!  "+(Roebe.block_character*5)+" \n")
#

46
47
48
49
50
51
52
53
54
55
56
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 46

def self.return_this_256_colour(
    id            = 9,
    use_this_text = "Hello world!"
  )
  id = id.to_s.downcase
  if (id !~ /^\d+/) and @dataset_for_the_256_colours and
    @dataset_for_the_256_colours.has_key?(id)
    id = @dataset_for_the_256_colours[id]
  end
  "\u001b[38;5;#{id}m#{use_this_text}#{REVERT}"
end

.return_this_text_in_random_colour(show_this_text = '') ⇒ Object

#

Colours.return_this_text_in_random_colour

Invocation example:

puts Colours.return_this_text_in_random_colour('Hello World!')
#

383
384
385
386
387
388
# File 'lib/colours/rgb/rgb.rb', line 383

def self.return_this_text_in_random_colour(
    show_this_text = ''
  )
  use_this_colour = ::Colours.random_colour?
  "#{rgb(use_this_colour)}#{show_this_text}#{restore?}"
end

.return_this_via_kde_colour_palette(this_text = '', this_colour = 'Pimpinella') ⇒ Object

#

Colours.return_this_via_kde_colour_palette

To invoke this method, try:

Colours.return_this_via_kde_colour_palette 'Hello world!'
Colours.return_this_via_kde_colour_palette 'Hello world!', :random
Colours.return_this_via_kde_colour_palette 'Hello world!', :plasma_blue
#

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/colours/kde_colour_palette/kde_colour_palette.rb', line 73

def self.return_this_via_kde_colour_palette(
    this_text   = '',
    this_colour = 'Pimpinella'
  )
  use_this_rgb_value_array = []
  case this_colour
  when :random # Pick a random colour in this case.
    this_colour = KDE_COLOUR_PALETTE.keys.sample
  else
    if this_colour.is_a? Symbol
      if this_colour.to_s.include? '_'
        # ================================================================= #
        # In this case, try to convert it.
        # ================================================================= #
        this_colour = this_colour.to_s.split('_').map(&:capitalize).join(' ')
      else
        this_colour = this_colour.to_s.capitalize
      end
    end
  end
  if KDE_COLOUR_PALETTE.has_key? this_colour
    use_this_rgb_value_array = KDE_COLOUR_PALETTE[this_colour][1]
  end
  # ======================================================================= #
  # Finally return the text, in the corresponding colour at hand.
  # ======================================================================= #
  return Colours.rgb_value_as_escape_code_string(use_this_rgb_value_array)+
         this_text+
         rev
end

.return_underline(show_this_text = 'This must be underline.', make_newline = false, use_this_as_revert_code = REVERT) ⇒ Object

#

Colours.return_underline

The point of this method here is to make a given text (String) appear “underlined”, via ANSI escape sequences. For underline the String that should be used is “u001b[4m”.

This can be tested on the commandline such as via:

echoen "\u001b[4m Underline \u001b[0m"

Usage examples:

puts ' ok | '+Colours.return_underline('Hello world!')+' | ok'
puts ' ok | '+Colours.return_underline('Hello world!') { :slateblue }+' | ok'

In January 2022 the second variant was removed, though. Let's keep things simple for now - perhaps in the future this may be re-enabled.

#

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/colours/toplevel_methods/underline.rb', line 77

def self.return_underline(
    show_this_text          = 'This must be underline.',
    make_newline            = false,
    use_this_as_revert_code = REVERT
  )
  # ===================================================================== #
  # Build up our main string that codes for underline.
  # ===================================================================== #
  result = "\u001b[4m".dup
  # if block_given?
  #   # ===================================================================== #
  #   # Right now we assume that this must be a colour if it is supplied
  #   # via a block. However had, in January 2022 I realised that this
  #   # assumption is not always correct, so this was disabled for now.
  #   # At a later moment in time we may reconsider this.
  #   # ===================================================================== #
  #   result << ";38;2;"
  #   colour_replacement = colour_to_rgb_value(yield)
  #   result << colour_replacement
  # end
  # result << 'm'
  if make_newline # Append a newline in this case.
    show_this_text = "#{show_this_text}\n"
  end
  result << show_this_text
  result << use_this_as_revert_code
  result
end

.revObject

#

Colours.rev

We use this method to revert to the old default, that is, the prior state for ANSI colours. It should be equivalent to: “x1b[0m” e. g. REVERT = “x1b[0m” # “x1b[39;49m” <— This here seems to fail for Konsole.underline, though.

An alternative could be DEFAULT_COLOUR.

#

76
77
78
79
# File 'lib/colours/revert/revert.rb', line 76

def self.rev
  # REVERT # <- This used to be: "\e[0;37m"
  @revert # This is light white. I prefer this colour actually.
end

.rgb_print(array = %w( 100 247 63 ), text = 'Hello world!') ⇒ Object

#

Colours.rgb_print

The first argument to this method should be an Array.

We will print here. If you need a newline appended, you have to do so on your own, by appending a n onto the text variable given to this method - or use Colours.rgb_puts() instead.

Specific usage examples:

Colours.rgb_print ["100", "247", "63"], 'Hello '
Colours.rgb_print ["100", "247", "25"], 'World!'
#

352
353
354
355
356
357
# File 'lib/colours/rgb/rgb.rb', line 352

def self.rgb_print(
    array = %w( 100 247 63 ),
    text  = 'Hello world!'
  )
  print "#{rgb_value_as_escape_code_string(array)}#{text}#{REVERT}"
end

.rgb_puts(array = %w( 100 247 63 ), text = 'Hello world!') ⇒ Object

#

Colours.rgb_puts

First argument should be an Array.

We will use puts here.

Specific usage examples:

Colours.rgb_puts ["100", "247", "63"], 'Hello '
Colours.rgb_puts ["100", "247", "25"], 'World!'
#

370
371
372
373
374
375
# File 'lib/colours/rgb/rgb.rb', line 370

def self.rgb_puts(
    array = %w( 100 247 63 ),
    text  = 'Hello world!'
  )
  rgb_print(array, "#{text}\n")
end

.rgb_value_as_escape_code_string(array = [ random_value?, random_value?, random_value? ], g = nil, b = nil) ⇒ Object

#

Colours.rgb_value_as_escape_code_string

This method will take a R,G,B value and show us a String representation

#

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/colours/rgb/rgb.rb', line 481

def self.rgb_value_as_escape_code_string(
    array = [
      random_value?,
      random_value?,
      random_value?
    ],
    g = nil,
    b = nil
  )
  if array.is_a? Symbol
    array = array.to_s
  end
  if array.is_a?(Array) and (array.size == 3)
    r = array[0]
    g = array[1]
    b = array[2]
  elsif array.is_a?(String) and g.nil? and b.nil?
    # ======================================================================= #
    # In this case we will assume a HTML colour. We thus have to
    # determine its rgb value.
    # ======================================================================= #
    if ::Colours.is_this_html_colour_included?(array)
      set_last_colour_used(array)
      r, g, b = Colours.convert_this_html_colour_into_an_array_of_rgb_values(array)
    else
      puts 'The input is not a HTML colour:'
      pp array
    end
  end
  # =========================================================================== #
  # The String that we build up in this method will have the ANSI escape
  # code on the left side.
  # =========================================================================== #
  return "#{left?}#{r};#{g};#{b}m"
end

.rparse(i = '') ⇒ Object

#

Colours.rparse

This method will return a string; the method eparse will output that (colourized) String.

#

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/colours/eparse/eparse.rb', line 29

def self.rparse(i = '')
  _ = i.to_s # We require a String.
  split_at = ':' # <- Split at this character.
  # ======================================================================== #
  # If the input does not include a ':' but it does include a '#', then
  # we will use that character instead.
  #
  # However had, as of Jun 2017, I have disabled that check. Now '#' will
  # always overrule. My reasoning now is that '#' is more important than
  # ':', if it is part of the input-string.
  # ======================================================================== #
  split_at = '#' if _.include? '#'
  first_colour  = COLOUR_GREEN
  second_colour = COLOUR_TEAL
  if i.include? split_at
    splitted = _.split(split_at)
    _ = first_colour+
        splitted.first+
        split_at+
        second_colour+
        splitted[1..-1].join(split_at).dup
    _ << REVERT
  elsif i.include? ' '
    split_at = ' '
    splitted = _.split(/ /)
    index = splitted.find_index {|e| ! e.empty? }
    _ = first_colour+splitted[0..index].join(' ')+split_at+
        second_colour+splitted[index+1..-1].join(' ').dup
    _ << REVERT
  end
  return _
end

.sanitize_line(entry) ⇒ Object

#

Colours.sanitize_line

This method will replace one line with the proper R,G,B valid entries.

#

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/colours/toplevel_methods/misc.rb', line 18

def self.sanitize_line(entry)
  all_potential_matches = entry.scan(/<(\w+)>/).flatten
  all_potential_matches.each {|substring|
    entry.gsub!(/<\/>/, rev)
    entry.gsub!(/<#{substring}>/, rgb_format(substring))
  }
  begin
    require 'roebe/modules/remove_html.rb'
  rescue LoadError; end
  if Object.const_defined?(:Roebe) and
     Roebe.respond_to?(:remove_html)
    entry = Roebe.remove_html[entry]
  end
  return entry
end

.sargument(i = '', make_newline = false) ⇒ Object

#

Colours.sargument

Invocation example:

Colours.sargument('Hello world!')
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/colours/colour_methods/sargument.rb', line 21

def self.sargument(
    i            = '',
    make_newline = false
  )
  if make_newline
    i = "#{i}#{N}"
  end
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(@colour_table[__method__.to_sym], i)
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.scomments(i = '', make_newline = false) ⇒ Object

#

Colours.scomments

Invocation example:

Colours.scomments('Hello world!')
#

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/colours/colour_methods/scomments.rb', line 22

def self.scomments(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(@colour_table[__method__.to_sym], i)
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.scomments?Boolean

#

Colours.scomments?

#

Returns:

  • (Boolean)

84
85
86
# File 'lib/colours/colour_methods/scomments.rb', line 84

def self.scomments?
  colour_table?[:scomments]
end

.sdir(i = '', make_newline = false) ⇒ Object

#

Colours.sdir

Invocation example:

puts Colours.sdir('Hello world!')
#

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/colours/colour_methods/sdir.rb', line 23

def self.sdir(
    i            = '',
    make_newline = false
  )
  if make_newline
    i = "#{i}#{N}"
  end
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(@colour_table[__method__.to_sym], i)
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])  
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.set_colour_table(i = :new_colours) ⇒ Object

#

Colours.set_colour_table

This method can be used to modify the instance variable The input to this method should be a Hash. It can also be a Symbol, in which case we will try to find a Hash that corresponds to that Symbol.

If in doubt, pass in a Hash though.

#

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/colours/colour_table/colour_table.rb', line 182

def self.set_colour_table(
    i = :new_colours
  )
  case i
  when :new_colours,
       :new_colour_table,
       :default
    i = HASH_NEW_COLOURS
  end
  # ======================================================================= #
  # Note that we must ensure that all the necessary keys are there
  # in the given input. If this is not the case, then we will
  # determine which entries are missing, and assign them from the
  # instance variable @colour_table.
  # ======================================================================= #
  missing_entries = (
    i.keys - @colour_table.keys
  ).flatten
  unless missing_entries.empty?
    # ===================================================================== #
    # Push them onto i in this case.
    # ===================================================================== #
    missing_entries.each {|this_key|
      if i.has_key? this_key
        # All fine, pass through in this case.
      else
        add_this = missing_entries[this_key]
        i[key] = add_this

      end
    }
  end
  @colour_table = i
end

.set_commandline(i = ARGV) ⇒ Object

#

Colours.set_commandline

#

17
18
19
# File 'lib/colours/commandline/commandline.rb', line 17

def self.set_commandline(i = ARGV)
  @commandline = [i].flatten.compact
end

.set_last_colour_used(i) ⇒ Object

#

Colours.set_last_colour_used

#

28
29
30
# File 'lib/colours/toplevel_methods/set_last_colour_used.rb', line 28

def self.set_last_colour_used(i)
  @last_colour_used = i
end

.set_revert(i = :default) ⇒ Object

#

Colours.set_revert

#

59
60
61
62
63
64
65
# File 'lib/colours/revert/revert.rb', line 59

def self.set_revert(i = :default)
  case i
  when :default
    i = REVERT
  end
  @revert = i
end

.sfancy(i = '', make_newline = false) ⇒ Object

#

Colours.sfancy

Invocation example:

Colours.sfancy('Hello world!')
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/colours/colour_methods/sfancy.rb', line 21

def self.sfancy(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.sfile(i = '', make_newline = false) ⇒ Object

#

Colours.sfile

This method can be explicitely used to colour files, such as '/opt/foobar.rb'.

Invocation examples:

Colours.sfile('/opt/foobar.rb')
Colours.sfile('/tmp/test.md')
Colours.sfile('Hello world!')
#

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/colours/colour_methods/sfile.rb', line 29

def self.sfile(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.show_256_colour_cubeObject

#

Colours.show_256_colour_cube

This will show the 256-colours cube. Colours 16-231 are a 6x6x6 color cube.

#

148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 148

def self.show_256_colour_cube
  puts 'Color cube, 6x6x6 blocks:'
  0.upto(5) {|green|
    0.upto(5) {|red|
      0.upto(5) {|blue|
        colour = 16 + (red * 36) + (green * 6) + blue
        print "\x1b[48;5;#{colour}m  "
      }
      print "\x1b[0m "
    }
    puts
  }
end

.show_all_256_coloursObject

#

Colours.show_all_256_colours

#

127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 127

def self.show_all_256_colours
  yielded = nil
  if block_given?
    yielded = yield
  end
  0.upto(255).each {|this_number|
    result = this_number.to_s.rjust(4)+' '+
             return_this_256_colour(this_number).to_s.dup
    if yielded and yielded == :newline
      result << "\n"
    end
    print result
  }
end

.show_basic_colour_paletteObject

#

Colours.show_basic_colour_palette

This will show a colour palette on the commandline.

#

19
20
21
22
23
24
25
26
27
28
29
# File 'lib/colours/toplevel_methods/show_basic_colour_palette.rb', line 19

def self.show_basic_colour_palette
  e
  MAIN_COLOURS.reject {|e| e == :black }.each { |entry|
    make_colour(entry) # make_colour() is defined in this file here.
  }
  cliner
  SECONDARY_COLOURS.each { |entry|
    make_colour(entry)
  }
  e
end

.show_helpObject

#

Colours.show_help (help tag)

#

31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/colours/commandline/commandline.rb', line 31

def self.show_help
  e
  e 'This menu supports the following commands:'
  e
  eparse '  file?               # read in from the default test file'
  eparse '  html_colours        # show all html colours'
  eparse '  open                # open this file here in your editor'
  eparse '  --base-dir?         # show the project base directory '\
         'of the Colours namespace'
  eparse '  --show-html-colours # show the available HTML colours'
  e
end

.show_html_coloursObject

#

Colours.show_html_colours

#

67
68
69
# File 'lib/colours/html_colours/show_html_colours.rb', line 67

def self.show_html_colours
  ::Colours::HtmlColours.show_html_colours
end

.show_the_colour_tableObject

#

Colours.show_the_colour_table

This will simply pretty-print the current colour table.

#

230
231
232
# File 'lib/colours/colour_table/colour_table.rb', line 230

def self.show_the_colour_table
  pp @colour_table
end

.shuffleObject

#

Colours.shuffle

Shuffle the above table. The available colours to take here will be from the HtmlColours namespace.

#

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/colours/colour_table/colour_table.rb', line 240

def self.shuffle
  # ======================================================================= #
  # Point to the html "table" to use.
  # ======================================================================= #
  _ = ::Colours::HtmlColours.all?.shuffle
  @colour_table = {
    simp:      _.shift,
    sdir:      _.shift,
    sfile:     _.shift,
    swarn:     _.shift,
    sfancy:    _.shift,
    sargument: _.shift,
    ssymlink:  _.shift
  }
end

.simportant(i = '', make_newline = false) ⇒ Object

#

Colours.simportant

This method is the one to denote “important” text components.

Invocation examples:

Colours.simportant('Hello world!')
Colours.simportant('yo there')
#

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/colours/colour_methods/simportant.rb', line 26

def self.simportant(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.snormal(i = '', make_newline = false) ⇒ Object

#

Colours.snormal

Invocation example:

Colours.snormal('Hello world!')
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/colours/colour_methods/snormal.rb', line 21

def self.snormal(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end
#

Invocation example:

Colours.ssymlink('Hello world!')
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/colours/colour_methods/ssymlink.rb', line 21

def self.ssymlink(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.swarn(i = '', make_newline = false) ⇒ Object

#

Colours.swarn

Invocation example:

Colours.swarn('Hello world!')
#

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/colours/colour_methods/swarn.rb', line 21

def self.swarn(
    i            = '',
    make_newline = false
  )
  if @use_colours
    if @use_html_colours
      i = SupportForHTMLColours.send(
        map_this_symbol_to_that_html_colour(@colour_table[__method__.to_sym]), i
      )
    elsif @use_256_colours
      use_this_colour = map_this_symbol_to_that_256_colour(@colour_table[__method__.to_sym])
      i = SupportFor256Colours.send(use_this_colour, i)
    else
      i = "#{corresponding_colour?(@colour_table[__method__.to_sym])}"\
          "#{i}"\
          "#{rev}"
    end
  end
  i
end

.testObject

#

Colours.test

This class-method can be used to test the Colours module.

It will be called from the test.rb file, in order to test all components of the Colours module.

To invoke it, do:

Colours.test
#

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/colours/testing/testing.rb', line 28

def self.test
  require 'colours/basic_colours/basic_colours.rb'
  require 'colours/colour_table/colour_table.rb'
  cliner
  show_basic_colour_palette
  cliner
  e red('Hello ')+cyan('World!')
  e 'Hi '+Colours.red+'there.'+rev
  e 'Hi '+Colours.cyan+'there.'+rev
  e 'Hi '+Colours::BasicColours.bold_white+'there.'+rev
  e 'Hi '+Colours.pink+'there.'+rev
  e 'Hi '+Colours.brown+'there.'+rev
  cliner
  e CYAN+'Hi there.'
  e BWHITE+'Hi there.'+BBLUE+' Yo there.'+rev
  e sfancy('yo')+simp(' there')
  disable_colours(true)
  e sfancy('yo')+simp(' there')
  enable_colours(true)
  e sfancy('yo')+simp(' there')
  e rgb_to_hex('155255255')
  e col '/Depot/Audio'
  e col '/Depot/Audio/Westbam_Sunshine.mp3'
  e rev+'This is '+simp('elegant => simportant()')+'.'
  e rev+'This is '+sfancy('elegant => sfancy()')+'.'
  e rev+'This is '+sdir('elegant => sdir()')+'.'
  e rev+'This is '+sfile('elegant => sfancy()')+'.'
  e rev+'This is '+swarn('elegant => swarn()')+'.'
  e rev+'This is '+ssym('elegant => ssym()')+'.'
  ecomment 'An this # could be a comment.'
  e
  e 'Changing colour codes now. We should see different colours '+
    'when compared to the above.'
  e
  Colours.update_the_colour_codes_with
  e rev+'This is '+simportant('elegant => simportant()')+'.'
  e rev+'This is '+sfancy('elegant => sfancy()')+'.'
  e rev+'This is '+sdir('elegant => sdir()')+'.'
  e rev+'This is '+sfile('elegant => sfancy()')+'.'
  e rev+'This is '+swarn('elegant => swarn()')+'.'
  e rev+'This is '+ssym('elegant => ssym()')+'.'
  e 'Do we use colours? '+use_colours?.to_s
  e cyan+' ==> Hi there.'
  e red+' ==> Hi there.'
  e green+' ==> Hi there.'
  e brown+' ==> Hi there.'
  e blue+' ==> Hi there.'
  e teal+' ==> Hi there.'
  e white+' ==> Hi there.'
  e grey+' ==> Hi there.'
  e lightblue+' ==> Hi there.'+red()+' yo'
  e RED+'This is red galore.'
  e 'right?'+Colours.rev
  e BLUE+'This is blue now.'
  e 'right?'+rev
  e 'Hi there - this should be white.'
  # html_colours?
  p main_colours
  main_colours.each {|entry|
    send(entry, 'test')
  }
  e 'yo this should '+pink('be pink.')
  puts CFANCY+' Hi there.'
  puts CIMPORTANT+' Hi there.'
  # Next, we will disable the colours.
  disable_colours(true)
  # The following ones have a newline.
  e rev+'This is '+simportant('elegant => simportant().',true)
  e rev+'This is '+sfancy('elegant => sfancy().',true)
  e rev+'This is '+sdir('elegant => sdir().',true)
  e rev+'This is '+sfile('elegant => sfancy().',true)
  Colours.enable_colours(true)
  e rev+'This is '+simportant('elegant => simportant()')+'.'
  e rev+'This is '+sfancy('elegant => sfancy()')+'.'
  e rev+'This is '+sdir('elegant => sdir()')+'.'
  e rev+'This is '+sfile('elegant => sfancy()')+'.'; e
  e 'Next, trying to underline:'
  underline 'Hi there'
  e 'Next trying eparse:'
  eparse 'Joe: Hey Tim, how do you do?'
  eparse 'Tim: Really fine. How about you?'
  eparse '   Joe: ok man let us proceed'
  eparse '  [name of character here] # show when this character last logged in'
  e
  e 'Next some tests with col():'
  e
  e '  '+col('/Depot/Audio/AVAILABLE_SONGS').to_s
  e '  '+col('/Depot/Audio').to_s
  e
  cliner
  e 'Now testing Colours.red("foobar"):'
  e red('foobar')
  e 'Next, we test Colours.enable() and Colours.disable()'
  disable
  e 'Colours.disable()'
  e rev+'This is '+simportant('elegant => simportant()')+'.'
  e 'Colours.enable()'
  enable
  e rev+'This is '+simportant('elegant => simportant()')+'.'
  e rev+'The colour for symlinks is: '+simportant('Colours.colour_for_symlinks')
  pp colour_for_symlinks
  e rev+'A classical Hello World! example, and the colour-code for it.'
  efancy 'Hello World!'
  pp sfancy('Hello World!')
  e 'Next removing some escape sequences:'
  e
  e remove_escape_sequences("  \e[1;31mhello world\e[0;0m # <-- "+
    "This here is not coloured and it also does not have "+
    "escape-sequences either.")
  e
  e 'Next testing whether Colours.yellow() works:'
  e
  e "  hello #{Colours.yellow('world!')}#{rev}"
  e
  e 'Next testing Colours.eparse():'
  e
  eparse '  hello # world!'
  e
  e 'Next testing Colours.ecomment():'
  e
  ecomment '  hello # world!'
  e
end

.underline(i = '', make_newline = false, &block) ⇒ Object

#

Colours.underline

This method will “puts” the result of applying underline to a string, on the console/terminal. If you wish to do the output on your own then you have to use the method Colours.return_underline or its alias called Colours.string_underline.

To test this, try:

Colours.underline('Hello world!')
#

40
41
42
43
44
45
46
# File 'lib/colours/toplevel_methods/underline.rb', line 40

def self.underline(
    i            = '', 
    make_newline = false,
    &block
  )
  e return_underline(i, make_newline, &block)
end

.update_the_colour_codes_with(i = HASH_NEW_COLOURS) ⇒ Object

#

Colours.update_the_colour_codes_with (update tag)

#

40
41
42
# File 'lib/colours/colour_table/colour_table.rb', line 40

def self.update_the_colour_codes_with(i = HASH_NEW_COLOURS)
  @colour_table.update(i)
end

.use_colours=(new_value = true) ⇒ Object

#

Colours.use_colours=

Determine whether we will use colours or whether we will not.

The first input argument to this method should be a Bool, such as true or false.

#

101
102
103
104
105
# File 'lib/colours/toplevel_methods/use_colours.rb', line 101

def self.use_colours=(
    new_value = true
  )
  @use_colours = new_value
end

.use_colours?Boolean

#

Colours.use_colours?

Use this method to find out whether we wish to use colours or whether we do not.

#

Returns:

  • (Boolean)

36
37
38
# File 'lib/colours/toplevel_methods/use_colours.rb', line 36

def self.use_colours?
  @use_colours
end

.use_html_colours?Boolean

#

Colours.use_html_colours?

Query whether we will use the HTML colours or whether we will not.

#

Returns:

  • (Boolean)

63
64
65
# File 'lib/colours/toplevel_methods/use_colours.rb', line 63

def self.use_html_colours?
  @use_html_colours
end

.use_new_colour_tableObject

#

Colours.use_new_colour_table

#

221
222
223
# File 'lib/colours/colour_table/colour_table.rb', line 221

def self.use_new_colour_table
  set_colour_table(:new_colour_table)
end

.write_this_in_256_colours(this_text = "Hello world!\n", id = rand(256), &block) ⇒ Object

#

Colours.write_this_in_256_colours

Similar to the other write method, but has the arguments reversed.

#

63
64
65
66
67
68
69
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 63

def self.write_this_in_256_colours(
    this_text = "Hello world!\n",
    id        = rand(256),
    &block
  )
  display_this_256_colour(id, this_text, &block)
end

.write_this_in_random_colour(i = '') ⇒ Object

#

Colours.write_this_in_random_colour

Usage example:

Colours.write_this_in_random_colour 'hi there'
#

396
397
398
399
400
# File 'lib/colours/rgb/rgb.rb', line 396

def self.write_this_in_random_colour(
    i = ''
  )
  e return_this_text_in_random_colour(i)
end

.write_this_via_kde_colour_palette(this_text = '', this_colour = 'Pimpinella', append_newline = true) ⇒ Object

#

Colours.write_this_via_kde_colour_palette

To invoke this method, try:

Colours.write_this_via_kde_colour_palette 'Hello world!'
Colours.write_this_via_kde_colour_palette 'Hello world!', :random
Colours.write_this_via_kde_colour_palette 'Hello world!', :plasma_blue
#

112
113
114
115
116
117
118
119
120
121
122
# File 'lib/colours/kde_colour_palette/kde_colour_palette.rb', line 112

def self.write_this_via_kde_colour_palette(
    this_text      = '',
    this_colour    = 'Pimpinella',
    append_newline = true
  )
  result = Colours.return_this_via_kde_colour_palette(this_text, this_colour)
  if append_newline
    result << "#{N}"
  end
  print result
end

Instance Method Details

#available_html_colours?Boolean Also known as: html_colours?, html_colours, all_html_colours, return_all_html_colours, colours?, colours, registered_colours?

#

available_html_colours?

#

Returns:

  • (Boolean)

151
152
153
# File 'lib/colours/html_colours/misc.rb', line 151

def available_html_colours?
   Colours.available_html_colours?
end

#build_this_rgb_stringObject

#

rgb_value_as_escape_code_string

#

build_this_rgb_string


306
307
308
309
310
311
312
313
314
315
# File 'lib/colours/rgb/rgb.rb', line 306

def rgb_value_as_escape_code_string(
    array = [
      random_value?,
      random_value?,
      random_value?
    ],
    g = nil,
    b = nil
  )
end

#cif(i) ⇒ Object Also known as: ff

#

cif

This is efancy, but we won't use newlines.

#

76
77
78
# File 'lib/colours/colour_methods/sfancy.rb', line 76

def cif(i)
  efancy(i, false)
end

#ciif(i) ⇒ Object

#

ciif

#

63
64
65
# File 'lib/colours/colour_methods/simportant.rb', line 63

def ciif(i)
  eimportant(i, false)
end

#colour_to_rgb_valueObject

#

rgb_value_as_escape_code_string

#

colour_to_rgb_value


311
312
313
314
315
316
317
318
319
320
# File 'lib/colours/rgb/rgb.rb', line 311

def rgb_value_as_escape_code_string(
    array = [
      random_value?,
      random_value?,
      random_value?
    ],
    g = nil,
    b = nil
  )
end

#convert_this_rgb_value_to_that_hexadecimal_representation(r, g = nil, b = nil) ⇒ Object

#

convert_this_rgb_value_to_that_hexadecimal_representation

#

316
317
318
319
320
# File 'lib/colours/rgb/rgb.rb', line 316

def convert_this_rgb_value_to_that_hexadecimal_representation(
    r, g = nil, b = nil
  )
  Colours.convert_this_rgb_value_to_that_hexadecimal_representation(r, g, b)
end

#default_colour(i = '') ⇒ Object

#

default_colour

#

58
59
60
# File 'lib/colours/colour_methods/default_colour.rb', line 58

def default_colour(i = '')
  Colours.default_colour(i)
end

#eargument(i = '', make_newline = false) ⇒ Object

#

eargument

The various simple colourize methods.

#

59
60
61
62
63
64
# File 'lib/colours/colour_methods/sargument.rb', line 59

def eargument(
    i            = '',
    make_newline = false
  )
  e Colours.sargument(i, make_newline)
end

#ecomment(i, optional_split_at_this_character = '#') ⇒ Object

#

ecomment

Just a wrapper over the Colours.ecomment() functionality.

#

93
94
95
96
97
98
# File 'lib/colours/colour_methods/scomments.rb', line 93

def ecomment(
    i,
    optional_split_at_this_character = '#'
  )
  Colours.ecomment(i, optional_split_at_this_character)
end

#edefault_colour(i = '', make_newline = false) ⇒ Object

#

edir

#

48
49
50
51
52
53
# File 'lib/colours/colour_methods/default_colour.rb', line 48

def edefault_colour(
    i            = '',
    make_newline = false
  )
  e Colours.default_colour(i, make_newline)
end

#edir(i = '', make_newline = false) ⇒ Object

#

edir

#

48
49
50
51
52
53
# File 'lib/colours/colour_methods/sdir.rb', line 48

def edir(
    i            = '',
    make_newline = false
  )
  e Colours.sdir(i, make_newline)
end

#ef(i) ⇒ Object

#

ef

#

15
16
17
# File 'lib/colours/toplevel_methods/e.rb', line 15

def ef(i)
  e(i, false) # The variant without newlines.
end

#efancy(i = '', make_newline = false) ⇒ Object Also known as: f

#

efancy

#

57
58
59
60
61
62
# File 'lib/colours/colour_methods/sfancy.rb', line 57

def efancy(
    i            = '',
    make_newline = false
  )
  Colours.efancy(i, make_newline)
end

#efile(i = '', make_newline = false) ⇒ Object

#

efile

#

60
61
62
63
64
65
# File 'lib/colours/colour_methods/sfile.rb', line 60

def efile(
    i            = '',
    make_newline = false
  )
  e sfile(i, make_newline)
end

#eimportant(i = '', make_newline = false) ⇒ Object Also known as: eimp, cii

#

eimportant

#

80
81
82
83
84
85
# File 'lib/colours/colour_methods/simportant.rb', line 80

def eimportant(
    i            = '',
    make_newline = false
  )
  Colours.eimp(i, make_newline)
end

#enormal(i = '', make_newline = false) ⇒ Object

#

enormal

#

55
56
57
58
59
60
# File 'lib/colours/colour_methods/snormal.rb', line 55

def enormal(
    i            = '',
    make_newline = false
  )
  e snormal(i, make_newline)
end

#eparse(i = '') ⇒ Object

#

eparse (eparse tag)

Input could be like this:

eparse 'Foo: bla'
eparse 'Foo: '+bla
#

69
70
71
# File 'lib/colours/eparse/eparse.rb', line 69

def eparse(i = '')
  Colours.eparse(i)
end
#
#

91
92
93
94
95
96
# File 'lib/colours/colour_methods/ssymlink.rb', line 91

def esymlink(
    i            = '',
    make_newline = false
  )
  Colours.esymlink(i, make_newline)
end

#ewarn(i = '', make_newline = false) ⇒ Object

#

ewarn

#

65
66
67
68
69
70
# File 'lib/colours/colour_methods/swarn.rb', line 65

def ewarn(
    i            = '',
    make_newline = false
  )
  Colours.ewarn(i, make_newline)
end

#is_this_a_256_colour?(i) ⇒ Boolean

#

is_this_a_256_colour?

#

Returns:

  • (Boolean)

181
182
183
# File 'lib/colours/256_colours/support_for_256_colours.rb', line 181

def is_this_a_256_colour?(i)
  ::Colours.is_this_a_256_colour?(i)
end

#italic(i = '', make_newline = false) ⇒ Object

#

italic

#

77
78
79
80
81
82
# File 'lib/colours/toplevel_methods/italic.rb', line 77

def italic(
    i            = '',
    make_newline = false
  )
  ::Colours.italic(i, make_newline)
end

#last_colour_used?Boolean

#

last_colour_used?

Tell us which colour was used last.

#

Returns:

  • (Boolean)

21
22
23
# File 'lib/colours/toplevel_methods/set_last_colour_used.rb', line 21

def last_colour_used?
  @last_colour_used.to_s # Always required a string.
end

#left?Boolean

#

left?

#

Returns:

  • (Boolean)

55
56
57
# File 'lib/colours/constants/misc.rb', line 55

def left?
  Colours.left?
end

#main_coloursObject

#

main_colours

This will return an Array with the symbols such as :black, :red etc..

#

71
72
73
# File 'lib/colours/constants/hash_simple_colours.rb', line 71

def main_colours
  ::Colours.available_main_colours?
end

#map_symbol_to_corresponding_colour(i) ⇒ Object Also known as: map_colour_to_constant

#

map_symbol_to_corresponding_colour

This maps a colour (string) to the respective constant.

#

215
216
217
# File 'lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb', line 215

def map_symbol_to_corresponding_colour(i)
  ::Colours.map_symbol_to_corresponding_colour(i)
end
#

menu (menu tag)

#

107
108
109
# File 'lib/colours/commandline/menu.rb', line 107

def menu(i = nil)
  Colours.menu(i) # Delegate towards the class method above here.
end

#open_this_file(shall_we_exit = false) ⇒ Object

#

self.open_this_file

#

14
15
16
17
18
19
20
21
22
23
24
# File 'lib/colours/toplevel_methods/open_this_file.rb', line 14

def open_this_file(
    shall_we_exit = false
  )
  case shall_we_exit
  when :then_exit
    shall_we_exit = true
  end
  _ = "bluefish #{__FILE__}"
  esystem(_)
  exit if shall_we_exit
end

#random_colour?Boolean Also known as: random_colour, random, sample, random_html_colour, return_random_html_colour

#

random_colour?

#

Returns:

  • (Boolean)

36
37
38
# File 'lib/colours/toplevel_methods/random_html_colour.rb', line 36

def random_colour?
  ::Colours::HtmlColours.random_colour?
end

#random_value?Boolean Also known as: rvalue, random_value, r?, g?, b?

#

random_value

We will obtain a random value between 0 and 255, hence why we will use rand(256).

#

Returns:

  • (Boolean)

29
30
31
# File 'lib/colours/toplevel_methods/random_value.rb', line 29

def random_value?
  Colours.random_value?
end

#restore?Boolean Also known as: revert, rev?

#

restore?

This will restore to the default again.

#

Returns:

  • (Boolean)

101
102
103
# File 'lib/colours/revert/revert.rb', line 101

def restore?
  Colours.restore?
end

#return_random_rgbObject Also known as: return_rgb_as_array

#

return_random_rgb

#

290
291
292
# File 'lib/colours/rgb/rgb.rb', line 290

def return_random_rgb
  Colours.return_random_rgb
end

#rev(i = '') ⇒ Object

#

rev

Use this method to “revert” to the old default colour again, by delegating towards the Colours.rev() method defined above.

From this point on, we use methods that can be toggled.

#

91
92
93
# File 'lib/colours/revert/revert.rb', line 91

def rev(i = '')
  ::Colours.rev # This will refer to the Colours.rev() module method.
end

#rgbObject

#

rgb_value_as_escape_code_string

#

rgb


308
309
310
311
312
313
314
315
316
317
# File 'lib/colours/rgb/rgb.rb', line 308

def rgb_value_as_escape_code_string(
    array = [
      random_value?,
      random_value?,
      random_value?
    ],
    g = nil,
    b = nil
  )
end

#rgb_as_stringObject