0.0
No commit activity in last 3 years
No release in over 3 years
Fancy console spinner that can print the current status
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
~> 10.0
>= 0

Runtime

~> 0.17
 Project Readme

SpinToWin

Simple ruby spinner that allows on the fly notifications in the format of:

:title :spinner :finished of :todo [:banner]

The bare bones spinner is

SpinToWin.with_spinner { sleep 1 }

=> \

With a title is

SpinToWin.with_spinner('Zzzz') { sleep 1 }`

=> Zzzz \

With a title and banner:

SpinToWin.with_spinner('Zzzz') { |spinner| spinner.banner('sleepy'); sleep 1 }

=> Zzzz \ [sleepy]

The title is persistent but the banner can be changed with calls to the yielded spinner

With title, banner, and todos

SpinToWin.with_spinner('Zzzz') do |spinner|
    spinner.increment_todo!(3)

    spinner.banner('snore')
    sleep 1
    spinner.increment_done!

    spinner.banner('dream')
    sleep 1
    spinner.increment_done!

    spinner.banner('wake up!')
    sleep 1
    spinner.increment_done!
end

=> Zzzz \ 3 of 3 [wake up!]

Charsets

Supports for UTF-8 chars in the spinner

  • circile: ◐ ◓ ◑ ◒
  • bar: ┤ ┘ ┴ └ ├ ┌ ┬ ┐
  • braille: ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷

The spinner charset can be set by setting the charset named parameter:

SpinToWin.with_spinner(charset: :braille) { sleep 1 }

=> ⣾

Threads

Spin to Win is built using Celluloid and was designed to be used by multiple threads. The banner can show an array of active threads.

   SpinToWin.with_spinner('Dreaming about:') do |spinner|
    threads = [
      Thread.new do
        SpinToWin.add_banner('ham')
        sleep 1
        SpinToWin.increment_done!
        SpinToWin.remove_banner('ham')
      end,
      Thread.new do
        SpinToWin.add_banner('sheep')
        sleep 2
        SpinToWin.increment_done!
        SpinToWin.remove_banner('sheep')
      end,
      Thread.new do
        SpinToWin.add_banner('socks')
        sleep 3
        SpinToWin.increment_done!
        SpinToWin.remove_banner('sock')
      end
    ]
    SpinToWin.increment_todo!(threads.size)

    threads.each(&:join)
   end

Dreaming about: \ 0 of 3 [ham|sheep|socks]

Installation

Add this line to your application's Gemfile:

gem 'spin_to_win'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spin_to_win

Usage

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/spin_to_win.