Advertisement
9551

backup

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