Sha256: e798b2ca0baf05fa2c784cc7751b5fffb06be3d1befa04b5f6e75ac73681f71f

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

class Infobar::Spinner
  PREDEFINED = {
    pipe:       %w[ | / – \\ ],
    arrow:      %w[ ↑ ↗ → ↘ ↓ ↙ ← ↖ ],
    bar1:       %w[ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ ],
    bar2:       %w[ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ▎ ▍ ▌ ▋ ▊ ▉ ],
    braille7:   %w[ ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷ ],
    braille1:   %w[ ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈ ],
    braille18:  %w[ ⡀ ⡄ ⡆ ⡇ ⣇ ⣧ ⣷ ⣿ ],
    braille181: %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

1 entries across 1 versions & 1 rubygems

Version Path
infobar-0.9.0 lib/infobar/spinner.rb