Sha256: 087889e798e59e152ba602f6b2f8a99ca9eb71b7d4e599c373ccfd8706b7cd84

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module Vedeu

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

    class << self

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

    end

    # Return a new instance of Vedeu::Clear.
    #
    # @param interface [Interface]
    # @return [Vedeu::Clear]
    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
      @clear ||= Array.new(interface.height) do |iy|
        Array.new(interface.width) do |ix|
          Vedeu::Char.new({ value:    ' ',
                            colour:   interface.colour,
                            style:    interface.style,
                            position: Vedeu::IndexPosition[iy, ix, interface.top, interface.left] })
        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::FileRenderer.render(clear)

      Vedeu::TerminalRenderer.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.11 lib/vedeu/output/clear.rb
vedeu-0.4.10 lib/vedeu/output/clear.rb