class Colours::Colours

Constants

LEADING_PART
#

LEADING_PART

We don’t include the “[” here.

#
TRAILING_PART
#

TRAILING_PART

#

Public Class Methods

[](i = ARGV) click to toggle source
#

Colours::Colours[]

#
# File lib/colours/class/colours.rb, line 362
def self.[](i = ARGV)
  new(i)
end
new(i = '') click to toggle source
#

initialize

#
# File lib/colours/class/colours.rb, line 53
def initialize(i = '')
  reset
  if i.is_a? Array
    i = i.join(' ').strip
  end
  @internal_hash[:raw_content] = i # Keep a reference-copy here.
end

Public Instance Methods

+(i = '') click to toggle source
#

+

#
# File lib/colours/class/colours.rb, line 284
def +(i = '')
  append(i)
end
append(i) click to toggle source
#

append

#
# File lib/colours/class/colours.rb, line 291
def append(i)
  "#{to_str}#{i.to_str}"
end
background(i = :yellow) click to toggle source
#

background

#
# File lib/colours/class/colours.rb, line 259
def background(i = :yellow)
  i = i.to_s
  unless i.start_with? 'background_'
    i = i.dup if i.frozen?
    i.prepend('background_')
  end
  i = i.to_sym
  unless HASH_ANSI_COLOURS.has_key? i
    e 'Warning: the key '+i.to_s+' is not registered in the main Hash.'
  end
  i = HASH_ANSI_COLOURS[i].to_s
  set_use_this_background_colour(i)
  self
end
Also aliased as: bg
bg(i = :yellow)
Alias for: background
black()
Alias for: red
blue()
Alias for: red
bold()
Alias for: bright
bright() click to toggle source
#

bright

#
# File lib/colours/class/colours.rb, line 251
def bright
  @internal_hash[:leading_colour_component] = '1'
  self
end
Also aliased as: bold
brown()
Alias for: red
build_main_string()
build_the_main_string() click to toggle source
#

build_the_main_string (main tag)

This method must always rebuild the full, modified content.

#
# File lib/colours/class/colours.rb, line 300
def build_the_main_string
  result = ''.dup
  result << leading_part?
  result << '['
  result << string_increased_intensity?
  result << ";#{use_this_colour?}" unless use_this_colour? == '0'
  if use_this_background_colour?
    result << ";#{use_this_background_colour?}"
  end
  result << ';3' if use_italic?
  result << ';4' if use_underline?
  result << ';5' if slow_blink?
  result << ';7' if reversed?
  result << 'm'
  result << raw_content?
  result << trailing_end?
  return result
end
Also aliased as: to_str, to_s, build_main_string
content?()
Alias for: raw_content?
cyan()
Alias for: red
display() click to toggle source
#

display

#
# File lib/colours/class/colours.rb, line 188
def display
  print build_main_string(content?)
end
Also aliased as: report
green()
Alias for: red
grey()
Alias for: red
increased_intensity?() click to toggle source
#

increased_intensity?

#
# File lib/colours/class/colours.rb, line 232
def increased_intensity?
  _ = @internal_hash[:leading_colour_component]
  return (_ and !_.empty?)
end
italic() click to toggle source
#

italic

#
# File lib/colours/class/colours.rb, line 347
def italic
  @internal_hash[:use_italic] = true
  self
end
leading_part?() click to toggle source
#

leading_part?

#
# File lib/colours/class/colours.rb, line 209
def leading_part?
  "#{LEADING_PART}"
end
light_blue()
Alias for: red
light_gray()
Alias for: red
light_green()
Alias for: red
light_magenta()
Alias for: red
light_red()
Alias for: red
magenta()
Alias for: red
purple()
Alias for: red
raw_content?() click to toggle source
#

raw_content?

#
# File lib/colours/class/colours.rb, line 159
def raw_content?
  @internal_hash[:raw_content]
end
Also aliased as: content?, string?
red() click to toggle source
#

red

#
# File lib/colours/class/colours.rb, line 324
def red
  real_name_of_the_method = HASH_ANSI_COLOURS[__callee__]
  set_use_this_colour(real_name_of_the_method)
  self
end
report()
Alias for: display
reset() click to toggle source
#

reset (reset tag)

#
# File lib/colours/class/colours.rb, line 64
def reset
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :raw_content
  # ======================================================================= #
  @internal_hash[:raw_content] = nil
  # ======================================================================= #
  # === :leading_colour_component
  #
  # This can be '', '0' or '1'. The '1' means bright; the '0' is for
  # regular colours. The default is ''.
  # ======================================================================= #
  @internal_hash[:leading_colour_component] = ''.dup
  # ======================================================================= #
  # === :use_italic
  # ======================================================================= #
  @internal_hash[:use_italic] = false
  # ======================================================================= #
  # === :use_underline
  # ======================================================================= #
  @internal_hash[:use_underline] = false
  # ======================================================================= #
  # === :slow_blink
  # ======================================================================= #
  @internal_hash[:slow_blink] = false
  # ======================================================================= #
  # === :use_this_background_colour
  # ======================================================================= #
  @internal_hash[:use_this_background_colour] = nil
  # ======================================================================= #
  # === :use_this_colour
  #
  # We must use a default colour.
  # ======================================================================= #
  @internal_hash[:use_this_colour] = '0'
  # ======================================================================= #
  # === :reversed
  #
  # If this is true then "7" will be used, which will invert foreground
  # colour and background colour.
  # ======================================================================= #
  @internal_hash[:reversed] = false
end
reversed() click to toggle source
#

reversed

#
# File lib/colours/class/colours.rb, line 137
def reversed
  @internal_hash[:reversed] = true
  self
end
reversed?() click to toggle source
#

reversed?

#
# File lib/colours/class/colours.rb, line 114
def reversed?
  @internal_hash[:reversed]
end
set_content(i) click to toggle source
#

set_content

#
# File lib/colours/class/colours.rb, line 195
def set_content(i)
  @internal_hash[:raw_content] = i.dup
end
set_use_this_background_colour(i) click to toggle source
#

set_use_this_background_colour

#
# File lib/colours/class/colours.rb, line 130
def set_use_this_background_colour(i)
  @internal_hash[:use_this_background_colour] = i
end
set_use_this_colour(i) click to toggle source
#

set_use_this_colour

#
# File lib/colours/class/colours.rb, line 277
def set_use_this_colour(i)
  @internal_hash[:use_this_colour] = i
end
set_use_underline_to_true() click to toggle source
#

set_use_underline_to_true

#
# File lib/colours/class/colours.rb, line 145
def set_use_underline_to_true
  @internal_hash[:use_underline] = true
end
string?()
Alias for: raw_content?
string_increased_intensity?() click to toggle source
#

string_increased_intensity?

#
# File lib/colours/class/colours.rb, line 240
def string_increased_intensity?
  _ = @internal_hash[:leading_colour_component]
  if _ and !_.empty?
    return "#{_}" # ;"
  end
  return ''
end
to_s()
to_str()
trailing_end?() click to toggle source
#

trailing_end?

#
# File lib/colours/class/colours.rb, line 202
def trailing_end?
  TRAILING_PART
end
underline() click to toggle source
#

underline

#
# File lib/colours/class/colours.rb, line 224
def underline
  set_use_underline_to_true
  self
end
Also aliased as: underlined
underlined()
Alias for: underline
use_italic?() click to toggle source
#

use_italic?

#
# File lib/colours/class/colours.rb, line 355
def use_italic?
  @internal_hash[:use_italic]
end
use_this_background_colour?() click to toggle source
#

use_this_background_colour?

Background colours go from e. g. 40 to 47, give or take.

#
# File lib/colours/class/colours.rb, line 123
def use_this_background_colour?
  @internal_hash[:use_this_background_colour]
end
use_this_colour?() click to toggle source
#

use_this_colour?

#
# File lib/colours/class/colours.rb, line 167
def use_this_colour?
  @internal_hash[:use_this_colour]
end
use_underline?() click to toggle source
#

use_underline?

#
# File lib/colours/class/colours.rb, line 174
def use_underline?
  @internal_hash[:use_underline]
end
white()
Alias for: red
yellow()
Alias for: red