Sha256: b2adf593fc039614b9af09f09d212fcd4fd570699fa77f6042a5b74f55d1e3bd

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 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

    # @api private
    # @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.
    #
    # @api private
    # @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).
    #
    # @api private
    # @return [Hash]
    def interface
      @_interface ||= Vedeu::Interfaces.find(name)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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