lib/vedeu/output/compositor.rb in vedeu-0.2.8 vs lib/vedeu/output/compositor.rb in vedeu-0.2.9
- old
+ new
@@ -36,52 +36,77 @@
attr_reader :name
# Renders the cursor into the currently focussed interface. May be hidden.
#
- # @return [String]
+ # @return [String] The escape sequence to render the cursor as shown or
+ # hidden.
def cursor
- Interface.new(Vedeu::Interfaces.find(Focus.current)).cursor.to_s
+ Interface.new(Interfaces.find(Focus.current)).cursor.to_s
end
- # Renders the buffer unless empty, otherwise clears the area which the
- # interface occupies.
+ # Return the content for this buffer.
#
- # @return [String]
+ # - If we have new content (i.e. content on 'back') to be shown, we first
+ # clear the area occupied by the previous content, then clear the area for
+ # the new content, and then finally render the new content.
+ # - If there is no new content (i.e. 'back' is empty), check the 'front'
+ # buffer and display that.
+ # - If there is no new content, and the front buffer is empty, display the
+ # 'previous' buffer.
+ # - If the 'previous' buffer is empty, return an empty hash.
+ #
+ # @return [Hash]
def view
- if buffer
- Render.call(Interface.new(new_interface))
+ if buffer.back?
+ Clear.call(compose(buffer.previous)) if buffer.previous?
+ buffer.swap
+
+ Render.call(compose(buffer.front))
+
+ elsif buffer.front?
+ Render.call(compose(buffer.front))
+
+ elsif buffer.previous?
+ Render.call(compose(buffer.previous))
+
else
- Clear.call(Interface.new(interface))
+ Clear.call(compose({}), { direct: false })
end
end
- # Combine the buffer attributes with the interface attributes. Buffer
- # presentation attributes will override interface defaults.
+ # Return a new instance of Interface built by combining the buffer content
+ # attributes with the stored interface attributes.
#
- # @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
+ # @return [Interface]
+ def compose(content)
+ if defined_value?(content[:geometry])
+ content[:geometry].each do |k, v|
+ interface[:geometry][k] = v if defined_value?(k)
+ end
+ end
+
+ interface[:lines] = content[:lines]
+ interface[:colour] = content[:colour] if defined_value?(content[:colour])
+ interface[:style] = content[:style] if defined_value?(content[:style])
+
+ Interface.new(interface)
end
# Returns the attributes of the named interface (layout).
#
# @return [Hash]
def interface
- @_interface ||= Vedeu::Interfaces.find(name)
+ @_interface ||= Interfaces.find(name)
end
- # Returns the attributes of the latest buffer (view).
+ # Return the named Buffer (view).
#
- # @return [Hash|NilClass]
+ # @return [Buffer]
def buffer
- @_buffer ||= Vedeu::Buffers.latest(name)
+ @_buffer ||= Buffers.find(name)
end
end # Compositor
end # Vedeu