Sha256: a6041296cf7782ad4592ecd8470d2874653c17703547fd97d062aed65f138840
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
require 'vedeu/support/coercions' module Vedeu # Provides a container for terminal escape sequences controlling the # foreground and background colours of a character or collection of # characters. # class Colour include Vedeu::Coercions attr_reader :attributes, :background, :foreground # Returns a new instance of Colour. # # @param attributes [Hash] # @option attributes background [String] # @option attributes foreground [String] # @return [Colour] def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @background = Background.coerce(@attributes[:background]) @foreground = Foreground.coerce(@attributes[:foreground]) end # Converts the value into a Vedeu::Foreground. # # @param value [String] # @return [String] def foreground=(value) @foreground = Foreground.coerce(value) end # Converts the value into a Vedeu::Background. # # @param value [String] # @return [String] def background=(value) @background = Background.coerce(value) end # Returns both or either of the converted attributes into a single escape # sequence. # # @return [String] def to_s foreground.to_s + background.to_s end private # The default values for a new instance of this class. # # @return [Hash] def defaults { foreground: '', background: '' } end end # Colour end # Vedeu
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.5 | lib/vedeu/output/colour.rb |
vedeu-0.4.4 | lib/vedeu/output/colour.rb |
vedeu-0.4.3 | lib/vedeu/output/colour.rb |