Sha256: 0a05bb6d6b9a53f24c1a45162d6afd6486f2f2f8afeaba72db2d763106a6f078

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module Vedeu

  # Clears the area defined by an interface.
  #
  class Clear

    include Vedeu::CharBuilder

    # Clears the area defined by the interface.
    #
    # @return [Array|String]
    # @see #initialize
    def self.clear(interface)
      new(interface).write
    end

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

    # For each visible line of the interface, set the foreground and background
    # colours to those specified when the interface was defined, then starting
    # write space characters over the area which the interface occupies.
    #
    # @return [Array<Array<Vedeu::Char>>]
    def clear
      out = interface.height.times.inject([]) do |row, iy|
        row << interface.width.times.inject([]) do |column, ix|
          column << char_builder(' ', iy, ix)
        end
      end
    end

    # Clear the view and send to the terminal.
    #
    # @return [Array]
    def write
      Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")

      if Vedeu::Configuration.drb?
        Vedeu.trigger(:_drb_store_output_, clear)

        Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
      end

      Vedeu::Terminal.output(Vedeu::Renderer.render(clear))
    end

    private

    # @!attribute [r] interface
    # @return [Interface]
    attr_reader :interface

  end # Clear

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.4.7 lib/vedeu/output/clear.rb
vedeu-0.4.6 lib/vedeu/output/clear.rb