Sha256: ec8f42bdfd7b69477a3eebe0e39eee1655c1fa7ec169703a81f0475a3e26178a
Contents?: true
Size: 1.73 KB
Versions: 4
Compression:
Stored size: 1.73 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 # @!attribute [r] attributes # @return [Hash] attr_reader :attributes # @!attribute [r] background # @return [Background|String] attr_reader :background # @!attribute [r] foreground # @return [Foreground|String] attr_reader :foreground # Returns a new instance of Vedeu::Colour. # # @param attributes [Hash] # @option attributes background [String] # @option attributes foreground [String] # @return [Colour] def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @background = Vedeu::Background.coerce(@attributes[:background]) @foreground = Vedeu::Foreground.coerce(@attributes[:foreground]) end # Converts the value into a Vedeu::Foreground. # # @param value [String] # @return [String] def foreground=(value) @foreground = Vedeu::Foreground.coerce(value) end # Converts the value into a Vedeu::Background. # # @param value [String] # @return [String] def background=(value) @background = Vedeu::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<Symbol => String>] def defaults { foreground: '', background: '' } end end # Colour end # Vedeu
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.13 | lib/vedeu/output/colour.rb |
vedeu-0.4.12 | lib/vedeu/output/colour.rb |
vedeu-0.4.11 | lib/vedeu/output/colour.rb |
vedeu-0.4.10 | lib/vedeu/output/colour.rb |