class ProgressBar
- ProgressBar
- Reference
- Object
Overview
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
# => [##########]
Defined in:
progress_bar.crConstant Summary
-
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 Method Summary
- #complete
- #complete?
- #count : Int32
-
#init
initiate progressbar => print empty bar of specified length
-
#progress(by add = 1)
progresses the bar by a specified amount
-
#reset
resetting the progress bar (emptying it)
- #set(count : Int32)
- #set?(count : Int32)
-
#tick
increment progress by one
-
#with_progress(&)
yields and returns block return value resetting the progress bar after completion
Constructor Detail
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 Method Detail
yields and returns block return value resetting the progress bar after completion