Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/ProgressMeter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ function BarGlyphs(s::AbstractString)
end
const defaultglyphs = BarGlyphs('|','█', Sys.iswindows() ? '█' : ['▏','▎','▍','▌','▋','▊','▉'],' ','|',)

""" BarGlyphs(which::Symbol)

- `:braille`, a gray code on Braille characters, approximately sorted by weight
- `:blocks`, a gray code on unicode quarter-blocks

Demonstration:
```
n=1000; progress = Progress(n, barglyphs=BarGlyphs(:blocks), showspeed=true, barlen=20, dt=0)
for i=1:n; sleep(1/60); next!(progress, ignore_predictor=true); end
```
"""
function BarGlyphs(which::Symbol)
if which == :braille
# Braille gray code in order of approximately (±1) increasing
# weight. See Knuth volume 4A. The second-last character used
# to be ⣿, but it is deleted to make the sequence loop: it’s
# not a valid Gray code.
BarGlyphs('│', '⣿', collect(" ⠁⠃⠂⠆⠄⠌⠈⠘⠐⠰⠠⡠⡀⣀⢀⢐⢘⢈⢨⢠⢢⢂⢃⢁⢅⢄⣄⡄⡆⡂⡃⡁⡑⡐⡘⡈⡨⠨⠬⠤⠦⠢⠣⠡⠱⠑⠕⠔⠖⠒⠚⠊⠋⠉⠍⠅⠇⠏⠎⠞⠜⠝⠙⠛⠓⠳⠲⠶⠴⠵⠥⠭⠩⠫⠪⠺⠸⡸⡰⡱⡡⡩⡉⡋⡊⡚⡒⡲⡢⡦⡤⡬⡌⡜⡔⡕⡅⣅⣁⣃⣂⣆⢆⢦⢤⢥⢡⣡⣠⣨⣈⣌⢌⢍⢉⢋⢊⢚⢒⢲⢰⣰⣐⣔⢔⢕⢑⣑⣱⢱⢳⢓⢛⢙⢝⢜⢼⢴⢶⢖⣖⣒⣚⣘⣸⢸⢺⢪⢮⢎⣎⣊⣋⣉⣩⢩⢭⢬⣬⣤⣦⣢⣣⢣⢧⢇⣇⡇⡏⡍⡭⡥⡵⡴⡶⡖⡞⡎⡮⡪⡫⡣⡳⡓⡛⡙⡹⠹⠽⠼⠾⠮⠯⠧⠷⠗⠟⠿⠻⡻⡺⡾⡼⡽⡝⡟⡗⡷⡧⣧⣥⣭⣍⣏⢏⢯⢫⣫⣪⣺⣲⣶⣴⣼⣜⣞⢞⢟⢗⢷⢵⢽⢹⣹⣙⣛⣓⣗⣕⣝⣽⣵⣷⣳⣻⢻⢿⢾⣾⣮⣯⡯⡿⣟"), ' ', '│')
elseif which == :braille_debruijn
BarGlyphs('│', '⣿', collect("⠀⢀⠠⠐⠈⠁⠂⠄⣀⢠⠰⠘⠉⠃⠆⣄⡠⢐⠨⠑⠊⠅⡂⢄⣠⢰⠸⠙⠋⠇⣆⡤⡐⢈⠡⠒⠌⡁⢂⠤⣐⢨⠱⠚⠍⡃⢆⣤⡰⢘⠩⠓⠎⡅⣂⢤⣰⢸⠹⠛⠏⣇⡦⡔⡈⢁⠢⠔⣈⢡⠲⠜⡉⢃⠦⣔⡨⢑⠪⠕⡊⢅⡢⢔⣨⢱⠺⠝⡋⢇⣦⡴⡘⢉⠣⠖⡌⣁⢢⠴⣘⢩⠳⠞⡍⣃⢦⣴⡸⢙⠫⠗⡎⣅⣢⢴⣸⢹⠻⠟⣏⡧⡖⣌⡡⢒⠬⡑⢊⠥⡒⢌⣡⢲⠼⡙⢋⠧⣖⡬⣑⢪⠵⡚⢍⡣⢖⣬⡱⢚⠭⡓⢎⡥⣒⢬⣱⢺⠽⡛⢏⣧⡶⡜⣉⢣⠶⣜⡩⢓⠮⡕
⢥⡲⢜⣩⢳⠾⡝⣋⢧⣶⡼⣙⢫⠷⡞⣍⣣⢶⣼⡹⢛⠯⡗⣎⣥⣲⢼⣹⢻⠿⣟⡯⣗⡮⣕⡪⢕⣪⢵⡺⢝⡫⢗⣮⡵⣚⢭⡳⢞⡭⣓⢮⣵⣺⢽⡻⢟⣯⡷⣞⣭⣳⢾⡽⣛⢯⣷⡾⣝⣫⢷⣾⣽⣻⢿"), ' ', '│')
elseif which == :blocks
BarGlyphs('│', '█', collect(" ▗▐▝▞▖▌▘▀▜▚▙▄▟▛"), ' ', '│')
elseif which == :blocks_debruijn
BarGlyphs('│', '█', collect(" ▗▝▘▄▐▀▙▞▚▟▜"), ' ', '│')
else
error("Unrecognized default BarGlyphs name: $which")
end
end

# Internal struct for holding common properties and internals for progress meters
Base.@kwdef mutable struct ProgressCore
color::Symbol = :green # color of the meter
Expand Down
16 changes: 16 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,22 @@ println("Testing custom bar glyphs")
testfunc14("[=> ]")
@test_throws ErrorException testfunc14("gklelt")

function testfunc14a(barglyphs::Symbol)
n = 30
p = Progress(n, barglyphs=BarGlyphs(barglyphs))
for i in 1:n
sleep(0.05)
next!(p)
end
finish!(p)
end

testfunc14a(:blocks)
testfunc14a(:braille)
testfunc14a(:blocks_debruijn)
testfunc14a(:braille_debruijn)
@test_throws ErrorException testfunc14a(:xxyyzz)

# Threshold-based progress reports
println("Testing threshold-based progress")
prog = ProgressThresh(1e-5; desc="Minimizing:")
Expand Down
Loading