Skip to content

Progress Bar

Irtsa edited this page Feb 22, 2025 · 2 revisions

Will allow you to print off a progress bar for displaying... progress. Note the loopProgressBar() function also takes a function (func) as a parameter. This allows you to pass in a function that will perform some code. The loopProgressBar() function execute the given function in a for loop the amount of times specified by the limit variable.


Source Code

__parseStyle = function(style)
    style = style.split(",")
    if style[-1] == "" then style.pop
    if style.len > 3 then return null

    if style.len > 1 then showPercent = {"true":true,"false":false}[style[1]] else showPercent = true
    if style.len > 2 then encloseBar = {"true":true,"false":false}[style[2]] else encloseBar = true
    
    return [style[0][0], style[0][1]] + [style[0].split(style[0][1])[1].to_int] + [showPercent, encloseBar]
end function
    




// Style Format : <bar><filler><notches [values between 10-100]>,(true/false to show percent),(true/false on enclosing the bar)
//   - note that both boolean values for percent and enclosing default to true if not provided.
//
// Examples: 
//     #-20,true,true     will make a bar that looks like : [####----------------] [20%]
//     # 10,true,true     will make a bar that looks like : [##          ] [20%]
//     =-20,false,true    will make a bar that looks like : [=====---------------]
//     = 20,false         will make a bar that looks like : [====                ]


progressBar = function(style, value, limit)
    style = __parseStyle(style)

    percentage = floor(value / limit * 100)
    value = style[0] * floor(value / limit * style[2])
    limit = style[1] * (style[2] - value.len)

    bar = value + limit
    if style[4] then bar = "[" + bar + "]"
    if style[3] then bar = bar + "   [" + percentage + "%]"
    
    return bar
end function



loopProgressBar = function(style, func, limit)
    v = 0
    for i in range(limit)
        func

        v = v + 1
        print(progressBar(style, v, limit), true)
    end for
end function
Clone this wiki locally