Sha256: 2a6b235f3086251db334d547e158c4710d39680c5cee6181f0523358fe4c4cb2
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 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 # @return [Hash] 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 # @api private # @return [Hash] def defaults { foreground: '', background: '' } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.2.1 | lib/vedeu/models/colour.rb |
vedeu-0.2.0 | lib/vedeu/models/colour.rb |