Sha256: bddc5dbfbb1e3b69880b46a88fcf63a88769e42feedface06bc18343ca822de7

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Vedeu

  # The class represents one half (the other, can be found at
  # {Vedeu::Foreground}) of a terminal colour escape sequence.
  #
  # @api private
  class Background < ColourTranslator

    private

    # Returns an escape sequence for a named background colour.
    #
    # Valid names are: `:black`, `:red`, `:green`, `:yellow`, `:blue`,
    # `:magenta`, `:cyan`, `:white` and `:default`.
    #
    # @return [String]
    def named
      ["\e[", background_codes[colour], 'm'].join
    end

    # Returns an escape sequence.
    #
    # @return [String]
    def numbered
      ["\e[48;5;", css_to_numbered, 'm'].join
    end

    # Returns an escape sequence.
    #
    # @return [String]
    def rgb
      if Configuration.colour_mode == 16777216
        sprintf("\e[48;2;%s;%s;%sm", *css_to_rgb)

      else
        numbered

      end
    end

    # Produces the background named colour escape sequence hash from the
    # foreground escape sequence hash.
    #
    # @return [Hash]
    def background_codes
      Esc.codes.inject({}) { |h, (k, v)| h.merge(k => v + 10) }
    end

  end # Background

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.2.10 lib/vedeu/models/background.rb
vedeu-0.2.9 lib/vedeu/models/background.rb
vedeu-0.2.8 lib/vedeu/models/background.rb