class Chromate::Effect
The `Effect` class is used to represent a generic escape sequences, providing a standardized escape mechanism. You may convert an effect to either a string, in which case it will be escaped as an SGR escape sequence, or an integer, in which case it will yield its internal value. You may also explicitly escape an effect by calling {#escape} on it.
Public Class Methods
Get the effect with the specified name. @param value [String,Symbol] the name of an effect
@return [Effect]
# File lib/chromate/effect.rb, line 30 def self.[](value) if value.is_a?(Symbol) or value.is_a?(String) EFFECTS[value.intern] else raise TypeError, "don't know what to do with a #{value.class}" end end
Create a new effect with the specified value. @param value [Fixnum]
@return [Effect]
# File lib/chromate/effect.rb, line 17 def initialize(value) unless value.is_a?(Numeric) raise TypeError, "cannot create #{self.class} from #{value.class}" end @value = value.to_i end
Public Instance Methods
# File lib/chromate/effect.rb, line 83 def +(other) case other when EffectSet other.add(self) when Effect EffectSet.new([self, other]) when String escape + other else raise TypeError, "cannot add #{other.class} to #{self.class}" end end
@return [Boolean]
# File lib/chromate/effect.rb, line 79 def ==(other) to_i == other.to_i end
Escape as an SGR escape sequence.
@return [String] an escape sequence of the form “e[1;2;3;…m”
# File lib/chromate/effect.rb, line 42 def escape "\e[#{@value}m" end
@return [String]
# File lib/chromate/effect.rb, line 57 def inspect if name.nil? "#<Effect: #{@value}>" else "#<Effect: #{name}>" end end
Get the name of this effect, if it exists.
@return [Symbol]
# File lib/chromate/effect.rb, line 50 def name if EFFECTS.value?(self) EFFECTS.find { |k, v| v == self }.first end end
Yield the internal value.
@return [Integer]
# File lib/chromate/effect.rb, line 69 def to_i @value end
@return [String]
# File lib/chromate/effect.rb, line 74 def to_s escape end