Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("write")
- local mon = peripheral.wrap("right")
- rednet.open("back")
- local function createList()
- todo = {}
- local h = fs.open("todoList", "r")
- while true do
- nextLine = h.readLine()
- if nextLine ~= nil then
- table.insert(todo, nextLine)
- else
- break
- end
- end
- h.close()
- end
- local acceptanceID = 47
- while true do
- createList()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Todo: ")
- mon.setCursorPos(1,3)
- for i = 1,#todo do
- --mon.write(i..". "..todo[i])
- write.center(i..", "..todo[i])
- --mon.setCursorPos(1,3+i)
- end
- id, msg = rednet.receive()
- if id == acceptanceID then
- if string.find(msg, "ADD") ~= nil then
- spot = string.find(msg, " ")+1
- newTodo = string.sub(msg, spot)
- h = fs.open("todoList","a")
- h.write(newTodo.."\n")
- h.close()
- elseif string.find(msg, "DEL") ~= nil then
- spot = string.find(msg, " ")+1
- delNum = string.sub(msg,spot)
- if tonumber(delNum) ~= nil then
- table.remove(todo,tonumber(delNum))
- h = fs.open("todoList","w")
- for i = 1,#todo do
- h.write(todo[i].."\n")
- end
- h.close()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment