The3vilM0nk3y

Todo List

Apr 6th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. mSide = "right"
  2. function readLines(sPath)
  3. -- reads the users file as raw text and returns it in a table.
  4. file = fs.open(sPath, "r")
  5. if file then
  6. tLines = {}
  7. sLine = file.readLine()
  8. while sLine do
  9. table.insert(tLines, sLine)
  10. sLine = file.readLine()
  11. end
  12. file.close()
  13. return tLines
  14. end
  15. return nil
  16. end
  17. -- Uses a table of text and writes it to the users file.
  18. function writeLines(sPath, tLines)
  19. local file = fs.open(sPath, "w")
  20. if file then
  21. for _, sLine in ipairs(tLines) do
  22. file.writeLine(tostring(sLine))
  23. end
  24. file.close()
  25. else
  26. error(sPath .. " does not exist")
  27. end
  28. end
  29. function mPrint(s)
  30. win.print(s)
  31. -- m.write(s)
  32. -- mx,my=m.getCursorPos()
  33. -- m.setCursorPos(1,my+1)
  34. end
  35. function center(s)
  36. mx,my = win.getCursorPos()
  37. m.setCursorPos(math.floor((w/2)-(#s/2)),my)
  38. print(s)
  39. end
  40. function updateMonitor()
  41. win.clear()
  42. win.setCursorPos(1,1)
  43. t = term.redirect(win)
  44. center("TODO LIST")
  45. center("---------")
  46. for i=1,#currentlist do
  47. print(i .." " ..currentlist[i])
  48. end
  49. term.redirect(t)
  50. end
  51. m=peripheral.find("monitor")
  52. m.setTextScale(1)
  53. x,y = term.getSize()
  54. w,h = m.getSize()
  55. win = window.create(m,1,1,w,h)
  56. currentlist = {}
  57. if fs.exists("autolist") then
  58. currentlist = readLines("autolist")
  59. end
  60. while true do
  61. updateMonitor()
  62. term.clear()
  63. term.setCursorPos(1,1)
  64. print("Type in what needs to be done then hit enter, or type 'read' to see a current list")print("To clear an entry, first type 'rm' then hit enter, then enter the number that coresponds to the entry you wish to remove. Use 'read' to get this number")
  65. term.write("> ")
  66. input = io.read()
  67. if input == "read" then
  68. term.clear()
  69. term.setCursorPos(1,1)
  70. print("Current List Includes:")
  71. for i=1,#currentlist do
  72. print(i .." " ..currentlist[i])
  73. end
  74. sleep(4)
  75. term.setCursorPos(1,y-1)
  76. write("Press Any Key to Continue")
  77. while true do
  78. e,k = os.pullEvent("key")
  79. if e == "key" then
  80. break
  81. end
  82. end
  83. term.clearLine()
  84. sleep(1)
  85. elseif input == "exit" then
  86. writeLines("autolist",currentlist)
  87. print("Exiting")
  88. sleep(2)
  89. break
  90. elseif input == "rm" then
  91. print("Remove which number?")
  92. rm = io.read()
  93. if tonumber(rm)> #currentlist then
  94. print("Entry Number " .. " does not exist")
  95. else
  96. print("Removed " .. currentlist[tonumber(rm)])
  97. table.remove(currentlist,tonumber(rm))
  98. writeLines("autolist",currentlist)
  99. end
  100. sleep(3)
  101. else
  102. table.insert(currentlist,input)
  103. writeLines("autolist",currentlist)
  104. print("Added Entry:")
  105. print(input)
  106. sleep(5)
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment