From bc41cc3a244bf47679d1c47d17006a2aa7356bc8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 29 Jan 2019 16:16:45 -0800 Subject: Switched to have colors/utf8 be optional, fixed an issue with currently running files leaking when errors occurred (causing spurious circular import errors), and improved tutorial. --- lib/progressbar/init.nom | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'lib/progressbar/init.nom') diff --git a/lib/progressbar/init.nom b/lib/progressbar/init.nom index 98efe11..b3fb3a2 100644 --- a/lib/progressbar/init.nom +++ b/lib/progressbar/init.nom @@ -1,12 +1,25 @@ #!/usr/bin/env nomsu -V6.15.13.8 # A progress bar - +use "consolecolor" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +test: + assume (0 / 1 progress bar) + assume (10 wide 0.5 progress bar) + external: ($x / $w progress bar) means: $x = ($x clamped between 0 and $w) - $bits = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"] - $middle = ("" if ($x == $w) else $bits.(1 + (floor ((#$bits) * ($x mod 1))))) - return (" - \027[0m[\027[32;40m\($bits, last, rep (floor $x))\$middle\(" ", rep ($w - ((floor $x) + 1)))\027[0m] - ") + if $(COLOR ENABLED): + $bits = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"] + $middle = ("" if ($x == $w) else $bits.(1 + (floor ((#$bits) * ($x mod 1))))) + return (" + \(reset color)[\(green)\($bits, last, rep (floor $x))\$middle\(" ", rep ($w - ((floor $x) + 1)))\(reset color)] + ") + ..else: + # Probably not unicode support either: + return (" + [\("#", rep ($x, rounded down))\("-", rep ($w - ($x, rounded down)))] + ") ($w wide $ progress bar) means (($ * $w) / $w progress bar) -- cgit v1.2.3