Sha256: 6e4c03c2dbb6b048c879da0d3c042465ad9174be84b6ba7df03e58f55db79dc3

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Colours

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

      # @return [Boolean]
      def background?
        present?(to_s)
      end

      # @return [String]
      def to_ast
        return '' unless background?

        if rgb?
          ":bg_#{colour.to_s.slice(1..-1)}"

        else
          ':bg'

        end
      end

      # @return [Hash<Symbol => String>]
      def to_h
        {
          background: colour.to_s,
        }
      end
      alias to_hash to_h

      # @param _options [Hash] Ignored.
      # @return [String]
      def to_html(_options = {})
        return '' unless rgb?

        "background-color:#{colour};"
      end

      private

      # @return [String]
      def prefix
        "\e[48;"
      end

      # Returns an escape sequence for a named colour.
      #
      # @note
      #   Valid names can be found at
      #   {Vedeu::EscapeSequences::Esc#valid_codes}
      #
      # @return [String]
      def named
        Vedeu.esc.background_colour(colour)
      end

      # @return [Vedeu::Colours::Backgrounds]
      def repository
        Vedeu.background_colours
      end

    end # Background

  end # Colours

end # Vedeu

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vedeu-0.8.20 lib/vedeu/colours/background.rb
vedeu-0.8.19 lib/vedeu/colours/background.rb
vedeu-0.8.18 lib/vedeu/colours/background.rb
vedeu-0.8.17 lib/vedeu/colours/background.rb
vedeu-0.8.16 lib/vedeu/colours/background.rb
vedeu-0.8.15 lib/vedeu/colours/background.rb
vedeu-0.8.14 lib/vedeu/colours/background.rb
vedeu-0.8.13 lib/vedeu/colours/background.rb
vedeu-0.8.12 lib/vedeu/colours/background.rb
vedeu-0.8.10 lib/vedeu/colours/background.rb
vedeu-0.8.9 lib/vedeu/colours/background.rb
vedeu-0.8.8 lib/vedeu/colours/background.rb
vedeu-0.8.7 lib/vedeu/colours/background.rb