9551

simple to do list

Jul 1st, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. if not fs.exists("button") then
  2.     shell.run("pastebin get LTDZZZEJ button")
  3. end
  4. if not fs.exists("dsa") then
  5.     shell.run("pastebin get J9mhuXuf dsa")
  6. end
  7. local m = peripheral.find("monitor")
  8. local b = require("button").monitor
  9. local data = require("dsa")
  10. local items = {}
  11. local startsize = {m.getSize()}
  12. local maxitems = startsize[2] - 3
  13. local updaterate = 0.5
  14. if not fs.exists("tdl.data") then
  15.     fs.open("tdl.data", "w").close()
  16. end
  17. for i = 1, maxitems do
  18.     items[i] = data.getLine("tdl.data", i)
  19.     if items[i] == "" then
  20.         items[i] = nil
  21.         break
  22.     end
  23. end
  24. local function centerWrite(text, customY, term)
  25.     local width = term.getSize()
  26.     term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), customY)
  27.     term.write(text)
  28. end
  29. m.clear()
  30. m.setCursorPos(1, 1)
  31. local function tdl()
  32.     centerWrite("To do list", 1, m)
  33.     centerWrite("------------------", 2, m)
  34. end
  35. while true do
  36.     local click = b.timetouch(updaterate, peripheral.getName(m))
  37.     m.clear()
  38.     tdl()
  39.     do
  40.         local width = m.getSize()
  41.         local text = ">create items<"
  42.         if b.button("top", click, math.ceil((width / 2) - (text:len() / 2)), 3, text) then
  43.             centerWrite("create new item in", 4, m)
  44.             centerWrite("computer terminal", 5, m)
  45.             local count = 1
  46.             for i = 1, #items do
  47.                 count = count + 1
  48.             end
  49.             items[count] = read()
  50.             data.writeLine("tdl.data", count, items[count])
  51.         end
  52.     end
  53.     for k, v in ipairs(items) do
  54.         local text = v
  55.         local width = m.getSize()
  56.         if b.button("top", click, math.ceil((width / 2) - (text:len() / 2)), k + 3, text) then
  57.             items[k] = nil
  58.             items = data.ser(items)
  59.             fs.open("tdl.data", "w").close()
  60.             for i = 1, #items do
  61.                 data.writeLine("tdl.data", i, items[i])
  62.             end
  63.         end
  64.     end
  65. end
  66.  
Add Comment
Please, Sign In to add comment