Sha256: 4ba63abbae77e78058e9fbafa6dd15407c12e61c106566011120f1368a6c583f

Contents?: true

Size: 665 Bytes

Versions: 2

Compression:

Stored size: 665 Bytes

Contents

module Circle
  module CLI
    class Watcher
      attr_reader :displayer, :preloader

      def initialize(&displayer)
        @displayer = displayer
        @preloader = -> {}
      end

      def to_preload(&preloader)
        @preloader = preloader
      end

      def preload
        preloader.call
      end

      def display
        displayer.call
      end

      def poll(polling_frequency)
        loop do
          display
          sleep polling_frequency
          preload
          clear
        end
      rescue Interrupt
        exit 0
      end

      private

      def clear
        system('clear') || system('cls')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
circle-cli-0.1.3 lib/circle/cli/watcher.rb
circle-cli-0.1.2 lib/circle/cli/watcher.rb