Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "1.3"
- local todos = { }
- local h = true
- local mon = peripheral.wrap("right")
- function load(name)
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- local function centerText(text, object)
- if object == nil then
- object = term
- end
- local x,y = object.getSize()
- local x2,y2 = object.getCursorPos()
- object.setCursorPos(math.floor((x / 2) - (string.len(text) / 2)), y2)
- object.write(text)
- end
- function create(x,y,width,height,color,mon)
- mon.setCursorPos(x,y)
- for j = 0, height do
- mon.setCursorPos(x,y+j)
- for i = 0,width do
- mon.setBackgroundColor(color)
- mon.write(" ")
- end
- end
- end
- function clearAll(mon, color)
- local w,h = mon.getSize()
- for i = 0,h do
- for j = 0, w do
- mon.setCursorPos(1+j,1+i)
- mon.setBackgroundColor(color)
- mon.write(" ")
- end
- end
- end
- function reload(object)
- if object == nil then
- object = term
- end
- if fs.exists("saves/todos") then
- todos = load("saves/todos")
- background(object)
- for i = 1, tablelength(todos) do
- object.setCursorPos(1,3+i)
- centerText(i..". "..todos[i], object)
- end
- end
- end
- function background(object)
- if object == nil then
- object = term
- end
- local x,y = object.getSize()
- create(x/2-20,3,40,tablelength(todos)+1,colors.black,object)
- end
- clearAll(term, colors.blue)
- clearAll(mon, colors.blue)
- mon.clear()
- term.clear()
- background(mon)
- background(term)
- reload(term)
- reload(mon)
- while true do
- mon.setBackgroundColor(colors.blue)
- term.setBackgroundColor(colors.blue)
- mon.setCursorPos(1,1)
- term.setCursorPos(1,1)
- centerText("To Do list v.".. version)
- centerText("To Do list v.".. version, mon)
- term.setCursorPos(1,2)
- centerText("To Do:")
- message = read()
- if message == "delete" then
- clearAll(term, colors.blue)
- clearAll(mon, colors.blue)
- mon.clear()
- term.clear()
- background(mon)
- background(term)
- reload(term)
- reload(mon)
- while h do
- mon.setBackgroundColor(colors.blue)
- term.setBackgroundColor(colors.blue)
- mon.setCursorPos(1,1)
- term.setCursorPos(1,1)
- centerText("To Do list v.".. version)
- centerText("To Do list v.".. version, mon)
- term.setCursorPos(1,2)
- term.clearLine()
- term.setTextColor(colors.red)
- centerText("Delete:")
- delete = read()
- if delete == "" then
- h = false
- term.clearLine()
- else
- h = true
- todos = load("saves/todos")
- table.remove(todos, tonumber(delete))
- save(todos, "saves/todos")
- end
- term.setTextColor(colors.white)
- term.clear()
- mon.clear()
- reload(term)
- reload(mon)
- end
- elseif message == "change" then
- clearAll(term, colors.blue)
- clearAll(mon, colors.blue)
- mon.clear()
- term.clear()
- background(mon)
- background(term)
- reload(term)
- reload(mon)
- mon.setBackgroundColor(colors.blue)
- term.setBackgroundColor(colors.blue)
- mon.setCursorPos(1,1)
- term.setCursorPos(1,1)
- centerText("To Do list v.".. version)
- centerText("To Do list v.".. version, mon)
- term.setCursorPos(1,2)
- term.clearLine()
- term.setTextColor(colors.orange)
- centerText("Change:")
- changenum = tonumber(read())
- if change == "" then
- term.setCursorPos(1,2)
- term.clearLine()
- else
- term.setCursorPos(1,2)
- term.clearLine()
- centerText("To:")
- tonum = tonumber(read())
- end
- todos = load("saves/todos")
- to = todos[tonum]
- change = todos[changenum]
- todos[tonum] = change
- todos[changenum] = to
- save(todos, "saves/todos")
- term.setTextColor(colors.white)
- term.clear()
- mon.clear()
- reload(term)
- reload(mon)
- else
- clearAll(term, colors.blue)
- clearAll(mon, colors.blue)
- table.insert(todos, message)
- fs.makeDir("saves")
- save(todos, "saves/todos")
- term.clear()
- mon.clear()
- reload(term)
- reload(mon)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment