Class: Vedeu::Colours::Colour
- Inherits:
-
Object
- Object
- Vedeu::Colours::Colour
- Extended by:
- Forwardable
- Includes:
- Repositories::Defaults
- Defined in:
- lib/vedeu/colours/colour.rb
Overview
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>
- #background ⇒ Vedeu::Colours::Background
-
#background=(value) ⇒ Vedeu::Colours::Foreground
Converts the value into a Vedeu::Colours::Background.
-
#defaults ⇒ Hash<Symbol => void>
private
The default options/attributes for a new instance of this class.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
- #foreground ⇒ Vedeu::Colours::Foreground
-
#foreground=(value) ⇒ Vedeu::Colours::Foreground
Converts the value into a Vedeu::Colours::Foreground.
- #to_ast ⇒ String
- #to_h ⇒ Hash<Symbol => Hash<Symbol => String>> (also: #to_hash)
-
#to_s ⇒ String
(also: #to_str)
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
50 51 52 |
# File 'lib/vedeu/colours/colour.rb', line 50 def default new(background: :default, foreground: :default) end |
Instance Method Details
#attributes ⇒ Hash<Symbol => Vedeu::Colours::Background, Vedeu::Colours::Foreground>
68 69 70 71 72 73 |
# File 'lib/vedeu/colours/colour.rb', line 68 def attributes { background: background, foreground: foreground, } end |
#background ⇒ Vedeu::Colours::Background
76 77 78 |
# File 'lib/vedeu/colours/colour.rb', line 76 def background Vedeu::Colours::Background.coerce(@background) end |
#background=(value) ⇒ Vedeu::Colours::Foreground
Converts the value into a Vedeu::Colours::Background.
84 85 86 |
# File 'lib/vedeu/colours/colour.rb', line 84 def background=(value) @background = Vedeu::Colours::Background.coerce(value) end |
#defaults ⇒ Hash<Symbol => void> (private)
The default options/attributes for a new instance of this class.
139 140 141 142 143 144 |
# File 'lib/vedeu/colours/colour.rb', line 139 def defaults { background: Vedeu::Colours::Background.new, foreground: Vedeu::Colours::Foreground.new, } end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
92 93 94 95 96 |
# File 'lib/vedeu/colours/colour.rb', line 92 def eql?(other) self.class.equal?(other.class) && background == other.background && foreground == other.foreground end |
#foreground ⇒ Vedeu::Colours::Foreground
100 101 102 |
# File 'lib/vedeu/colours/colour.rb', line 100 def foreground Vedeu::Colours::Foreground.coerce(@foreground) end |
#foreground=(value) ⇒ Vedeu::Colours::Foreground
Converts the value into a Vedeu::Colours::Foreground.
108 109 110 |
# File 'lib/vedeu/colours/colour.rb', line 108 def foreground=(value) @foreground = Vedeu::Colours::Foreground.coerce(value) end |
#to_ast ⇒ String
113 114 115 116 117 |
# File 'lib/vedeu/colours/colour.rb', line 113 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
120 121 122 123 124 |
# File 'lib/vedeu/colours/colour.rb', line 120 def to_h { colour: background.to_h.merge!(foreground.to_h), } end |
#to_s ⇒ String Also known as: to_str
Returns both or either of the converted attributes into a single escape sequence.
131 132 133 |
# File 'lib/vedeu/colours/colour.rb', line 131 def to_s "#{foreground}#{background}" end |