RandomShovel

[CC][Beta] Todo list v1.1.1 *Quick Fix!*

Nov 16th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.89 KB | None | 0 0
  1. --[[  Config Section  ]]--
  2.  
  3. realisticLoading = false
  4. -- This sets the sleep timer based on the size of your tasks file
  5.  
  6. useMonitor = false
  7. --[[
  8. This lets the program always use a monitor to display tasks.
  9. When you remove a task or add a task, it will display the tasks on the monitor.
  10. ]]--
  11.  
  12. --[[   Do not edit what is below this line, UNLESS you know what you are doing!   ]]--
  13.  
  14. --[[  Tables & Variables  ]]--
  15.  
  16. local tArgs = { ... }
  17. local helpInputs = {"help", "?", "author", "info", "task", "tasks"}
  18. local helpTaskInputs = {"check", "delete", "list", "run", "add", "remove", "clear"}
  19. local currTask = {}
  20. local sides = {"left", "right", "top", "bottom", "back", "front"}
  21. local monitor = nil  
  22. -- monitor variable corrected later
  23. local listIdentifier = 1  
  24. -- 1, 2, 3, 4, 5... List "Identifier"
  25.  
  26. --[[  Functions ]]--
  27.  
  28. function cs()
  29.  term.clear()
  30.  term.setCursorPos(1, 1)
  31. end
  32.  
  33. function findMonitor()
  34.  for i=1, #sides do
  35.   if peripheral.getType(sides[i]) == "monitor" then
  36.    monitor = peripheral.wrap(sides[i])
  37.    monitor2 = sides[i]
  38.    -- Monitor returned table and string error
  39.    break
  40.   end
  41.  end
  42. end
  43.  
  44. function bar(text)
  45.  cs()
  46.  textutils.slowPrint(text)
  47.  if fs.exists("tasks") then
  48.   if realisticLoading == true then
  49.    if fs.getSize("tasks") > 100 then
  50.     textutils.slowPrint("This may take five minutes to process...")
  51.    elseif fs.getSize("tasks") < 100 and fs.getSize("tasks") > 50 then
  52.     textutils.slowPrint("This may take a minute or two to process...")
  53.    else
  54.     textutils.slowPrint("This may take a bit...")
  55.    end
  56.   elseif realisticLoading == false then
  57.    termX, termY = term.getSize()
  58.    curX, curY = term.getCursorPos()
  59.    write("[")
  60.    term.setCursorPos(termX, curY)
  61.    write("]")
  62.    term.setCursorPos(curX/curX+1, curY)
  63.    for i=1, termX-2 do
  64.     write("=")
  65.     if realisticLoading == true then
  66.      if fs.exists("tasks") then
  67.       sleep(math.random(0.0, fs.getSize("tasks") / 50))
  68.      end
  69.     elseif realisticLoading == false then
  70.      sleep(math.random(0.0, 0.5))
  71.     end
  72.    end
  73.    term.setCursorPos(1, curY+1)
  74.   end
  75.  end
  76. end
  77.  
  78. function saveTasks(task)
  79.  fetchTasks()
  80.  if tArgs[3] == "add" then
  81.   currTask[#currTask+1] = task
  82.  end
  83.   local tasks = fs.open("tasks", "w")
  84.   tasks.write(textutils.serialize(currTask))
  85.   tasks.close()
  86.   cs()
  87.   if tArgs[3] == "add" then
  88.    print("'"..task.."' has been added!")
  89.   end
  90. end
  91.  
  92. function fetchTasks()
  93.  if fs.exists("tasks") then
  94.   local tasks = fs.open("tasks", "r")
  95.   local data = tasks.readAll()
  96.   tasks.close()
  97.   data = textutils.unserialize(data)
  98.   for i=1, #data do
  99.    currTask[i] = data[i]
  100.   end
  101.  else
  102.   cs()
  103.   printError("You don't have a task file!")
  104.   sleep(1)
  105.   print("")
  106.   print("Do you wish to create a task file?")
  107.   print("( Y / N )")
  108.   write("> ")
  109.   createTaskAnswer = read()
  110.   if createTaskAnswer == "Y" then
  111.    shell.run(""..shell.getRunningProgram(), "?", "task", "check")
  112.   else
  113.    cs()
  114.   end
  115.  end
  116. end
  117.  
  118. function removeTasks(taskNumber)
  119.  fetchTasks()
  120.  table.remove(currTask, taskNumber)
  121.  local tasks = fs.open("tasks", "w")
  122.  tasks.write(textutils.serialize(currTask))
  123.  tasks.close()
  124.  cs()
  125. end
  126.  
  127. --[[  Help Centre  ]]--
  128.  
  129. if #tArgs < 1 then
  130.  print(""..shell.getRunningProgram().." <help / ?> <help command>")
  131.  printError(""..shell.getRunningProgram()..":111: Usage error!")
  132.  error("Insufficient inputs")
  133. else
  134.  cs()
  135.  if tArgs[1] == "help" or tArgs[1] == "?" then
  136.   if tArgs[2] == nil then
  137.    print("These commands are executed as so:")
  138.    print(""..shell.getRunningProgram().." <help / ?> <help command>")
  139.    print("")
  140.    print("Possible inputs:")
  141.    textutils.pagedTabulate(helpInputs)
  142.   else
  143.    if tArgs[2] == "author" then
  144.     print("This was made by RandomShovel")
  145.    elseif tArgs[2] == "info" then
  146.     print("This program was designed to aid the fellow minecraftian")
  147.    elseif tArgs[2] == "task" or tArgs[2] == "tasks" then
  148.     cs()
  149.     if tArgs[3] == nil then
  150.      print("Possible inputs:")
  151.      textutils.pagedTabulate(helpTaskInputs)
  152.     elseif tArgs[3] == "check" then
  153.      if fs.exists("tasks") then
  154.       print("Tasks found!")
  155.       bar("Loading tasks...")
  156.       cs()
  157.       print("Tasks loaded!")
  158.      else
  159.       printError("Tasks not found!")
  160.       sleep(2)
  161.       bar("Creating file...")
  162.       cs()
  163.       print("File created!")
  164.       sleep(2)
  165.       cs()
  166.       local tasks = fs.open("tasks", "w")
  167.       tasks.write(textutils.serialize(currTask))
  168.       tasks.close()
  169.       print("Programs:")
  170.       shell.run("programs")
  171.      end
  172.     elseif tArgs[3] == "delete" then
  173.      bar("Deleting file...")
  174.      cs()
  175.      print("File deleted!")
  176.      cs()
  177.      print("Programs:")
  178.      shell.run("programs")
  179.      fs.delete("tasks")
  180.     elseif tArgs[3] == "list" then
  181.      print("Current tasks:")
  182.      print("")
  183.      fetchTasks()
  184.      shell.run(shell.getRunningProgram(), "?", "task", "run")
  185.     elseif tArgs[3] == "remove" then
  186.      print("Do you know the number of your task?")
  187.      print("( Y / N )")
  188.      write("> ")
  189.      response = read()
  190.      if response == "Y" or response == "y" then
  191.       cs()
  192.       print("Enter task number:")
  193.       write("> ")
  194.       removeTasks(tonumber(read()))
  195.       shell.run(shell.getRunningProgram(), "?", "task", "list")
  196.      else
  197.       cs()
  198.       print("Please locate your task.")
  199.       print("")
  200.       fetchTasks()
  201.       for i=1, #currTask do
  202.        print(""..listIdentifier..") "..currTask[i])
  203.        listIdentifier = listIdentifier + 1
  204.       end
  205.       print("")
  206.       print("Task number:")
  207.       write("> ")
  208.       removeTasks(tonumber(read()))
  209.       shell.run(shell.getRunningProgram(), "?", "task", "list")
  210.      end
  211.     elseif tArgs[3] == "add" then
  212.      cs()
  213.      print("Enter your task:")
  214.      write("> ")
  215.      userTask = read()
  216.      saveTasks(userTask)
  217.      shell.run(shell.getRunningProgram(), "?", "tasks", "list")
  218.     elseif tArgs[3] == "clear" then
  219.      cs()
  220.      bar("Clearing monitor...")
  221.      findMonitor()
  222.      monitor.clear()
  223.      monitor.setCursorPos(1, 1)
  224.      cs()
  225.      print("Monitor cleared!")
  226.      sleep(1)
  227.      cs()
  228.     end
  229.    end
  230.   end
  231.  end
  232. end
  233.  
  234. if tArgs[2] == "task" or tArgs[2] == "tasks" then
  235.  if tArgs[3] == "run" and useMonitor == true then
  236.   --[[  Locate Monitor  ]]--
  237.  
  238.   findMonitor()
  239.   print("The monitor that will be used is located on the "..monitor2.." side")
  240.  
  241.   --[[  Display Tasks  ]]--
  242.  
  243.   fetchTasks()
  244.   monitor.clear()
  245.   monitor.setCursorPos(1, 1)
  246.   maxMonX, maxMonY = monitor.getSize()
  247.   for i=1, #currTask do
  248.    if string.len(currTask[i]) <= maxMonX then
  249.     monitor.write(""..listIdentifier..") "..currTask[i])
  250.     listIdentifier = listIdentifier + 1
  251.     monitor.setCursorPos(1, i+1)
  252.     curMonX, curMonY = monitor.getCursorPos()
  253.     if curMonY >= maxMonY then
  254.      error("You need a bigger monitor!")
  255.     end
  256.    else
  257.     error("You need a bigger monitor!")
  258.    end
  259.   end
  260.  elseif tArgs[3] == "run" and useMonitor == false then
  261.   fetchTasks()
  262.   cs()
  263.   listIdentifier = 1
  264.   for i=1, #currTask do
  265.    print(""..listIdentifier..") "..currTask[i])
  266.    listIdentifier = listIdentifier + 1
  267.   end
  268.  end
  269. end
Advertisement
Add Comment
Please, Sign In to add comment