Sha256: 7b00533c4c15ff605240a407c835602829cb9d83125952f06dd5dde5aa966485

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

module Luck
class ProgressBar < Control
  attr_accessor :maximum, :value, :precap, :bar, :arrow, :blank, :postcap
  
  def initialize *args
    @maximum = 1
    @value = 0
    @precap = '['
    @bar = '='
    @arrow = '>'
    @blank = ' '
    @postcap = ']'
    super
  end
  
  def percentage
    @value.to_f / @maximum.to_f
  end
  
  def template str
    @precap, @bar, @arrow, @blank, @postcap = str.unpack 'aaaaa'
  end
  
  def redraw
    @display.place y1, x1, @precap + (@bar * (percentage * (width - @precap.size - @postcap.size)) + @arrow).ljust(width - @precap.size - @postcap.size, @blank) + @postcap
  end
end

class DoubleProgressBar < ProgressBar
  attr_accessor :maximum2, :value2, :bar2, :arrow2
  
  def initialize *args
    @maximum2 = 1
    @value2 = 0
    @bar2 = '-'
    @arrow2 = '>'
    super
  end
  
  def percentage2
    @value2.to_f / @maximum2.to_f
  end
  
  def template str
    @precap, @bar2, @arrow2, @bar, @arrow, @blank, @postcap = str.unpack 'aaaaaaa'
  end
  
  def redraw
    super
    @display.place y1, x1, @precap + (@bar2 * (percentage2 * (width - @precap.size - @postcap.size)) + @arrow2)
  end
end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
luck-0.1.5 lib/luck/progressbar.rb
luck-0.1.4 lib/luck/progressbar.rb
luck-0.1.3 lib/luck/progressbar.rb
luck-0.1.2 lib/luck/progressbar.rb
luck-0.1.1 lib/luck/progressbar.rb
luck-0.1.0 lib/luck/progressbar.rb
luck-0.0.0 lib/luck/progressbar.rb