Sha256: 6a5bce8ac570d0b4a5934aed5bfab5cbc65ca29e2fd09b4b67c8544a5a685b38

Contents?: true

Size: 1.78 KB

Versions: 18

Compression:

Stored size: 1.78 KB

Contents

class Infobar::Spinner
  PREDEFINED = {
    pipe:      %w[ | / – \\ ],
    arrow:     %w[ ↑ ↗ → ↘ ↓ ↙ ← ↖ ],
    bar1:      %w[ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ ],
    bar2:      %w[ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ▎ ▍ ▌ ▋ ▊ ▉ ],
    braille7:  %w[ ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷ ],
    braille1:  %w[ ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈ ],
    square1:   %w[ ▖ ▘ ▝ ▗ ],
    square2:   %w[ ◰ ◳ ◲ ◱ ],
    tetris:    %w[ ▌ ▀ ▐▄ ],
    eyes:      %w[ ◡◡ ⊙⊙ ◠◠ ],
    corners:   %w[ ┤ ┘ ┴ └ ├ ┌ ┬ ┐ ],
    triangle:  %w[ ◢ ◣ ◤ ◥ ],
    circle1:   %w[ ◴ ◷ ◶ ◵ ],
    circle2:   %w[ ◐ ◓ ◑ ◒ ],
    circle3:   %w[ ◜ ◝ ◞ ◟ ],
    cross:     %w[ + × ],
    cylon:     [ '●  ', ' ● ', '  ●', ' ● ' ],
    pacman:    [ 'ᗧ∙∙∙∙●', ' O∙∙∙●', '  ᗧ∙∙●','   O∙●', '    ᗧ●', 'ᗣ    O', ' ᗣ   ᗤ', ' ᗣ  O ', ' ᗣ ᗤ  ', ' ᗣO   ', ' ᗤ    ', 'O ∞   ', 'ᗧ   ∞ ', 'O     ' ],
    asteroids: [ 'ᐊ  ◍', 'ᐃ  ◍', 'ᐓ  ◍', 'ᐅ· ◍', 'ᐅ ·◍', 'ᐅ  ○', 'ᐅ  ◌', 'ᐁ   ' ],
    clock:     %w[ 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧 ],
    hourglass: %w[ ⏳ ⌛ ],
  }

  def initialize(frames = nil)
    @frames =
      case frames
      when Array
        frames
      when Symbol
        PREDEFINED.fetch(frames) do
          |k| raise KeyError, "frames #{k} not predefined"
        end
      when nil
        PREDEFINED[:pipe]
      end
  end

  def spin(count)
    @string =
      if count == :random
        @frames[rand(@frames.size)]
      else
        @frames[count % @frames.size]
      end
    self
  end

  def to_s
    @string
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
infobar-0.8.1 lib/infobar/spinner.rb
infobar-0.8.0 lib/infobar/spinner.rb
infobar-0.7.4 lib/infobar/spinner.rb
infobar-0.7.2 lib/infobar/spinner.rb
infobar-0.7.1 lib/infobar/spinner.rb
infobar-0.7.0 lib/infobar/spinner.rb
infobar-0.6.2 lib/infobar/spinner.rb
infobar-0.6.1 lib/infobar/spinner.rb
infobar-0.6.0 lib/infobar/spinner.rb
infobar-0.5.1 lib/infobar/spinner.rb
infobar-0.5.0 lib/infobar/spinner.rb
infobar-0.4.0 lib/infobar/spinner.rb
infobar-0.3.0 lib/infobar/spinner.rb
infobar-0.2.0 lib/infobar/spinner.rb
infobar-0.1.1 lib/infobar/spinner.rb
infobar-0.1.0 lib/infobar/spinner.rb
infobar-0.0.7 lib/infobar/spinner.rb
infobar-0.0.6 lib/infobar/spinner.rb