Class: Vedeu::Colours::Colour Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Repositories::Defaults
Defined in:
lib/vedeu/colours/colour.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

TODO:

Fix colours in all terminals. (GL: 2015-04-13)

Provides a container for terminal escape sequences controlling the foreground and background colours of a character or collection of characters.

Vedeu uses HTML/CSS style notation (i.e. ‘#aadd00’), they can be used at the stream level, the line level or for the whole interface. Terminals generally support either 8, 16 or 256 colours, with few supporting full 24-bit colour (see notes below).

Vedeu attempts to detect the colour depth using the ‘$TERM` environment variable.

To set your ‘$TERM` variable to allow 256 colour support:

“‘bash echo “export TERM=xterm-256color” >> ~/.bashrc “`

Notes: Terminals which support the 24-bit colour mode include (but are not limited to): iTerm2 (OSX), Gnome Terminal (Linux).

Setting your ‘$TERM` environment variable as above gets you up to 256 colours, but when you then add the `colour_mode 16_777_216` configuration to your client application, it’s really a hit and miss affair. iTerm2 renders all the colours correctly as does Gnome Terminal. Terminator (Linux) goes crazy though and defaults to 16 colours despite the ‘$TERM` setting. This area needs more work in Vedeu.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Repositories::Defaults

#initialize, #validate

Methods included from Vedeu::Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Class Method Details

.defaultVedeu::Colours::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/vedeu/colours/colour.rb', line 52

def default
  new(background: :default, foreground: :default)
end

Instance Method Details

#attributesHash<Symbol => Vedeu::Colours::Background, Vedeu::Colours::Foreground>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def attributes
  {
    background: background,
    foreground: foreground,
  }
end

#backgroundVedeu::Colours::Background

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
# File 'lib/vedeu/colours/colour.rb', line 78

def background
  Vedeu::Colours::Background.coerce(@background)
end

#background=(value) ⇒ Vedeu::Colours::Foreground

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the value into a Vedeu::Colours::Background.

Parameters:

  • value (String)

Returns:



86
87
88
# File 'lib/vedeu/colours/colour.rb', line 86

def background=(value)
  @background = Vedeu::Colours::Background.coerce(value)
end

#defaultsHash<Symbol => void> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


141
142
143
144
145
146
# File 'lib/vedeu/colours/colour.rb', line 141

def defaults
  {
    background: Vedeu::Colours::Background.new,
    foreground: Vedeu::Colours::Foreground.new,
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

An object is equal when its values are the same.

Parameters:

  • other (void)

Returns:



94
95
96
97
98
# File 'lib/vedeu/colours/colour.rb', line 94

def eql?(other)
  self.class.equal?(other.class) &&
    background == other.background &&
    foreground == other.foreground
end

#foregroundVedeu::Colours::Foreground

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
# File 'lib/vedeu/colours/colour.rb', line 102

def foreground
  Vedeu::Colours::Foreground.coerce(@foreground)
end

#foreground=(value) ⇒ Vedeu::Colours::Foreground

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the value into a Vedeu::Colours::Foreground.

Parameters:

  • value (String)

Returns:



110
111
112
# File 'lib/vedeu/colours/colour.rb', line 110

def foreground=(value)
  @foreground = Vedeu::Colours::Foreground.coerce(value)
end

#to_astString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


115
116
117
118
119
# File 'lib/vedeu/colours/colour.rb', line 115

def to_ast
  [foreground.to_ast, background.to_ast].reject do |value|
    absent?(value)
  end.join(' ')
end

#to_hHash<Symbol => Hash<Symbol => String>> Also known as: to_hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => Hash<Symbol => String>>)


122
123
124
125
126
# File 'lib/vedeu/colours/colour.rb', line 122

def to_h
  {
    colour: background.to_h.merge!(foreground.to_h),
  }
end

#to_sString Also known as: to_str

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns both or either of the converted attributes into a single escape sequence.

Returns:

  • (String)


133
134
135
# File 'lib/vedeu/colours/colour.rb', line 133

def to_s
  "#{foreground}#{background}"
end