Sha256: d68d6d865a28bb8ca7292db1149ee5dd18dae74e85b02ae30337491aec6f73ba

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

module Vedeu
  class Compositor
    class << self
      def arrange(output = [], interface = :dummy)
        return if output.nil? || output.empty?

        if output.is_a?(Array)
          new(output, interface).arrange
        elsif output.is_a?(Hash)
          output.map do |i, o|
            new(o, i).arrange
          end
        end
      end
    end

    def initialize(output = [], interface = :dummy)
      @output, @interface = output, interface
    end

    def arrange
      Renderer.write(composition)
    end

    private

    def composition
      container = []
      streams = []
      output.map do |line|
        line.each_with_index do |stream, index|
          streams << clear(index)
          streams << Directive.enact(stream)
        end
        container << streams.join
        streams = []
      end
      container
    end

    def clear(index)
      [origin(index), (' ' * width), origin(index)].join
    end

    def origin(index)
      Position.set(geometry.vy(index), geometry.vx)
    end

    def width
      geometry.width
    end

    def geometry
      target_interface.geometry
    end

    def output
      return @output.split if @output.is_a?(String)
      @output
    end

    def target_interface
      raise UndefinedInterface if interface.nil?
      interface
    end

    def interface
      @_interface ||= Interfaces.defined.find(@interface)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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