Sha256: e80284face388969a658c2698f720b03e371f883841098601843288f8079d16a

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Vedeu

  # Attempts to convert the provided interface object with associated lines,
  # streams, colours, styles, etc, into a single string containing all content
  # and escape sequences.
  #
  # @api private
  class Render

    # Create a new instance of Render with the provided {Vedeu::Interface} and
    # then convert the interface into a single string of content and escape
    # sequences.
    #
    # @param interface [Interface]
    # @return [String]
    def self.call(interface)
      new(interface).render
    end

    # Return a new instance of Render.
    #
    # @param interface [Interface]
    # @return [Render]
    def initialize(interface)
      @interface = interface
    end

    # Produces a single string which contains all content and escape sequences
    # required to render this interface to a position in the terminal window.
    #
    # @return [String]
    def render
      out = [ Clear.call(interface, { direct: false }) ]

      Vedeu.log("Rendering view: '#{interface.name}'")

      interface.viewport.each_with_index do |line, index|
        out << interface.origin(index)
        out << line.join
      end
      out.join
    end

    private

    attr_reader :interface

  end # Render

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.10 lib/vedeu/output/render.rb
vedeu-0.2.9 lib/vedeu/output/render.rb