Sha256: 75a970c1cbde4b1ea9b4524e6b7f4740ee45f227ff9705bc8945b4b8868ac635

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Vedeu
  class Interface
    include Queue

    attr_accessor :attributes, :name, :cursor, :current

    def initialize(attributes = {})
      @attributes = attributes || {}
      @name       = attributes[:name]
      @cursor     = attributes.fetch(:cursor, true)
      @current    = []
    end

    # :nocov:
    def refresh
      if enqueued?
        @current = dequeue
      elsif @current.empty?
        Compositor.arrange(initial_state)

        @current = dequeue
      else
        @current
      end
    end
    # :nocov:

    def geometry
      @geometry ||= Geometry.new(attributes)
    end

    def colour
      @colour ||= Colour.new([foreground, background])
    end

    def cursor
      @cursor ? Cursor.show : Cursor.hide
    end

    def layer
      @layer ||= Layer.new(layer_attr).index
    end

    private

    def initial_state
      { name => Array.new(geometry.height) { [{ text: '' }] } }
    end

    def layer_attr
      attributes.fetch(:layer, 0)
    end

    def foreground
      attributes[:fg] || attributes[:foreground]
    end

    def background
      attributes[:bg] || attributes[:background]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.0.25 lib/vedeu/repository/interface.rb
vedeu-0.0.24 lib/vedeu/repository/interface.rb