Advertisement
dadragon84

progress bar

Feb 25th, 2025
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. function gen(pTable, hidden)
  2.     local termWidth, termHeight = term.getSize()
  3.     local ogTerm = term.current()
  4.     local bgWindow = window.create(ogTerm, 1, 1, termWidth, termHeight, false)
  5.  
  6.     -- All customizable values.
  7.     local barWidth = math.floor(termWidth*.75)
  8.     local fullChar = " "
  9.     local emptyChar = "\143"
  10.     local bg = "f"
  11.     local fg = "0"
  12.  
  13.     -- Draws the empty progress bar.
  14.     local mouseX, mouseY = term.getCursorPos()
  15.     term.setCursorPos(termWidth/2-barWidth/2, mouseY)
  16.     term.blit(emptyChar:rep(barWidth), bg:rep(barWidth), fg:rep(barWidth))
  17.  
  18.     -- Iterates through the table and performs functions.
  19.     for key, value in pairs(pTable) do
  20.         if hidden then term.redirect(bgWindow) end
  21.         value()
  22.         term.redirect(ogTerm)
  23.     -- Draws 'full characters' to the progress bar as the action finishes.
  24.         term.setCursorPos(termWidth/2-barWidth/2, mouseY)
  25.         term.blit(fullChar:rep(math.floor(key / #pTable * barWidth)), bg:rep(math.floor(key / #pTable * barWidth)), fg:rep(math.floor(key / #pTable * barWidth)))
  26.     end
  27.     term.setCursorPos(mouseX, mouseY+1)
  28. end
  29.  
  30. return gen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement