Module: Colours

Includes:
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/colours.rb,
lib/colours/colour/colour.rb,
lib/colours/eparse/eparse.rb,
lib/colours/project/project.rb,
lib/colours/testing/testing.rb,
lib/colours/version/version.rb,
lib/colours/toplevel_methods/e.rb,
lib/colours/constants/constants.rb,
lib/colours/toplevel_methods/rev.rb,
lib/colours/essentials/essentials.rb,
lib/colours/commandline/commandline.rb,
lib/colours/rainbow_colours/rainbow.rb,
lib/colours/rainbow_colours/set_mode.rb,
lib/colours/html_colours/html_colours.rb,
lib/colours/rainbow_colours/constants.rb,
lib/colours/rainbow_colours/println_ani.rb,
lib/colours/rainbow_colours/println_plain.rb,
lib/colours/rainbow_colours/report_errors.rb,
lib/colours/html_colours/hash_html_colours.rb,
lib/colours/rainbow_colours/returnln_plain.rb,
lib/colours/html_colours/random_html_colour.rb,
lib/colours/autogenerated/256_colours_methods.rb,
lib/colours/toplevel_methods/toplevel_methods.rb,
lib/colours/autogenerated/html_colours_methods.rb,
lib/colours/rainbow_colours/print_rainbow_line.rb,
lib/colours/rainbow_colours/paint_detected_mode.rb,
lib/colours/kde_colour_palette/kde_colour_palette.rb,
lib/colours/module_256_colours/module_256_colours.rb,
lib/colours/autogenerated/256_colours_instance_methods.rb,
lib/colours/autogenerated/html_colours_instance_methods.rb,
lib/colours/rainbow_colours/do_parse_via_rainbow_colours.rb,
lib/colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb,
lib/colours/rainbow_colours/check_for_trollop_being_available_or_exit.rb,
lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb,
lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb,
lib/colours/html_colours/push_the_html_colours_methods_onto_the_toplevel_namespace.rb,
lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb

Overview

#

require ‘colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb’

#

Defined Under Namespace

Modules: E, Essentials, HtmlColours, HtmlColoursMethods, Module256Colours, RainbowColours Classes: Base, Colour, Colours, Commandline, Eparse, RGB, ReplaceTokensWithColourCode

Constant Summary collapse

PROJECT_BASE_DIRECTORY =
#

Colours::PROJECT_BASE_DIRECTORY

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

VERSION

#
'0.9.8'
LAST_UPDATE =
#

LAST_UPDATE

#
'04.12.2023'
URL_TO_THE_DOCUMENTATION =
#

URL_TO_THE_DOCUMENTATION

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

Colours::N

#
"\n"
USE_THIS_COLOUR_FOR_THE_DEFAULT_COLOUR =
#

Colours::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
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"
HASH_ANSI_COLOURS =
#

Colours::HASH_ANSI_COLOURS

#
{
  black:             '30',
  red:               '31',
  green:             '32',
  brown:             '33', # This is also known as yellow.
  yellow:            '33',
  blue:              '34',
  purple:            '35', # Also known as magenta.
  magenta:           '35',
  light_magenta:     '35',
  cyan:              '36',
  light_gray:        '37',
  grey:              '37',
  white:             '37',
  light_red:         '41',
  background_black:  '40',
  background_red:    '41',
  background_green:  '42',
  background_brown:  '43',
  background_yellow: '43',
  background_blue:   '44',
  light_blue:        '44', # Alias to the above ^^^.
  background_purple: '45',
  background_cyan:   '46',
  background_white:  '47'
}
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
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]+?)>/
GENERIC_RUBY_HEADER =
#

GENERIC_RUBY_HEADER

#
'#!/usr/bin/ruby -w
# Encoding: UTF-8
# frozen_string_literal: true
# =========================================================================== #'
RUBY_HEADER =

RUBY_HEADER

GENERIC_RUBY_HEADER
UNDERLINE_CODE =
#

UNDERLINE_CODE

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

echo -e "\e[4mone two three\e[23m"
#
'4'
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 and this is not in italic"
#
'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"
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 =
#

Colours::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
)
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
REDRAW_THE_PROMPT =
#

Colours::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"
HOME_DIRECTORY_OF_USER_X =
#

Colours::HOME_DIRECTORY_OF_USER_X

This constant is only useful on my home system.

#
'/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}programming/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
COLOUR_BLACK =
#

COLOUR_BLACK

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

COLOUR_GRAY

COLOUR_BLACK
BLACK =

BLACK

COLOUR_BLACK
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_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_GRAY =
#

COLOUR_LIGHT_GRAY

This is also known as white.

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

WHITE

COLOUR_LIGHT_GRAY
COLOUR_LIGHT_GREY =

COLOUR_LIGHT_GREY

COLOUR_LIGHT_GRAY
COLOUR_WHITE =
#

COLOUR_WHITE

This is bold white, actually.

#
"#{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
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

This is also known as “bold 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
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 =
#

Colours::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
ARRAY_REGISTERED_ANSI_COLOURS =
#

ARRAY_REGISTERED_ANSI_COLOURS

This array exists mostly for testing-purposes.

#
[

  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

]
KDE_COLOUR_PALETTE =
{}
HASH_NEW_COLOURS =
#

Colours::HASH_NEW_COLOURS

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

Since as of the year 2018, this Hash is rarely used anymore, though.

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

Colourss.set_method_to_colour_table(:new_colours)
#
{
  default_colour: :green,        
  # sargument:    :bold_brown,       # === sarg()      # removed in November 2023.
  # scomments:    :bold_blue,        # === scomments() # removed in November 2023.
  sdir:           :thistle,          # === sdir()
  sfancy:         :rosybrown,        # === sfancy()
  sfile:          :brown,            # === sfile()
  simportant:     :pink,             # === simportant()
  ssymlink:       :teal,             # === ssymlink()
  swarn:          :olivedrab,        # === swarn
  snormal:        :mediumaquamarine, # === snormal()
  scomments:      :grey,             # === scomments()
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autogenerate_256_colours_methodsObject

#

Colours.autogenerate_256_colours_methods

#


440
441
442
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 440

def self.autogenerate_256_colours_methods
  Colours::Module256Colours.autogenerate_256_colours_methods
end

.autogenerate_html_colours_methodsObject

#

Colours.autogenerate_html_colours_methods

#


358
359
360
# File 'lib/colours/html_colours/html_colours.rb', line 358

def self.autogenerate_html_colours_methods
  ::Colours::HtmlColours.autogenerate_html_colours_methods
end

.available_file_constantsObject

#

Colours.available_file_constants

#


251
252
253
254
255
256
257
# File 'lib/colours/constants/constants.rb', line 251

def self.available_file_constants
  [
    FILE_HTML_COLOURS,       # colours/yaml/html_colours.yml
    FILE_KDE_COLOUR_PALETTE, # colours/yaml/kde_colour_palette.yml
    FILE_256_COLOURS         # colours/yaml/256_colours.yml
  ]
end

.available_html_colours?Boolean

#

Colours.available_html_colours?

#

Returns:

  • (Boolean)


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

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)


355
356
357
# File 'lib/colours/constants/constants.rb', line 355

def self.available_main_colours?
  MAIN_COLOURS
end

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

#

Colours.bold

ANSI colour escape code for bold is “1”.

The method has to call Colours.rev() at the end, because that way downstream users can modify the default rev-colour in use.

Usage example:

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


719
720
721
722
723
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 719

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

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

#

Colours.bold_and_italic

Usage example:

puts Colours.bold_and_italic 'Hello world!'
#


752
753
754
755
756
757
758
759
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 752

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().

#


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/colours/rainbow_colours/rainbow.rb', line 47

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.

#


740
741
742
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 740

def self.clear_screen
  system 'clear'
end

.cliner(i = 78, &block) ⇒ Object

#

Colours.cliner

#


685
686
687
688
689
690
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 685

def self.cliner(
    i = 78, &block
  )
  yield if block_given?
  e '=' * 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 '/home/x/songs/'
Colours.col '/home/x/songs/Westbam_Sunshine.mp3'
#


694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 694

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.

#


315
316
317
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 315

def self.colour_for_symlinks
  return @colour_table[:ssymlink].to_sym
end

.colour_method_or_display_the_content_of_the_file_or_use_via_pipe(i = ARGF, name_of_the_colour = $PROGRAM_NAME) ⇒ Object

#

Colours.colour_method_or_display_the_content_of_the_file_or_use_via_pipe

This method has an awful name, but its core use case is simple.

It will handle commandline instructions such as:

orange Hey there
slateblue how are you doing?

Usage example from within ruby:

Colours.testing123('abc', :orange)
#


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/toplevel_methods/toplevel_methods.rb', line 490

def self.colour_method_or_display_the_content_of_the_file_or_use_via_pipe(
    i                  = ARGF,
    name_of_the_colour = $PROGRAM_NAME
  )
  require 'colours/autogenerated/html_colours_methods.rb'
  # ======================================================================= #
  # === :read
  # ======================================================================= #
  if i.respond_to? :read
    i = i.read
  elsif i and File.exist?(i)
    i = File.read(i)
  end
  i = Colours.remove_trailing_end_from(i)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  if name_of_the_colour
    if name_of_the_colour.respond_to?(:include?) and
       name_of_the_colour.include?('/')
      name_of_the_colour = File.basename(name_of_the_colour)
    end
  end
  name_of_the_colour = name_of_the_colour.to_sym
  return ::Colours::HtmlColoursMethods.send(name_of_the_colour, i)
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)


218
219
220
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 218

def self.colour_table?
  @colour_table
end

.colour_to_rgb(i = :slateblue) ⇒ Object

#

Colours.colour_to_rgb

#


318
319
320
# File 'lib/colours/html_colours/html_colours.rb', line 318

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

.commandline_arguments?Boolean

#

Colours.commandline_arguments?

#

Returns:

  • (Boolean)


175
176
177
# File 'lib/colours/commandline/commandline.rb', line 175

def self.commandline_arguments?
  @commandline_arguments
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]
#


618
619
620
621
622
623
624
625
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 618

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]
#


647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 647

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
#


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/colours/rgb/rgb.rb', line 277

def self.convert_this_html_colour_into_an_array_of_rgb_values(
    html_colour = :random
  )
  require 'colours/html_colours/random_html_colour.rb'
  case html_colour
  # ========================================================================= #
  # === :random
  # ========================================================================= #
  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.

#


248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/colours/rgb/rgb.rb', line 248

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)
#


434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/colours/rgb/rgb.rb', line 434

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!')
#


294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 294

def self.default_colour(
    i            = '',
    make_newline = false
  )
  if use_colours?
    if make_newline
      i = "#{i}#{N}"
    end
    if @use_html_colours
      replacement_colour = @colour_table[__method__.to_sym].to_sym
      return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
    end
  end
  return i
end

.disable_colours(be_verbose = false) ⇒ Object

#

Colours.disable_colours

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

#


199
200
201
202
203
204
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 199

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

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

#

Colours.display_this_256_colour

#


331
332
333
334
335
336
337
338
339
340
341
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 331

def self.display_this_256_colour(
    id            = 9,
    use_this_text = "Hello world!\n",
    &block
  )
  Colours::Module256Colours.display_this_256_colour(
    id,
    use_this_text,
    &block
  )
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)


134
135
136
137
# File 'lib/colours/html_colours/hash_html_colours.rb', line 134

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)


336
337
338
339
340
341
342
# File 'lib/colours/html_colours/html_colours.rb', line 336

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

.does_this_string_contain_a_special_token?(i, &block) ⇒ Boolean

#

Colours.does_this_string_contain_a_special_token?

#

Returns:

  • (Boolean)


347
348
349
350
# File 'lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb', line 347

def self.does_this_string_contain_a_special_token?(i, &block)
  _ = ::Colours::ReplaceTokensWithColourCode.new(i, :do_not_run_yet, &block)
  _.does_this_string_contain_a_special_token?(i)
end

.does_this_string_include_a_html_colour?(i) ⇒ Boolean

#

Colours.does_this_string_include_a_html_colour?

#

Returns:

  • (Boolean)


996
997
998
999
1000
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 996

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)


957
958
959
960
961
962
963
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 957

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"
#


22
23
24
25
26
27
28
29
30
31
# File 'lib/colours/toplevel_methods/e.rb', line 22

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 = '#', first_colour_to_use = :steelblue, second_colour_to_use = :seagreen, colour_to_use_for_the_token = :slategray) ⇒ Object

#

Colours.ecomment

This method 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. By default it will split on the token ‘#’.

#


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 358

def self.ecomment(
    i,
    optional_split_at_this_character = '#', # ← Specify which character to split at.
    first_colour_to_use         = :steelblue,
    second_colour_to_use        = :seagreen,
    colour_to_use_for_the_token = :slategray
  )
  _ = i.to_s
  if optional_split_at_this_character.is_a? Hash
    # ===================================================================== #
    # === :token
    # ===================================================================== #
    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
    _ = _.dup if _.frozen?
    splitted = _.split(optional_split_at_this_character)
    first_part  = ::Colours::HtmlColoursMethods.send(first_colour_to_use, splitted.first)
    middle_part = ::Colours::HtmlColoursMethods.send(colour_to_use_for_the_token, optional_split_at_this_character)
    second_part = ::Colours::HtmlColoursMethods.send(second_colour_to_use, splitted.last)
    _ = first_part+
        middle_part+
        second_part+
        ::Colours.rev
  end
  e _
end

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

#

Colours.efancy

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

#


575
576
577
578
579
580
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 575

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

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

#

Colours.eimp

#


543
544
545
546
547
548
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 543

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>.

#


972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 972

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.

#


263
264
265
266
267
268
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 263

def self.enable_colours(
    be_verbose = false
  )
  puts 'Enabling colours next.' if be_verbose
  @use_colours = true # Defined below.
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.

#


94
95
96
# File 'lib/colours/eparse/eparse.rb', line 94

def self.eparse(i = '')
  ::Colours.e(rparse(i)) # Defined in this file here.
end
#
#


465
466
467
468
469
470
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 465

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

.esystem(i) ⇒ Object

#

Colours.esystem

#


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

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

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

#

Colours.ewarn

#


485
486
487
488
489
490
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 485

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:

alias e puts
e Colours.fancy_parse '<i><red>E. coli</red></i>'
e Colours.fancy_parse '<i><lightgreen>E. coli</lightgreen></i>'
e Colours.fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
e Colours.fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
e Colours.fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
e Colours.fancy_parse "<tomato><b>Hello world.</b></tomato>"
e Colours.fancy_parse "<tomato>Hello world.</tomato>"
e Colours.fancy_parse '<i>hey</i> <teal>there</teal>'
e Colours.fancy_parse '<i>hey</i> <teal>there</teal> ok'
e Colours.fancy_parse "<lightgreen><i>hey</i></lightgreen> <teal>there</teal>"
e Colours.fancy_parse "<tomato>hey</tomato> <teal>there</teal>"
e Colours.fancy_parse "<tomato><i>hey</i></tomato> <teal>there</teal>"
e Colours.fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal>"
e Colours.fancy_parse "<tomato><b><i>hey</i></b></tomato> <teal>there</teal> <b>how do you do</b>"
e Colours.fancy_parse "<tomato><b>Hello world.</b></tomato>"
#


400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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
445
446
# File 'lib/colours/class/colours.rb', line 400

def self.fancy_parse(
    i               = '',
    use_this_colour = :default_colour
  )
  if i.is_a? Array
    i = i.join # We do not want an Array past this point.
  end
  # ========================================================================= #
  # === Handle italic tags, aka <i>
  #
  # The old code was:
  #
  #  i.gsub!(use_this_regex, return_italic('\1'))
  #
  # Up until November 2022, then it was changed.
  # ========================================================================= #
  if i.include?('<i>') and i.include?('</i>')
    # ======================================================================= #
    # The following regex is defined at:
    #
    #   https://rubular.com/r/k5tE9xBzky8muR
    #
    # ======================================================================= #
    use_this_regex = /<i>([<>\/\.A-Za-zöäüÖÄÜ\s-]*?)<\/i>/
    i = i.dup if i.frozen?
    i.gsub!(
      use_this_regex,
      ::Colours::Colours.new('\1').italic.to_s+ # or return_italic('\1')
      ::Colours.rev
    )
  end
  # ========================================================================= #
  # === Handle bold tags, aka <b>
  # ========================================================================= #
  if i.include?('<b>') and i.include?('</b>')
    use_this_regex = /<b>(.+)<\/b>/
    i.gsub!(
      use_this_regex,
      ::Colours::Colours.new('\1').bold.to_s # or 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_256_coloursObject

#

Colours.file_256_colours

This method will return the path to the .yml file containing the data for the 256-colours variant.

#


709
710
711
# File 'lib/colours/constants/constants.rb', line 709

def self.file_256_colours
  FILE_256_COLOURS
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)


243
244
245
# File 'lib/colours/constants/constants.rb', line 243

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"

This can also be generated from the commandline, thanks to the bin/colours executable, via:

colours --generate_shell_file_containing_the_html_colours
#


538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 538

def self.generate_shell_file_containing_the_html_colours(
    generate_the_shell_file_into_this_directory = Dir.pwd
  )
  require 'colours/html_colours/random_html_colour.rb'
  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"
  available_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/programming/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?

Query-method to return the Hash containing all HTML colours, including their respective RGB values.

#

Returns:

  • (Boolean)


120
121
122
# File 'lib/colours/html_colours/hash_html_colours.rb', line 120

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

.html_colour_to_hex_value(this_html_colour = nil, return_with_hash_key = true) ⇒ Object

#

Colours.html_colour_to_hex_value

This method will return a String, such as “FFFF00”.

Usage example:

Colours.html_colour_to_hex_value('yellow') # => "#FFFF00"
#


771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 771

def self.html_colour_to_hex_value(
    this_html_colour     = nil,
    return_with_hash_key = true
  )
  if this_html_colour.is_a? Array
    this_html_colour = this_html_colour.first
  end
  # ======================================================================= #
  # Obtain the path to the file that keeps the html-colours. On my home
  # system this may be a path like this:
  #
  #   /usr/lib/ruby/site_ruby/3.2.0/colours/yaml/html_colours.yml
  #
  # ======================================================================= #
  _ = file_html_colours_to_rgb?
  if File.exist? _
    # ===================================================================== #
    # Load the yaml-file next:
    # ===================================================================== #
    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"
#


484
485
486
487
488
489
# File 'lib/colours/rgb/rgb.rb', line 484

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
#


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
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 228

def self.html_colourize(
    colour_to_use = return_random_html_colour,
    this_text     = nil,
    append_revert = true,
    &block
  )
  require 'colours/html_colours/html_colours.rb'
  require 'colours/rgb/rgb.rb'
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :omit_end
    # ===================================================================== #
    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)


438
439
440
# File 'lib/colours/constants/constants.rb', line 438

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

.is_on_roebe?Boolean

#

Colours.is_on_roebe?

#

Returns:

  • (Boolean)


574
575
576
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 574

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

.is_this_a_256_colour?(i, dataset = ::Colours::Module256Colours.dataset?) ⇒ Boolean

#

Colours.is_this_a_256_colour?

Invocation example:

Colours.is_this_a_256_colour? 'LightSteelBlue3'
#

Returns:

  • (Boolean)


351
352
353
354
355
356
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 351

def self.is_this_a_256_colour?(
    i,
    dataset = ::Colours::Module256Colours.dataset?
  )
  ::Colours::Module256Colours.is_this_a_256_colour?(i, dataset)
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!')
#


893
894
895
896
897
898
899
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 893

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

.left?Boolean

#

Colours.left?

#

Returns:

  • (Boolean)


492
493
494
# File 'lib/colours/constants/constants.rb', line 492

def self.left?
  LEFT
end

.make_colour(what_colour_to_use) ⇒ Object

#

Colours.make_colour

This is used primarily for testing.

#


182
183
184
185
186
187
188
189
190
191
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 182

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)
Colours.beautiful(:brown)
#


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
201
# File 'lib/colours/map_symbol_to_corresponding_colour/map_symbol_to_corresponding_colour.rb', line 43

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
  # ======================================================================= #
  # === :bright_cyan
  # ======================================================================= #
  when :bright_cyan,
       :cyanb,
       :cyan
    return BOLD_CYAN
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       :si,
       :default_colour,
       :defaultcolour,
       :normal,
       nil
    return DEFAULT_COLOUR
  # ======================================================================= #
  # === :light_grey
  # ======================================================================= #
  when :light_grey,
       :grey
    return COLOUR_LIGHT_GREY
  # ======================================================================= #
  # === :bold_green
  # ======================================================================= #
  when :bold_green,
       :boldgreen,
       :bright_green,
       :greenb,
       :lightgreen
    return BOLD_GREEN # => "\e[1;32m"
  # ======================================================================= #
  # === :bold_brown
  # ======================================================================= #
  when :bold_brown,
       :bbrown,
       :gold,
       :saddlebrown
    return BOLD_BROWN
  # ======================================================================= #
  # === :white
  # ======================================================================= #
  when :white,
       :whitebonblack
    return WHITE
  # ======================================================================= #
  # === :red
  # ======================================================================= #
  when :red
    return RED
  # ======================================================================= #
  # === :pink
  # ======================================================================= #
  when :pink,
       :bright_magenta
    return BRIGHT_MAGENTA
  # ======================================================================= #
  # === :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 the module Module256Colours.

#


373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 373

def self.map_this_symbol_to_that_256_colour(i)
  case i
  # ========================================================================= #
  # === :boldgreen
  # ========================================================================= #
  when :boldgreen,
       :bold_green
    :chartreuse2
  # ========================================================================= #
  # === :teal
  # ========================================================================= #
  when :teal
    :teal
  # ========================================================================= #
  # === :bold_yellow
  # ========================================================================= #
  when :bold_yellow
    :yellow2
  # ========================================================================= #
  # === :gold
  # ========================================================================= #
  when :gold
    :gold3
  # ========================================================================= #
  # === :bold_blue
  # ========================================================================= #
  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
    e "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.

#


15
16
17
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
# File 'lib/colours/toplevel_methods/map_this_symbol_to_that_html_colour.rb', line 15

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

Colours.menu (menu tag)

To invoke this method, try:

colours --show_html_colours
colours file?
#


189
190
191
192
193
194
# File 'lib/colours/commandline/commandline.rb', line 189

def self.menu(
    i = ARGV
  )
  _ = ::Colours::Commandline.new(i, :do_not_run_yet)
  _.menu(i) # Directly pass it into the menu-method here.
end

.new(i = ARGV) ⇒ Object

#

Colours.new

Easier toplevel-instantiation.

#


453
454
455
# File 'lib/colours/class/colours.rb', line 453

def self.new(i = ARGV)
  ::Colours::Colours.new(i)
end

.prefer_which_colour_scheme?Boolean

#

Colours.prefer_which_colour_scheme?

#

Returns:

  • (Boolean)


42
43
44
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 42

def self.prefer_which_colour_scheme?
  @prefer_this_colour_schemata.first.to_sym
end

.project_base_dir?Boolean

#

Colours.project_base_dir?

This method should be used to query the project’s base directory.

#

Returns:

  • (Boolean)


20
21
22
# File 'lib/colours/project/project.rb', line 20

def self.project_base_dir?
  PROJECT_BASE_DIRECTORY
end

.push_the_html_colours_methods_onto_the_toplevel_namespaceObject

#

Colours.push_the_html_colours_methods_onto_the_toplevel_namespace

#


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/colours/html_colours/push_the_html_colours_methods_onto_the_toplevel_namespace.rb', line 17

def self.push_the_html_colours_methods_onto_the_toplevel_namespace
  require 'colours/autogenerated/html_colours_methods.rb'
  require 'colours/autogenerated/html_colours_instance_methods.rb'
  # ========================================================================= #
  # We have to put the ColourMethods into the toplevel namespace at once,
  # so that methods such as slateblue() are defined.
  # ========================================================================= #
  extend ::Colours::HtmlColoursMethods

  include ::Colours::HtmlColoursMethods

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"
#


45
46
47
# File 'lib/colours/html_colours/random_html_colour.rb', line 45

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'
#


349
350
351
352
353
# File 'lib/colours/rgb/rgb.rb', line 349

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)


858
859
860
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 858

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.

#


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/toplevel_methods/toplevel_methods.rb', line 120

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]
#


419
420
421
# File 'lib/colours/constants/constants.rb', line 419

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.

#


907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 907

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 = 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"
#


1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 1042

def self.remove_trailing_end_from(
    i,
    remove_this_escape_sequence = 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 = true) ⇒ 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 fairly pointless to invoke this 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)
#


395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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
445
446
447
448
449
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 395

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 = true
  )
  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::HtmlColoursMethods.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.uniq
  add_on_string = i.dup
  # ======================================================================= #
  # scanned_results may be an Array such as ['steelblue', 'tomato']
  # ======================================================================= #
  scanned_results.each {|this_colour|
    if is_this_a_valid_html_colour?(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::HtmlColoursMethods.send(this_colour.to_sym, "\\1") { :omit_end }
      part2 = ::Colours::HtmlColoursMethods.send(use_this_colour_for_the_default_colour) { :omit_end }
      add_on_string.gsub!(
        ::Colours.return_main_regex_to_use_for_obtaining_the_full_content(this_colour),
        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_html_like_tokens(i, optional_use_this_hash = nil, &block) ⇒ Object

#

Colours.replace_html_like_tokens

The second argument to this method allows the user to use another Hash for the replacement table.

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
#


369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/colours/replace_tokens_with_colour_code/replace_tokens_with_colour_code.rb', line 369

def self.replace_html_like_tokens(
    i,
    optional_use_this_hash = nil,
    &block
  )
  _ = ::Colours::ReplaceTokensWithColourCode.new(i, :do_not_run_yet, &block)
  if optional_use_this_hash
    _.set_use_this_hash(optional_use_this_hash)
  end
  _.run
  _.result?
end

.report_whether_colours_will_be_usedObject

#

Colours.report_whether_colours_will_be_used

#


345
346
347
348
349
350
351
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 345

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

.reset_the_lineObject

#

Colours.reset_the_line

This method will reset the current line. This can then be used in a progress indicator application.

#


1026
1027
1028
1029
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 1026

def self.reset_the_line
  STDOUT.write("\u001b[1000D") # Move to the left by 1000 characters. Aka reset.
  STDOUT.flush # This line will force the output to appear immediately, 
end

.return_a_unique_array_containing_all_available_coloursObject

#

Colours.return_a_unique_array_containing_all_available_colours

#


695
696
697
698
699
700
701
702
703
704
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 695

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!')
#


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 154

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_main_regex_to_use_for_obtaining_the_full_content(this_colour) ⇒ Object

#

Colours.return_main_regex_to_use_for_obtaining_the_full_content

The first regex that is commented out, in the body of this method, was in use until May 2023. It was then replaced with the new regex, which also has an associated test-case, in the test/ subdirectory of the colours gem.

For the current regex see here:

https://rubular.com/r/1dpSmYqQ9SVvMt

I was also using a second regex that was slightly incompatible. For legacy reasons it can be seen here: rubular.com/r/sDNQd81MtciMJL

#


314
315
316
317
318
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 314

def self.return_main_regex_to_use_for_obtaining_the_full_content(this_colour)
  # /<#{this_colour}>([\-\{\}\[\]\\\(\)\/a-zA-Z0-9’éúÄäÖöÜüÅαβß&%+−=≡πμ°₁₂₃₄₅₆₇₈₉⁰¹²³⁴⁵⁶⁷⁸⁹⁻!#\*~:;∨"',_\|\n\. ]+)<\/#{this_colour}>/
  # /<#{this_numbered_word}>([-#~≥!\e=><;,→⁻⁺@^„“γαµ_₀₁₂₃₄₅₆₇₈₉²³⁴⁵⁶⁷⁸⁹äöüÄÖÜβß%&:≡°$A-Za-z0-9\n \?\\'\|\(\)\{\}\[\]\"\*\.\+]+)<\/#{this_numbered_word}>/
  /<#{this_colour}>([\n₀₁₂₃₄₅₆₇₈₉⁰¹²³⁴⁵⁶⁷⁸⁹°→⁻⁺≥$@σπµμγ∨^αβßÅÄäéúÖöÜüa-zA-Z0-9’'"„“~#&%!,;:_+−=≡<>\*\\\/\.\{\}\(\)\|\[\]\?\- ]*?)<\/#{this_colour}>/
end

.return_random_rgbObject

#

Colours.return_random_rgb

#


299
300
301
# File 'lib/colours/rgb/rgb.rb', line 299

def self.return_random_rgb
  [random_value?, random_value?, random_value?]
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!')
#


401
402
403
404
405
406
# File 'lib/colours/rgb/rgb.rb', line 401

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
#


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
# File 'lib/colours/kde_colour_palette/kde_colour_palette.rb', line 75

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.

#


823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 823

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[#{UNDERLINE_CODE}m".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
  return 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.

#


41
42
43
44
# File 'lib/colours/toplevel_methods/rev.rb', line 41

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!'
#


368
369
370
371
372
373
# File 'lib/colours/rgb/rgb.rb', line 368

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!'
#


386
387
388
389
390
391
# File 'lib/colours/rgb/rgb.rb', line 386

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

#


499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/colours/rgb/rgb.rb', line 499

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
      e '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.

#


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
# File 'lib/colours/eparse/eparse.rb', line 54

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  = ::Colours::Eparse::FIRST_COLOUR
  second_colour = ::Colours::Eparse::SECOND_COLOUR
  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.

#


666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 666

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

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

#

Colours.scomments

Invocation example:

Colours.scomments('Hello world!')
#


400
401
402
403
404
405
406
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 400

def self.scomments(
    i            = '',
    make_newline = false
  )
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
end

.scomments?Boolean

#

Colours.scomments?

This method will usually return :grey.

#

Returns:

  • (Boolean)


413
414
415
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 413

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

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

#

Colours.sdir

#


611
612
613
614
615
616
617
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 611

def self.sdir(
    i            = '',
    make_newline = false
  )
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  return ::Colours::HtmlColoursMethods.send(replacement_colour, 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.

#


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/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 146

def self.set_colour_table(
    i = :new_colours
  )
  case i
  # ======================================================================= #
  # === :new_colours
  # ======================================================================= #
  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_arguments(i = ARGV) ⇒ Object

#

Colours.set_commandline_arguments

#


168
169
170
# File 'lib/colours/commandline/commandline.rb', line 168

def self.set_commandline_arguments(i = ARGV)
  @commandline_arguments = [i].flatten.compact
end

.set_last_colour_used(i) ⇒ Object

#

Colours.set_last_colour_used

#


95
96
97
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 95

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

.set_revert(i = :default) ⇒ Object

#

Colours.set_revert

#


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

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

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

#

Colours.sfancy

Invocation example:

Colours.sfancy('Hello world!')
#


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 96

def self.sfancy(
    i            = '',
    make_newline = false
  )
  # ======================================================================= #
  # Fetch the appropriate replacement-colour next:
  # ======================================================================= #
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  unless ::Colours::HtmlColoursMethods.respond_to?(replacement_colour.to_sym)
    replacement_colour = ::Colours.map_this_symbol_to_that_html_colour(replacement_colour.to_sym)
  end
  return ::Colours::HtmlColoursMethods.send(replacement_colour, 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!')
#


198
199
200
201
202
203
204
205
206
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 198

def self.sfile(
    i            = '',
    make_newline = false
  )
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  if ::Colours.const_defined?(:HtmlColoursMethods)
    return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
  end
end

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

#

Colours.sfile_or_sdir

This method will directly delegate to either Colours.sfile() or Colours.sdir(), depending on whether we have a file at hand or whether we have a directory at hand.

Usage examples:

Colours.sfile_or_sdir('/home/x/Temp/MyGems/')
Colours.sfile_or_sdir('/home/x/Temp/opened_files.yml')
#


662
663
664
665
666
667
668
669
670
671
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 662

def self.sfile_or_sdir(
    i            = '',
    make_newline = false
  )
  if File.exist?(i) and File.file?(i)
    return ::Colours.sfile(i, make_newline)
  elsif File.directory?(i)
    return ::Colours.sdir(i, make_newline)
  end
end

.show_256_colour_cubeObject

#

Colours.show_256_colour_cube

#


324
325
326
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 324

def self.show_256_colour_cube
  ::Colours::Module256Colours.show_256_colour_cube
end

.show_all_256_colours(&block) ⇒ Object

#

Colours.show_all_256_colours

#


361
362
363
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 361

def self.show_all_256_colours(&block)
  ::Colours::Module256Colours.show_all_256_colours(&block)
end

.show_basic_colour_paletteObject

#

Colours.show_basic_colour_palette

This will show a colour palette on the commandline.

#


1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 1007

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)

#


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 273

def self.show_help
  e
  e 'The commandline-interface for the Colours project supports '\
    'the following documented instructions:'
  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 '  --version?          # report the current version of '\
         'the colours gem'
  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

#


301
302
303
# File 'lib/colours/html_colours/html_colours.rb', line 301

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.

#


239
240
241
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 239

def self.show_the_colour_table
  pp @colour_table
end

.show_the_versionObject

#

Colours.show_the_version

Invocation example:

colours --version?
#


328
329
330
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 328

def self.show_the_version
  e steelblue(VERSION)
end

.shuffleObject

#

Colours.shuffle

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

#


249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 249

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,
    ssymlink:  _.shift
  }
end

.simple_colours_testObject

#

Colours.simple_colours_test

This method purposely tests only the basic parts for colours-related output onto the terminal.

#


20
21
22
# File 'lib/colours/testing/testing.rb', line 20

def self.simple_colours_test
  show_basic_colour_palette
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')
#


513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 513

def self.simportant(
    i            = '',
    make_newline = false
  )
  require 'colours/essentials/essentials.rb'
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  _ = ::Colours::HtmlColoursMethods
  if _.respond_to? replacement_colour
    return _.send(replacement_colour, i)
  else
    ::Colours::Essentials.send(replacement_colour, i)
  end
end
#
#


277
278
279
280
281
282
283
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 277

def self.ssymlink(
    i            = '',
    make_newline = false
  )
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  return ::Colours::HtmlColoursMethods.send(replacement_colour, i)
end

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

#

Colours.swarn

Invocation example:

Colours.swarn('Hello world!')
#


444
445
446
447
448
449
450
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 444

def self.swarn(
    i            = '',
    make_newline = false
  )
  replacement_colour = @colour_table[__method__.to_sym].to_sym
  return ::Colours::HtmlColoursMethods.send(replacement_colour, 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
#


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
151
152
153
154
155
156
157
158
159
# File 'lib/colours/testing/testing.rb', line 37

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!')
#


467
468
469
470
471
472
473
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 467

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)

#


80
81
82
83
84
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 80

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=

This setter-method determines whether the colours gem will use colours or whether it will not.

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

#


362
363
364
365
366
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 362

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)


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

def self.use_colours?
  @use_colours
end

.use_new_colour_tableObject

#

Colours.use_new_colour_table

#


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

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.

#


429
430
431
432
433
434
435
# File 'lib/colours/module_256_colours/module_256_colours.rb', line 429

def self.write_this_in_256_colours(
    this_text = "Hello world!\n",
    id        = rand(256),
    &block
  )
  ::Colours::Module256Colours.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'
#


414
415
416
417
418
# File 'lib/colours/rgb/rgb.rb', line 414

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 any of the following:

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
#


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

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

#all_html_coloursBoolean

#

available_html_colours?

#

all_html_colours

Returns:

  • (Boolean)


292
293
294
# File 'lib/colours/html_colours/html_colours.rb', line 292

def available_html_colours?
  ::Colours.available_html_colours?
end

#all_html_colours?Boolean

#

available_html_colours?

#

all_html_colours?

Returns:

  • (Boolean)


289
290
291
# File 'lib/colours/html_colours/html_colours.rb', line 289

def available_html_colours?
  ::Colours.available_html_colours?
end

#available_html_colours?Boolean

#

available_html_colours?

#

Returns:

  • (Boolean)


287
288
289
# File 'lib/colours/html_colours/html_colours.rb', line 287

def available_html_colours?
  ::Colours.available_html_colours?
end

#build_this_rgb_stringObject

#

rgb_value_as_escape_code_string

#

build_this_rgb_string



322
323
324
325
326
327
328
329
330
331
# File 'lib/colours/rgb/rgb.rb', line 322

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.

#


604
605
606
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 604

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

#ciif(i) ⇒ Object

#

ciif

Alias to the above method, basically, aka eimportant().

#


566
567
568
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 566

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

#colour_to_rgb_valueObject

#

rgb_value_as_escape_code_string

#

colour_to_rgb_value



327
328
329
330
331
332
333
334
335
336
# File 'lib/colours/rgb/rgb.rb', line 327

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

#coloursBoolean

#

available_html_colours?

#

colours

Returns:

  • (Boolean)


295
296
297
# File 'lib/colours/html_colours/html_colours.rb', line 295

def available_html_colours?
  ::Colours.available_html_colours?
end

#colours?Boolean

#

available_html_colours?

#

colours?

Returns:

  • (Boolean)


294
295
296
# File 'lib/colours/html_colours/html_colours.rb', line 294

def available_html_colours?
  ::Colours.available_html_colours?
end

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

#

convert_this_rgb_value_to_that_hexadecimal_representation

#


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

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

#


335
336
337
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 335

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

#e(i = N, append_newline = true) ⇒ Object Also known as: ci

#

e (e tag)

This is just a wrapper towards the above method called Colours.e()

If the second argument ‘make_newline` is true then we will append a newline. This is the default behaviour.

This method just delegates to the module method Colours.e()

#


43
44
45
46
47
48
# File 'lib/colours/toplevel_methods/e.rb', line 43

def e(
    i              = N,
    append_newline = true
  ) # This is the main point of Colours.
  ::Colours.e(i, append_newline) # Point towards the class method of e().
end

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

#

ecomment

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

#


429
430
431
432
433
434
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 429

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

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

#

edefault_colour

#


342
343
344
345
346
347
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 342

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

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

#

edir

#


267
268
269
270
271
272
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 267

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

#ef(i) ⇒ Object

#

ef

#


53
54
55
# File 'lib/colours/toplevel_methods/e.rb', line 53

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

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

#

efancy

#


585
586
587
588
589
590
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 585

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

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

#

efile

#


642
643
644
645
646
647
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 642

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

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

#

eimportant

#


553
554
555
556
557
558
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 553

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

#eparse(i = '') ⇒ Object

#

eparse (eparse tag)

Input to this method could be like this:

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


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

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


475
476
477
478
479
480
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 475

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

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

#

ewarn

#


495
496
497
498
499
500
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 495

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

#html_coloursBoolean

#

available_html_colours?

#

html_colours

Returns:

  • (Boolean)


291
292
293
# File 'lib/colours/html_colours/html_colours.rb', line 291

def available_html_colours?
  ::Colours.available_html_colours?
end

#html_colours?Boolean

#

available_html_colours?

#

html_colours?

Returns:

  • (Boolean)


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

def available_html_colours?
  ::Colours.available_html_colours?
end

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

#

italic

#


728
729
730
731
732
733
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 728

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)


88
89
90
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 88

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

#left?Boolean

#

left?

#

Returns:

  • (Boolean)


499
500
501
# File 'lib/colours/constants/constants.rb', line 499

def left?
  Colours.left?
end

#main_coloursObject

#

main_colours

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

#


365
366
367
# File 'lib/colours/constants/constants.rb', line 365

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.

#


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

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

#open_this_file(shall_we_exit = false) ⇒ Object

#

Colours.open_this_file

This method will make use of the editor called bluefish to open this file.

#


584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 584

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

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

#

random_colour?

#

Returns:

  • (Boolean)


347
348
349
# File 'lib/colours/html_colours/html_colours.rb', line 347

def random_colour?
  return Colours.random_html_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)


872
873
874
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 872

def random_value?
  ::Colours.random_value?
end

#registered_colours?Boolean

#

available_html_colours?

#

registered_colours?

Returns:

  • (Boolean)


296
297
298
# File 'lib/colours/html_colours/html_colours.rb', line 296

def available_html_colours?
  ::Colours.available_html_colours?
end

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

#

restore?

This will restore to the default again.

#

Returns:

  • (Boolean)


337
338
339
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 337

def restore?
  Colours.restore?
end

#return_all_html_coloursBoolean

#

available_html_colours?

#

return_all_html_colours

Returns:

  • (Boolean)


293
294
295
# File 'lib/colours/html_colours/html_colours.rb', line 293

def available_html_colours?
  ::Colours.available_html_colours?
end

#return_random_rgbObject Also known as: return_rgb_as_array

#

return_random_rgb

#


306
307
308
# File 'lib/colours/rgb/rgb.rb', line 306

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.

#


56
57
58
# File 'lib/colours/toplevel_methods/rev.rb', line 56

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

#rgbObject

#

rgb_value_as_escape_code_string

#

rgb



324
325
326
327
328
329
330
331
332
333
# File 'lib/colours/rgb/rgb.rb', line 324

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

#rgb_as_stringObject

#

rgb_value_as_escape_code_string

#

rgb_as_string



326
327
328
329
330
331
332
333
334
335
# File 'lib/colours/rgb/rgb.rb', line 326

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

#rgb_formatObject

#

rgb_value_as_escape_code_string

#

rgb_format



325
326
327
328
329
330
331
332
333
334
# File 'lib/colours/rgb/rgb.rb', line 325

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

#rgb_to_hexObject

#

convert_this_rgb_value_to_that_hexadecimal_representation

#

rgb_to_hex



336
337
338
339
340
# File 'lib/colours/rgb/rgb.rb', line 336

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

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

#

rgb_value_as_escape_code_string

#


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

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

#rgb_value_as_stringObject

#

rgb_value_as_escape_code_string

#

rgb_value_as_string



323
324
325
326
327
328
329
330
331
332
# File 'lib/colours/rgb/rgb.rb', line 323

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

#scomments(i = '') ⇒ Object Also known as: scomment

#

scomments

#


420
421
422
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 420

def scomments(i = '')
  ::Colours.scomments(i) # Delegate towards Colours.scomments? here.
end

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

#

sdir

#


622
623
624
625
626
627
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 622

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

#sfancy(i = '') ⇒ Object

#

sfancy

#


595
596
597
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 595

def sfancy(i = '')
  ::Colours.sfancy(i)
end

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

#

sfile

#


632
633
634
635
636
637
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 632

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

#show_html_coloursObject

#

show_html_colours

#


311
312
313
# File 'lib/colours/html_colours/html_colours.rb', line 311

def show_html_colours
  ::Colours.show_html_colours
end

#simportant(i = '', make_newline = false) ⇒ Object Also known as: simp, si

#

simportant

Delegate towards Colours.simportant() here.

#


532
533
534
535
536
537
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 532

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

Note that a symlink called symlink() exists to this method, but it is not exactly clear whether this alias will be kept, as it may interfere with some other methods when we do an include-action.

#


326
327
328
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 326

def ssymlink(i = '')
  ::Colours.ssymlink(i)
end

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

#

swarn

#


455
456
457
458
459
460
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 455

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

#to_hexObject

#

convert_this_rgb_value_to_that_hexadecimal_representation

#

to_hex



337
338
339
340
341
# File 'lib/colours/rgb/rgb.rb', line 337

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

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

#

underline

#


292
293
294
295
296
297
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 292

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

#use_colours?Boolean

#

use_colours?

Delegate towards the class-method here. Unsure whether this method is really needed, but let’s keep it for now. After all we can use “include Colours” to add that method.

#

Returns:

  • (Boolean)


72
73
74
# File 'lib/colours/toplevel_methods/toplevel_methods.rb', line 72

def use_colours?
  ::Colours.use_colours?
end

#use_new_colour_codes(i = HASH_NEW_COLOURS) ⇒ Object Also known as: assign_new_colour_codes

#

use_new_colour_codes

Use this method to assign new colour codes. We assume that you must pass a hash to this method.

Usage example:

new_hash = {
  :sfancy         => 'green',
  :simportant     => 'teal',
  :default_colour => 'grey',
  :sfile          => 'magenta',
  :sdir           => 'cyan'
}
Colours.assign_new_colour_codes(new_hash)
#


128
129
130
131
132
# File 'lib/colours/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink/sfile_sdir_sfancy_swarn_simp_scomments_and_ssymlink.rb', line 128

def use_new_colour_codes(
    i = HASH_NEW_COLOURS
  )
  @colour_table.update(i)
end