Sha256: 7e774fc85869e975c3a6a49b420667b9a75fbcc03b648af0309f8670ae3f312e

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

module Vedeu

  # Classes within the Output namespace handle various aspects of
  # rendering content.
  #
  module Output

    # Sends the output to the renderers.
    #
    class Output

      # Writes output to the defined renderers.
      #
      # @return [Array|String]
      # @see #initialize
      def self.render(output)
        new(output).render
      end

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

      # Send the view to the renderers. If the output is a
      # {Vedeu::Models::Escape} object (typical when showing or
      # hiding the cursor) then we bypass the
      # {Vedeu::Terminal::Buffer} and write directly to the terminal
      # because escape sequences only make sense to the terminal and
      # not other renderers.
      #
      # @return [Array|NilClass]
      def render
        return nil if output.nil?
        return render_terminal_buffer unless output.is_a?(Vedeu::Models::Escape)

        Vedeu::Output::Direct.write(value: output.value,
                                    x:     output.position.x,
                                    y:     output.position.y)
      end

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

      # @return [Array]
      def render_terminal_buffer
        Vedeu::Terminal::Buffer.write(output).render
      end

    end # Output

  end # Output

end # Vedeu

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.6.24 lib/vedeu/output/output.rb
vedeu-0.6.23 lib/vedeu/output/output.rb
vedeu-0.6.22 lib/vedeu/output/output.rb
vedeu-0.6.21 lib/vedeu/output/output.rb
vedeu-0.6.20 lib/vedeu/output/output.rb
vedeu-0.6.19 lib/vedeu/output/output.rb
vedeu-0.6.18 lib/vedeu/output/output.rb
vedeu-0.6.17 lib/vedeu/output/output.rb
vedeu-0.6.16 lib/vedeu/output/output.rb
vedeu-0.6.15 lib/vedeu/output/output.rb
vedeu-0.6.14 lib/vedeu/output/output.rb