Created
February 13, 2022 12:47
-
-
Save koonix/03b73f0f281dffe6a289bad52b5f9b75 to your computer and use it in GitHub Desktop.
Unicode Progress Bar in Lua.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lua code for generating a nice unicode progress bar. | |
-- author: Ehsan Ghorbannezhad <ehsan at disroot dot org> | |
-- input percentage | |
PERCENT = 96 | |
function round(n) | |
return math.floor(n+0.5) | |
end | |
function progressbar(percent) | |
local step = 5 | |
local phases = {' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'} | |
local nwhole = math.floor(percent / step) | |
local nphase = round(percent % step / (step / (#phases - 1))) | |
local nempty = (100 / step) - (nwhole + 1) | |
local phasechar = phases[nphase+1] | |
if percent == 100 then phasechar = '' end | |
return ">" .. string.rep(phases[#phases], nwhole) .. phasechar .. | |
string.rep(' ', nempty) .. "<" | |
end | |
print(progressbar(PERCENT)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment