class ProgressBar

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.cr

Constant Summary

CHARSETS = {default: [" ", "#"], line: [" ", "-"], equals: [" ", "="], bar: ["▒", "█"]}

Constructors

Instance Method Summary

Constructor Detail

def self.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"])


[View source]

Instance Method Detail

def complete #

[View source]
def complete? #

[View source]
def count : Int32 #

[View source]
def init #

initiate progressbar => print empty bar of specified length


[View source]
def progress(by add = 1) #

progresses the bar by a specified amount


[View source]
def reset #

resetting the progress bar (emptying it)


[View source]
def set(count : Int32) #

[View source]
def set?(count : Int32) #

[View source]
def tick #

increment progress by one


[View source]
def with_progress(&) #

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


[View source]