Skip to content

Instantly share code, notes, and snippets.

@koonix
Created February 13, 2022 12:47
Show Gist options
  • Save koonix/03b73f0f281dffe6a289bad52b5f9b75 to your computer and use it in GitHub Desktop.
Save koonix/03b73f0f281dffe6a289bad52b5f9b75 to your computer and use it in GitHub Desktop.
Unicode Progress Bar in Lua.
-- 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