class

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"])

Source

Instance methods

complete
Source
complete?
Source
count
Source
init

initiate progressbar => print empty bar of specified length

Source
progress(by add = 1)

progresses the bar by a specified amount

Source
reset

resetting the progress bar (emptying it)

Source
set(count : Int32)
Source
set?(count : Int32)
Source
tick

increment progress by one

Source
with_progress

yields and returns block return value resetting the progress bar after completion

Source