grand_mind1

Todo List

Oct 4th, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. os.loadAPI("write")
  2. local mon = peripheral.wrap("right")
  3. rednet.open("back")
  4.  
  5. local function createList()
  6.   todo = {}
  7.   local h = fs.open("todoList", "r")
  8.   while true do
  9.     nextLine = h.readLine()
  10.     if nextLine ~= nil then
  11.       table.insert(todo, nextLine)
  12.     else
  13.       break
  14.     end
  15.   end
  16.   h.close()
  17. end
  18.  
  19. local acceptanceID = 47
  20.  
  21. while true do
  22.   createList()
  23.   mon.setBackgroundColor(colors.black)
  24.   mon.setTextColor(colors.white)
  25.   mon.clear()
  26.   mon.setCursorPos(1,1)
  27.   mon.write("Todo: ")
  28.   mon.setCursorPos(1,3)
  29.   for i = 1,#todo do
  30.     --mon.write(i..". "..todo[i])
  31.     write.center(i..", "..todo[i])
  32.     --mon.setCursorPos(1,3+i)
  33.   end
  34.  
  35.   id, msg = rednet.receive()
  36.   if id == acceptanceID then
  37.     if string.find(msg, "ADD") ~= nil then
  38.       spot = string.find(msg, " ")+1
  39.       newTodo = string.sub(msg, spot)
  40.       h = fs.open("todoList","a")
  41.       h.write(newTodo.."\n")
  42.       h.close()
  43.     elseif string.find(msg, "DEL") ~= nil then
  44.       spot = string.find(msg, " ")+1
  45.       delNum = string.sub(msg,spot)
  46.       if tonumber(delNum) ~= nil then
  47.         table.remove(todo,tonumber(delNum))
  48.         h = fs.open("todoList","w")
  49.         for i = 1,#todo do
  50.           h.write(todo[i].."\n")
  51.         end
  52.         h.close()
  53.       end
  54.     end
  55.   end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment