Skip to content

Latest commit

 

History

History
executable file
·
101 lines (78 loc) · 1.91 KB

File metadata and controls

executable file
·
101 lines (78 loc) · 1.91 KB

Display activity with ASCII spinners and progress indicators.

Sometimes you need to display activity on the text console to inform the user that the program is actually doing something. Be funny with a lot predefined sets or make you own widget to display an animation text during a long-running process in your console app.

gem install indicator

1 Add to your application Gemfile

gem 'indicator'

2 Type

bundle install
Indicator::spin do
  10.times do
    sleep 0.5
  end
end
Indicator::spin(:ondemand => true) do |spinner|
  10.times do
    spinner.spinning
    sleep 0.2
  end
end
spinner = Indicator.spinner
10.times do
  spinner.spinning
  sleep 0.2
end
spinner.clean
Indicator::spin :set => :p do
  10.times do
    sleep 0.5
  end
end

Available sets: :x :< :> :V :dots :bars :p :bqpd :- :o :O

UNICODE extra sets: :arrows :box :braile

Indicator::spin :frames => %w{ * + } do
  10.times do
    sleep 0.5
  end
end

Use int method to increment percent

Indicator::spin :count => 20 do |spin|
  10.times do
    spin.inc 2
    sleep 0.2
  end
end

Default increment is 1.

Indicator::spin :pre => "Work", :frames => ['   ', '.  ', '.. ', '...'], :count => 10, :post => ' in progress' do |spin|
  10.times do
    spin.inc
    sleep 0.2
  end
  spin.clear
end

:pre_percent and :post_percent is also available.

Indicator::spin :pre => "Work", :frames => ['   ', '.  ', '.. ', '...'], :count => 10 do |spin|
  10.times do |i|
    spin.inc
    spin.post= " in progress #{i} of 10"
    sleep 0.2
  end
end

Released under the MIT license: www.opensource.org/licenses/MIT