9551

Untitled

Jul 2nd, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.33 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 arg = ...
  8. if arg == "update" then
  9.     shell.run("rename tdl tdl.old")
  10.     shell.run("pastebin get yU5gzMZ1 tdl")
  11.     shell.run("rm tdl.old")
  12.     shell.run("tdl")
  13. end
  14. local b = require("button").terminal
  15. local data = require("dsa")
  16. local items = {}
  17. local startsize = {term.getSize()}
  18. local maxitems = startsize[2] - 3
  19. local updaterate = 0.1
  20. if not fs.exists("tdl.data") then
  21.     fs.open("tdl.data", "w").close()
  22. end
  23. for i = 1, maxitems do
  24.     items[i] = data.getLine("tdl.data", i)
  25.     if items[i] == "" then
  26.         items[i] = nil
  27.         break
  28.     end
  29. end
  30. local function centerWrite(text, customY)
  31.     local width = term.getSize()
  32.     term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), customY)
  33.     term.write(text)
  34. end
  35. term.setCursorPos(1, 1)
  36. local function tdl()
  37.     term.setTextColor(colors.white)
  38.     centerWrite("To do list", 1)
  39.     term.setTextColor(colors.gray)
  40.     centerWrite(string.rep("-",startsize[1]+1), 2)
  41.     term.setTextColor(colors.cyan)
  42. end
  43. while true do
  44.     local click = b.timetouch(updaterate)
  45.     term.setBackgroundColor(colors.black)
  46.     term.clear()
  47.     tdl()
  48.     do
  49.         local width = term.getSize()
  50.         local text = ">create items<"
  51.         if b.button(1, click, math.ceil((width / 2) - (text:len() / 2)), 3, text) then
  52.             centerWrite("make new item", 4)
  53.             centerWrite("please enter name", 5)
  54.             local count = 1
  55.             for i = 1, #items do
  56.                 count = count + 1
  57.             end
  58.             term.setCursorPos(1,6)
  59.             items[count] = read()
  60.             data.writeLine("tdl.data", count, items[count])
  61.         end
  62.         term.setTextColor(colors.white)
  63.     end
  64.     for k, v in ipairs(items) do
  65.         local width = term.getSize()
  66.         local inf = data.getLine("tdl.data",k)
  67.         if inf:gsub(string.sub(inf,2),"") == "!" then
  68.             text = inf:gsub("!","")
  69.             term.setTextColor(colors.orange)
  70.         else
  71.             text = inf
  72.         end
  73.         term.setCursorPos(1,1)
  74.         print(k.." "..v.." "..data.getLine("tdl.data",k))
  75.         if b.button(1, click, math.ceil((width / 2) - (text:len() / 2)), k + 4, text) then
  76.             items[k] = nil
  77.             items = data.ser(items)
  78.             fs.open("tdl.data", "w").close()
  79.             for i = 1, #items do
  80.                 data.writeLine("tdl.data", i, items[i])
  81.             end
  82.         end
  83.         term.setTextColor(colors.white)
  84.     end
  85.     for k, v in ipairs(items) do
  86.         local text = v
  87.         local width = term.getSize()
  88.         if b.button(2, click, math.ceil((width / 2) - (text:len() / 2)), k + 4, "") then
  89.             local info = data.getLine("tdl.data",k)
  90.             if info:gsub(string.sub(info,2),"") ~= "!" then
  91.                 data.writeLine("tdl.data",k,"!"..info)
  92.             else
  93.                 data.writeLine("tdl.data",k,info:gsub("!",""))
  94.             end
  95.         end
  96.     end
  97.     local scale = {term.getSize()}
  98.     term.setTextColor(colors.red)
  99.     if b.button(1,click,1,scale[2],">exit<") then
  100.         term.clear()
  101.         term.setCursorPos(1,1)
  102.         break
  103.     end
  104.     term.setTextColor(colors.yellow)
  105.     if b.button(1,click,scale[1]-11,scale[2],">update tdl<") then
  106.         shell.run("rename tdl tdl.old")
  107.         shell.run("pastebin get yU5gzMZ1 tdl")
  108.         shell.run("rm tdl.old")
  109.         shell.run("tdl")
  110.         break
  111.     end
  112. end
Add Comment
Please, Sign In to add comment