Class: Vedeu::Colours::Colour
- Inherits:
-
Object
- Object
- Vedeu::Colours::Colour
- 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.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(attributes = {}) ⇒ Vedeu::Colours::Colour
constructor
Returns a new instance of Vedeu::Colours::Colour.
-
#to_s ⇒ String
(also: #to_str)
Returns both or either of the converted attributes into a single escape sequence.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Colours::Colour
Returns a new instance of Vedeu::Colours::Colour.
75 76 77 78 |
# File 'lib/vedeu/colours/colour.rb', line 75 def initialize(attributes = {}) @background = Vedeu::Colours::Background.coerce(attributes[:background]) @foreground = Vedeu::Colours::Foreground.coerce(attributes[:foreground]) end |
Instance Attribute Details
#background ⇒ Vedeu::Colours::Background
42 43 44 |
# File 'lib/vedeu/colours/colour.rb', line 42 def background @background end |
#foreground ⇒ Vedeu::Colours::Foreground
46 47 48 |
# File 'lib/vedeu/colours/colour.rb', line 46 def foreground @foreground end |
Class Method Details
.coerce(value) ⇒ Vedeu::Colours::Colour
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vedeu/colours/colour.rb', line 50 def self.coerce(value) return value if value.is_a?(self) return new unless value.is_a?(Hash) if value[:colour] && value[:colour].is_a?(self) value[:colour] elsif value[:colour] && value[:colour].is_a?(Hash) new(value[:colour]) elsif value[:background] || value[:foreground] new(value) else new end end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
92 93 94 95 |
# File 'lib/vedeu/colours/colour.rb', line 92 def eql?(other) self.class == other.class && background == other.background && foreground == other.foreground end |
#to_s ⇒ String Also known as: to_str
Returns both or either of the converted attributes into a single escape sequence.
110 111 112 |
# File 'lib/vedeu/colours/colour.rb', line 110 def to_s foreground.to_s + background.to_s end |