xKevinn

Progress Bar and Percent

Sep 27th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. component = require("component")
  2. term = require("term")
  3. c = component.gt_machine
  4.  
  5. component.gpu.setResolution(12,2)
  6.  
  7. while true do
  8.   os.sleep(0.25)
  9.   p = tonumber(c.getWorkProgress())
  10.   pm = tonumber(c.getWorkMaxProgress())
  11.   pc = math.floor(((p / pm) * 100) + 0.5)
  12.   if pc < 10 then
  13.     prog = "[          ]"
  14.   elseif pc >= 10 and pc < 20 then
  15.     prog = "[#         ]"
  16.   elseif pc >= 20 and pc < 30 then
  17.     prog = "[##        ]"
  18.   elseif pc >= 30 and pc < 40 then
  19.     prog = "[###       ]"
  20.   elseif pc >= 40 and pc < 50 then
  21.     prog = "[####      ]"
  22.   elseif pc >= 50 and pc < 60 then
  23.     prog = "[#####     ]"
  24.   elseif pc >= 60 and pc < 70 then
  25.     prog = "[######    ]"
  26.   elseif pc >= 70 and pc < 80 then
  27.     prog = "[#######   ]"
  28.   elseif pc >= 80 and pc < 90 then
  29.     prog = "[########  ]"
  30.   elseif pc >= 90 and pc < 100 then
  31.     prog = "[######### ]"
  32.   elseif pc == 100 then
  33.     prog = "[##########]"
  34.   end
  35.  
  36.   term.clear()
  37.   term.setCursor(6,1)
  38.   if pm == 0 then
  39.     term.setCursor(2,1)
  40.     term.write("Waiting...")
  41.   else
  42.     term.write(pc.."%")
  43.     term.setCursor(1,2)
  44.     term.write(prog)
  45.   end
  46. end
Add Comment
Please, Sign In to add comment