lib/vedeu/output/compositor.rb in vedeu-0.0.6 vs lib/vedeu/output/compositor.rb in vedeu-0.0.7
- old
+ new
@@ -1,36 +1,34 @@
module Vedeu
class Compositor
class << self
- def write(output = [])
+ def write(output = [], interface = Dummy)
return if output.nil? || output.empty?
- new(output).write
+ new(output, interface).write
end
end
- def initialize(output = [])
- @output = output
+ def initialize(output = [], interface = Dummy)
+ @output, @interface = output, interface
end
def write
- parsed.each_with_index do |data, index|
- clear_line(index)
-
- write_line(data)
- end.join("\n")
+ Renderer.write(composition)
end
private
- attr_reader :output
+ attr_reader :output, :interface
- def parsed
+ def composition
container = []
streams = []
output.map do |line|
- line.map do |stream|
+ line.each_with_index do |stream, index|
+ streams << clear_line(index)
+
if stream.is_a?(String)
streams << stream
else
streams << Directive.enact(stream)
end
@@ -40,13 +38,49 @@
end
container
end
def clear_line(index)
- Terminal.clear_line(index)
+ [position(vy(index), vx), (" " * width), position(vy(index), vx)].join
end
- def write_line(data)
- Terminal.output(data)
+ def vx(index = 0)
+ geometry.vx(index)
+ end
+
+ def vy(index = 0)
+ geometry.vy(index)
+ end
+
+ def height
+ geometry.height
+ end
+
+ def width
+ geometry.width
+ end
+
+ def y
+ geometry.y
+ end
+
+ def dy
+ geometry.dy
+ end
+
+ def x
+ geometry.x
+ end
+
+ def dx
+ geometry.dx
+ end
+
+ def geometry
+ interface.geometry
+ end
+
+ def position(y, x)
+ Position.set(y, x)
end
end
end