Sha256: f3291f5e073a8ee3faefa6d815826cab92f8aa6e6c7c717d57e707a425773cf5

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

module Vedeu

  # Combines stored interface layout/geometry with an interface view/buffer
  # to create a single view to be sent to the terminal for output.
  #
  # @api private
  class Compositor

    include Common

    # @param name [String] The name of the interface/buffer.
    # @return [Compositor]
    def self.render(name)
      new(name).render
    end

    # Initialize a new Compositor.
    #
    # @param name [String] The name of the interface/buffer.
    # @return [Compositor]
    def initialize(name)
      @name = name
    end

    # Send the view to the terminal.
    #
    # @return [Array]
    def render
      Terminal.output(view)
    end

    private

    attr_reader :name

    # Renders the buffer unless empty, otherwise clears the area which the
    # interface occupies.
    #
    # @return [String]
    def view
      if buffer
        Render.call(Interface.new(new_interface))

      else
        Clear.call(Interface.new(interface))

      end
    end

    # Combine the buffer attributes with the interface attributes. Buffer
    # presentation attributes will override interface defaults.
    #
    # @return [Hash]
    def new_interface
      combined = interface
      combined[:lines]  = buffer[:lines]
      combined[:colour] = buffer[:colour] if defined_value?(buffer[:colour])
      combined[:style]  = buffer[:style]  if defined_value?(buffer[:style])
      combined
    end

    # Returns the attributes of the named interface (layout).
    #
    # @return [Hash]
    def interface
      @_interface ||= Vedeu::Interfaces.find(name)
    end

    # Returns the attributes of the latest buffer (view).
    #
    # @return [Hash]
    def buffer
      @_buffer ||= Vedeu::Buffers.latest(name)
    end

  end # Compositor

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.2.4 lib/vedeu/output/compositor.rb