TheSommer

Task Manager

Nov 9th, 2020 (edited)
1,270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. SIDE = "top"
  2.  
  3. local monitor = peripheral.wrap(SIDE)
  4. local tasks = {}
  5.  
  6. local function centerText(text)
  7.   x,y = monitor.getSize()
  8.   x1,y1 = monitor.getCursorPos()
  9.   monitor.setCursorPos((math.floor(x/2) - (math.floor(#text/2))) + 1, y1) -- this is why we cant have nice things
  10.   monitor.write(text)
  11. end
  12.  
  13. local function UpdateMonitor()
  14.   monitor.setCursorPos(0, 3)
  15.   monitor.clear()
  16.   monitor.setTextColor(colors.orange)
  17.   centerText("Task Manager")
  18.  
  19.   if #tasks > 0 then
  20.     cursorY = 5
  21.     for i=1, #tasks, 1 do
  22.       if tasks[i].priority == 1 then
  23.         monitor.setTextColor(colors.red)
  24.       elseif tasks[i].priority == 2 then
  25.         monitor.setTextColor(colors.yellow)
  26.       elseif tasks[i].priority == 3 then
  27.         monitor.setTextColor(colors.green)
  28.       else
  29.         monitor.setTextColor(colors.white)
  30.       end
  31.  
  32.       monitor.setCursorPos(0, cursorY)
  33.       centerText(tasks[i].task)
  34.       cursorY = cursorY + 1
  35.     end
  36.   end
  37. end
  38.  
  39. local function AddTask(task, priority)
  40.   table.insert(tasks, {task=task, priority=priority})
  41.   UpdateMonitor()
  42. end
  43.  
  44. UpdateMonitor()
  45. sleep(2)
  46. AddTask("Aerotheum Automation", 1)
  47. sleep(2)
  48. AddTask("Petrotheum Automation", 1)
  49. sleep(2)
  50. AddTask("Task Manager Add/Remove", 3)
Advertisement
Add Comment
Please, Sign In to add comment