local function floor (var)
local decimal = var % 1
local var = decimal < 0.3 and var - decimal or decimal > 0.7 and math.ceil(var) or var - decimal + 0.5
return var - var % 1, var % 1 == 0.5 and true or false
end
loadingbar.animate = function (self)
local half = '\149'
local nFiled, bHalf = floor(self.percent * self.size * 0.01)
self.term.setCursorPos(self.cursorPos[1], self.cursorPos[2])
for i = 1, nFiled do
self.term.blit(' ', 'f', self.fgCol)
end
if bHalf then
term.blit(half, self.fgCol, self.bgCol)
nFiled = nFiled + 1
end
for _ = nFiled + 1, self.size do
self.term.blit(' ', '0', self.bgCol)
end
end
createLoadingbar = function (term, x, y, size, fgCol, bgCol)
return setmetatable({
term = term or error('term expected'),
size = size or 5,
cursorPos = x and y and {x, y} or {term.getCursorPos()},
fgCol = fgCol or 'f',
bgCol = bgCol or '0',
timeout = 0,
percent = 0
}, mt)
end
I coded, because i was bored, a (maybe bad coded) progress bar constructor.
It isn't full tested yet, but it should work. Maybe, it inspires you, how to code yourself one.
I hope I could help you =)
Sewbacca