Sha256: aa6bd8b20b7dbc71e8190a331e02337b137fe7613a3b56719536c2d1116970fb

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 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]

      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

    def clear
      Clear.call(interface)
    end

  end # Render

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.2.8 lib/vedeu/output/render.rb
vedeu-0.2.7 lib/vedeu/output/render.rb
vedeu-0.2.6 lib/vedeu/output/render.rb