Class: Vedeu::Colours::Colour Private
- Inherits:
-
Object
- Object
- Vedeu::Colours::Colour
- 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.
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
- #attributes ⇒ Hash<Symbol => Vedeu::Colours::Background, Vedeu::Colours::Foreground> private
- #background ⇒ Vedeu::Colours::Background private
-
#background=(value) ⇒ Vedeu::Colours::Foreground
private
Converts the value into a Vedeu::Colours::Background.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
- #foreground ⇒ Vedeu::Colours::Foreground private
-
#foreground=(value) ⇒ Vedeu::Colours::Foreground
private
Converts the value into a Vedeu::Colours::Foreground.
- #to_ast ⇒ String private
- #to_h ⇒ Hash<Symbol => Hash<Symbol => String>> (also: #to_hash) private
-
#to_s ⇒ String
(also: #to_str)
private
Returns both or either of the converted attributes into a single escape sequence.
Methods included from Repositories::Defaults
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
.default ⇒ Vedeu::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
#attributes ⇒ Hash<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 |
#background ⇒ Vedeu::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.
86 87 88 |
# File 'lib/vedeu/colours/colour.rb', line 86 def background=(value) @background = Vedeu::Colours::Background.coerce(value) end |
#defaults ⇒ Hash<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.
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.
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 |
#foreground ⇒ 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.
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.
110 111 112 |
# File 'lib/vedeu/colours/colour.rb', line 110 def foreground=(value) @foreground = Vedeu::Colours::Foreground.coerce(value) end |
#to_ast ⇒ String
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.
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_h ⇒ Hash<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.
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_s ⇒ String 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.
133 134 135 |
# File 'lib/vedeu/colours/colour.rb', line 133 def to_s "#{foreground}#{background}" end |