Sha256: 9d18ca24972ccaba7c5c2164067338236c7d95182d2c4602e0d01b02d818d847

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

module Vedeu

  # Refreshes the terminal.
  #
  # @api private
  module Refresh

    include Common
    extend self

    # System event to refresh all registered interfaces.
    Vedeu.event(:_refresh_) { Vedeu::Refresh.all }

    # Refresh all registered interfaces.
    #
    # @return [Array]
    def all
      Vedeu::Interfaces.registered.each { |name| by_name(name) }
    end

    # Refresh the interface which is currently focussed.
    #
    # @return [|NoInterfacesDefined]
    def by_focus
      by_name(Focus.current)
    end

    # Refresh an interface, or collection of interfaces belonging to a group.
    #
    # @param group_name [String] The name of the group to be refreshed.
    # @return [Array|GroupNotFound] A collection of the names of interfaces
    #   refreshed, or an exception if the group was not found.
    def by_group(group_name)
      Groups.find(group_name).each { |name| by_name(name) }
    end

    # Refresh an interface by name.
    #
    # @param name [String] The name of the interface to be refreshed.
    # @return [Array|BufferNotFound]
    def by_name(name)
      Compositor.render(name)
    end

    # Register a refresh event for an interface or group of interfaces by name.
    # When the event is called, the interface, or all interfaces belonging to
    # the group with this name will be refreshed.
    #
    # @param type [Symbol]
    # @param name [String]
    # @param delay [Float]
    # @return [Boolean]
    def register_event(type, name, delay = 0.0)
      event = if type == :by_group
        "_refresh_group_#{name}_".to_sym

      else
        "_refresh_#{name}_".to_sym

      end

      return false if Events.registered?(event)

      Events.add(event, { delay: delay }) { Refresh.send(type, name) }

      true
    end

  end # Refresh

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.2.10 lib/vedeu/support/refresh.rb
vedeu-0.2.9 lib/vedeu/support/refresh.rb
vedeu-0.2.8 lib/vedeu/support/refresh.rb
vedeu-0.2.7 lib/vedeu/support/refresh.rb
vedeu-0.2.6 lib/vedeu/support/refresh.rb