Advertisement
Pinkishu

mt_taskswitcher

Aug 13th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1.  
  2. local taskList = nil
  3. local index = 1
  4. function getTaskList()
  5.     local list = mt.getTaskList()
  6.     local rm = nil
  7.     for i,v in ipairs(list) do
  8.         if v == "mttaskswitcher" then rm = i break end
  9.     end
  10.     if rm then table.remove(list,rm) end
  11.     taskList = list
  12.     index = math.min(index,#taskList)
  13. end
  14. getTaskList()
  15. term.setCursorBlink(false)
  16. term.clear()
  17.  
  18. function list()
  19.     term.clear()
  20.     p=1
  21.     term.setCursorPos(1,1)
  22.     for k,v in ipairs(taskList) do
  23.         term.write((index==p and "*" or " ")..v)
  24.         p=p+1
  25.         term.setCursorPos(1,p)
  26.     end
  27. end
  28. list()
  29. while true do
  30.     local ev,p1 = os.pullEvent()
  31.     if ev == "key" then
  32.         if p1 == 200 then
  33.             index = math.max(index-1,1)
  34.             list()
  35.             --up
  36.         elseif p1 == 208 then
  37.             index = math.min(index+1,#taskList)
  38.             list()
  39.             --down
  40.         elseif p1 == 28 then
  41.             mt.switchTask(taskList[index])
  42.         elseif p1 == 63 then
  43.             getTaskList()
  44.             list()
  45.         end
  46.     end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement