Class: RubyProgress::Worm

Inherits:
Object
  • Object
show all
Includes:
WormRunner
Defined in:
lib/ruby-progress/worm.rb

Overview

Animated progress indicator with ripple effect using Unicode combining characters

Constant Summary collapse

RIPPLE_STYLES =

Worm indicator renders a small ripple/wave of characters. Use this class directly to control a running indicator, or use the CLI helpers which wrap this behavior for daemonization and command execution.

Public instance methods (selected): #generate_dots Public module mixins provide the main animation loop via WormRunner.

Ripple effect styles

Examples:

w = RubyProgress::Worm.new(length: 5, message: 'loading')
w.send(:generate_dots, 2, 1) # => "..o.."
{
  'circles' => {
    baseline: '·',  # middle dot
    midline: '●',   # black circle
    peak: '⬤' # large circle
  },
  'blocks' => {
    baseline: '▁',  # lower eighth block
    midline: '▄',   # lower half block
    peak: '█'       # full block
  },
  'geometric' => {
    baseline: '▪',  # small black square
    midline: '▫',   # small white square
    peak: '■'       # large black square
  },
  'cirlces_small' => {
    baseline: '∙',
    midline: '∙',
    peak: '●'
  },
  'arrow' => {
    baseline: '▹',
    midline: '▸',
    peak: '▶'
  },
  'balloon' => {
    baseline: '.',
    midline: 'o',
    peak: '°'
  },
  'circle_open' => {
    baseline: '○',
    midline: '●',
    peak: '○'
  }
}.freeze
SPEED_MAP =

Speed mappings

{
  'slow' => 0.5,
  'medium' => 0.2,
  'fast' => 0.1
}.freeze

Instance Method Summary collapse

Methods included from WormRunner

#animate, #animation_loop, #animation_loop_daemon_mode, #animation_loop_step, #run_daemon_mode, #run_indefinitely, #run_with_command, #stop

Constructor Details

#initialize(options = {}) ⇒ Worm

Returns a new instance of Worm.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby-progress/worm.rb', line 68

def initialize(options = {})
  # Create a new Worm indicator instance.
  #
  # @param options [Hash] configuration options
  # @option options [Integer] :length number of characters in the ripple (default 3)
  # @option options [String] :message optional label text
  # @option options [String,Symbol] :style ripple style name or custom spec
  # @return [void]
  @length = options[:length] || 3
  @message = options[:message]
  @speed = parse_speed(options[:speed] || 'medium')
  @style = parse_style(options[:style] || 'circles')
  @command = options[:command]
  @success_text = options[:success]
  @error_text = options[:error]
  @show_checkmark = options[:checkmark] || false
  @output_stdout = options[:stdout] || false
  @output_lines = options[:output_lines]
  @output_position = options[:output_position]
  @output_live = options[:stdout_live] || false
  @direction_mode = options[:direction] || :bidirectional
  @start_chars, @end_chars = RubyProgress::Utils.parse_ends(options[:ends])
  @running = false
end