lib/vedeu/output/compositor.rb in vedeu-0.0.20 vs lib/vedeu/output/compositor.rb in vedeu-0.0.21

- old
+ new

@@ -1,8 +1,6 @@ module Vedeu - class UndefinedInterface < StandardError; end - class Compositor class << self def arrange(output = {}) output.map do |interface, stream| new({ interface: interface, stream: stream }).arrange @@ -24,64 +22,59 @@ attr_reader :attributes, :stream def composition container = [] - streams = [] - container << colour.set + pad_stream - if stream.size < height - remaining = height - stream.size - remaining.times { |i| stream << [''] } - end - stream.each_with_index do |lines, index| - streams << clear(index) + line = [interface.colour.set, clear(index)] lines.each do |data| - streams << Directive.enact(interface, data) + line << Directive.enact(interface, data) end - container << streams.join - streams = [] + line << interface.colour.reset << interface.cursor + + container << line.join end - container << colour.reset - container << cursor - container end + def pad_stream + if stream.size < height + remaining = height - stream.size + remaining.times { |i| stream << [''] } + end + end + def clear(index) [origin(index), (' ' * width), origin(index)].join end def origin(index) - geometry.origin(index) + interface.geometry.origin(index) end def height - geometry.height + interface.geometry.height end def width - geometry.width + interface.geometry.width end - def geometry - interface.geometry + def stream + @_stream ||= if @stream.is_a?(String) + [@stream.split("\n")] + else + @stream + end end - def colour - interface.colour - end - - def cursor - interface.cursor - end - def interface - @_interface ||= InterfaceRepository.find_by_name(@interface) + @_interface ||= InterfaceRepository.find(@interface) end end end