From c65b97399e529efc3c1eb9b4cf4afe4053591456 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Fri, 5 Aug 2022 08:46:10 +0100 Subject: [PATCH] =?UTF-8?q?Allow=20selecting=20pre-written=20BarGlyph?= =?UTF-8?q?=E2=80=99s=20by=20a=20symbol=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds two bar glyph sequences based on Gray codes on quarter-blocks and braille characters in Unicode. --- src/ProgressMeter.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ProgressMeter.jl b/src/ProgressMeter.jl index 7c8ad5f..5e2fae6 100644 --- a/src/ProgressMeter.jl +++ b/src/ProgressMeter.jl @@ -46,6 +46,31 @@ function BarGlyphs(s::AbstractString) return BarGlyphs(glyphs...) end +""" 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 == :blocks + BarGlyphs('│', '█', collect(" ▗▐▝▞▖▌▘▀▜▚▙▄▟▛"), ' ', '│') + else + error("Unrecognized default BarGlyphs name: $which") + end +end + """ `prog = Progress(n; dt=0.1, desc="Progress: ", color=:green, output=stderr, barlen=tty_width(desc), start=0)` creates a progress meter for a