progress_bar.cr
Version, currently 0.3.02 versions
- 0.3.0latestJun 23, 2017
- 0.2.0not indexedFeb 29, 2024
github.com/TPei/progress_bar.cr
A ProgressBar implementation for the Crystal programming language
17 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
progress_bar.cr:
github: TPei/progress_bar.cr
version: ~> 0.3.0Then run:
shards installshard.yml
- Crystal
- no constraint declared
- License
- MIT
- Author
- tpei <tpei@users.noreply.github.com>
Dependencies
This version declares no dependencies.
README
# ProgressBar.cr [](https://travis-ci.org/TPei/progress_bar.cr)

## Installation
Add to your shard.yml
```yaml
dependencies:
progress_bar.cr:
github: tpei/progress_bar.cr
branch: master
```
and then install the library into your project with
```bash
$ crystal deps
```
## Usage
```crystal
require "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
# => [##########]
```
### Block Usage
You can use the `with_progress` block to automatically reset and clean
up the progress bar after your block is done.
Block usage will also print the completion_message, even if you don't
completely fill the bar.
```crystal
pb = ProgressBar.new(completion_message: "DONE?")
pb.with_progress do
pb.init
5.times do
sleep 0.1 # very time intense!
pb.tick # increase bar progress by 1
end
end
# => [######## ]
# => DONE?
```
### Available Methods
```crystal
pb.init # prints empty bar
pb.tick: # increases bar filling by one and reprints
pb.progress(by: 10) # increases bar by desired number
pb.set(5) # set bar to given number
pb.set?(5) # try setting bar => true / false
pb.count # get current count
pb.reset # resets the progress bar to 0, without redrawing, making it
pb.complete # prints finish message, sets bar to max
reusable
```
## initialize options
- ticks: length the bar is made for. calling #tick more often raises an
error (default is 10)
- show_percentage: true / false - whether or not to display the
percentage next to the bar
- completion_message: message to be displayed after progress reaches
100%
- charset / chars: characters to display for bar
### Characters
The bar basically consists of two different types of characters: one
signifying emptiness, one a filled state.
There are a number of different predefined char sets, that you can use:
- :default => [##### ]
- :line => [----- ]
- :equals => [===== ]
- :bar => [█████▒▒▒▒▒]
`ProgressBar.new(charset: :equals)`
You can also just hand in two characters of your own choosing:
`ProgressBar.new(chars: ["O", "X"] # => [XXXXX00000]`
## Errors
Don't exceed the tick number, will throw an exception!
```crystal
# count already == ticks
begin
pb.tick # => (ProgressExceededException)
rescue
puts "Sorry, installation taking longer than expected"
end
sleep 0.1
```
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.3.0- Tagged
- Jun 23, 2017
- Commit
44e778aeada8- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/TPei/progress_bar.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 2