Sha256: 07a1a013366926e13c2edf416feffb7034e13979e581508d009470a639f3005c

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

# frozen_string_literal: true

module Pcli
  class SimpleSpinnerBar
    def self.start(template, output)
      new(template, output).tap(&:start)
    end

    def initialize(template, output)
      @template = template
      @spinner = TTY::Spinner.new(
        '[:spinner] :template',
        format: :dots,
        interval: 20,
        output: output
      )
    end

    def start
      spinner.update(template: template)
      spinner.auto_spin
    end

    def success(new_template = false)
      spinner.update(template: new_template) if new_template
      spinner.success
    end

    def failure(new_template = false)
      spinner.update(template: new_template) if new_template
      spinner.error(Pl.red('(failed)'))
    end

    private

    attr_reader :template, :spinner
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcli-0.1.1 lib/pcli/simple_spinner_bar.rb
pcli-0.1.0 lib/pcli/simple_spinner_bar.rb