Sha256: b10e12dd6d81b81ed4b70316f9a3f963790ba18c8ec502a112af36ac7c204f36

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module Vedeu
  class Interface
    include Queue

    attr_accessor :id, :attributes, :active, :name

    class << self
      def create(attributes = {})
        new(attributes).create
      end
    end

    def initialize(attributes = {})
      @attributes = attributes || {}

      @active     = false
      @name       = attributes[:name]
      @cursor     = attributes.fetch(:cursor, true)
    end

    def create
      InterfaceRepository.create(self)

      Compositor.arrange(initial_state)

      self
    end

    def update
      if enqueued?
        dequeue
      else
        [cursor, colour.reset, geometry.origin]
      end
    end

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

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

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

    private

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

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

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

  module ClassMethods
    def interface(name, options = {})
      interface_name = name.is_a?(Symbol) ? name.to_s : name

      Interface.create({ name: interface_name }.merge!(options))
    end
  end

  def self.included(receiver)
    receiver.extend(ClassMethods)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.0.18 lib/vedeu/repository/interface.rb