Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function tdlMain(arg)
- if not fs.exists("button") then
- shell.run("pastebin get LTDZZZEJ button")
- end
- if not fs.exists("dsa") then
- shell.run("pastebin get J9mhuXuf dsa")
- end
- local b = require("button").terminal
- local data = require("dsa")
- local items = {}
- local startsize = {term.getSize()}
- local maxitems = startsize[2] - 5
- local updaterate = 0.1
- if not fs.exists("tdl.data") then
- fs.open("tdl.data", "w").close()
- end
- for i = 1, maxitems do
- items[i] = data.getLine("tdl.data", i)
- if items[i] == "" then
- items[i] = nil
- break
- end
- end
- local function centerWrite(text, customY)
- local width = term.getSize()
- term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), customY)
- term.write(text)
- end
- term.setCursorPos(1, 1)
- local function tdl()
- term.setTextColor(colors.white)
- centerWrite("To do list", 1)
- term.setTextColor(colors.gray)
- centerWrite(string.rep("-", startsize[1] + 1), 2)
- term.setTextColor(colors.cyan)
- end
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- tdl()
- if click ~= nil then
- do
- local width = term.getSize()
- local text = ">create items<"
- if b.button(1, click, math.ceil((width / 2) - (text:len() / 2)), 3, text) then
- centerWrite("make new item", 4)
- centerWrite("please enter name", 5)
- local count = 1
- for i = 1, #items do
- count = count + 1
- end
- term.setCursorPos(1, 6)
- items[count] = read()
- data.writeLine("tdl.data", count, items[count])
- end
- term.setTextColor(colors.white)
- end
- for k, v in ipairs(items) do
- local width = term.getSize()
- local text = data.getLine("tdl.data", k)
- if text:gsub(string.sub(text, 2), "") == "\127" then
- term.setTextColor(colors.orange)
- end
- if b.button(1, click, math.ceil((width / 2) - (text:len() / 2)), k + 4, text:gsub("\127", "")) then
- items[k] = nil
- items = data.ser(items)
- fs.open("tdl.data", "w").close()
- for i = 1, #items do
- data.writeLine("tdl.data", i, items[i])
- end
- end
- term.setTextColor(colors.white)
- end
- for k, v in ipairs(items) do
- local width = term.getSize()
- local text = data.getLine("tdl.data", k)
- if text:gsub(string.sub(text, 2), "") == "\127" then
- term.setTextColor(colors.orange)
- end
- if b.button(2, click, math.ceil((width / 2) - (text:len() / 2)), k + 4, text:gsub("\127", "")) then
- if text:gsub(string.sub(text, 2), "") ~= "\127" then
- data.writeLine("tdl.data", k, "\127" .. text)
- else
- data.writeLine("tdl.data", k, text:gsub("\127", ""))
- end
- end
- term.setTextColor(colors.white)
- end
- local scale = {term.getSize()}
- term.setTextColor(colors.red)
- if b.button(1, click, 1, scale[2], ">exit<") then
- term.clear()
- term.setCursorPos(1, 1)
- break
- end
- term.setTextColor(colors.yellow)
- if b.button(1, click, scale[1] - 11, scale[2], ">update tdl<") then
- shell.run("rename tdl tdl.old")
- shell.run("pastebin get yU5gzMZ1 tdl")
- shell.run("rm tdl.old")
- shell.run("tdl")
- break
- end
- if b.button(1, click, scale[1] - 4, 1, ">\16\b<") then
- shell.run("edit tdl.data")
- end
- end
- click = b.timetouch(updaterate)
- end
- end
- local arg = ...
- if arg == "update" then
- shell.run("rename tdl tdl.old")
- shell.run("pastebin get yU5gzMZ1 tdl")
- shell.run("rm tdl.old")
- shell.run("tdl")
- end
- local ok, err = pcall(tdlMain)
- if not ok then
- term.clear()
- term.setCursorPos(1, 1)
- print("to do list has crashed\nreason:\n" .. err)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement