Interactive Progress Bar

# encoding: utf-8 require 'progressbar' require 'concurrent' # InteractiveProgressBar class InteractiveProgressBar include Concurrent::Async # @param [String] title # @return [InteractiveProgressBar] def initialize(title = nil) @progressbar = ProgressBar.create total: nil, title: title end def start(title = nil) @progressbar.title = title unless title.nil? if block_given? async.increment yield @stop = true else async.increment end end def stop @stop = true end def increment @stop = false until @stop @progressbar.increment break if @stop sleep 0.3 end end end
use:
ipb = InteractiveProgressBar.new 'title'
ipb.start
# some code
ipb.stop

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.