ProgressBar
Inherits Reference / Object
Have a long running command? Keep your users updated on the progress by displaying a progress bar
require "progress_bar.cr/progress_bar"
# simple
pb = ProgressBar.new
# print empty progress bar
pb.init
10.times do
sleep 0.1 # very time intense!
pb.tick # increase bar progress by 1
end
# => [##########]
Constants
CHARSETS = {
default: [" ", "#"],
line: [" ", "-"],
equals: [" ", "="],
bar: ["▒", "█"],
}
Constructors
new(ticks : Int32 = 10, charset : Symbol = :default, chars : Array(String) = [] of String, show_percentage : Bool = false, completion_message : Nil | String = nil)
initializes the progress bar with necessary information:
ticks = 10 # number of increments (bar size)
charset = :default # can also be :line, :equals, :bar (what characters to use for bar)
chars = [] # you can give two custom strings [empty_string, filled_string] to print instead of using a predefined charset
completion_message: nil # string to display after loading is done
ProgressBar.new(chars: [" ", "x"])
Instance methods
complete
Sourcecomplete?
Sourcecount
Sourceset(count : Int32)
Sourceset?(count : Int32)
Sourcewith_progress
yields and returns block return value resetting the progress bar after completion