Sha256: 3974256c955d276640c73dd9fd48039a572049c1da0275dcef52615904f09839

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Vedeu

  # Converts a grid of {Vedeu::Char} objects into a stream of escape sequences
  # and content suitable for a terminal.
  #
  class TerminalRenderer

    # @param output [Array<Array<Vedeu::Char>>]
    # @return [String]
    def self.render(*output)
      new(*output).render
    end

    # Returns a new instance of Vedeu::TerminalRenderer.
    #
    # @param output [Array<Array<Vedeu::Char>>]
    # @return [Vedeu::TerminalRenderer]
    def initialize(*output)
      @output = output
    end

    # @return [Array<String>]
    def render
      Vedeu::Terminal.output(hide_cursor, parsed, show_cursor)
    end

    private

    # @!attribute [r] output
    # @return [Array<Array<Vedeu::Char>>]
    attr_reader :output

    # @return [String]
    def show_cursor
      Vedeu::Esc.string(:show_cursor)
    end

    # @return [String]
    def parsed
      Array(output).flatten.map(&:to_s).join
    end

    # @return [String]
    def hide_cursor
      Vedeu::Esc.string(:hide_cursor)
    end

  end # TerminalRenderer

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.4.11 lib/vedeu/output/renderers/terminal_renderer.rb
vedeu-0.4.10 lib/vedeu/output/renderers/terminal_renderer.rb