Sha256: 21baa8748aeae6e46c1a7d87e5067341e5edd84ef7a420c9d037254019b81949
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
module Vedeu # Provides a container for terminal escape sequences controlling the # foreground and background colours of a character or collection of # characters. # # @api private class Colour attr_reader :attributes # Returns a new instance of Colour. # # @param attributes [Hash] # @return [Colour] def initialize(attributes = {}) @attributes = defaults.merge!(attributes) end # Converts the `:foreground` attribute into a terminal escape sequence. # # @return [String] def foreground @foreground ||= Foreground.escape_sequence(attributes[:foreground]) end # Converts the `:background` attribute into a terminal escape sequence. # # @return [String] def background @background ||= Background.escape_sequence(attributes[:background]) end # Returns both or either of the converted attributes into a single escape # sequence. # # @return [String] def to_s foreground + background end private # The default values for a new instance of Colour. # # @return [Hash] def defaults { foreground: '', background: '' } end end # Colour end # Vedeu
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.2.11 | lib/vedeu/colours/colour.rb |
vedeu-0.2.10 | lib/vedeu/models/colour.rb |