Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Config Section ]]--
- realisticLoading = false
- -- This sets the sleep timer based on the size of your tasks file
- useMonitor = false
- --[[
- This lets the program always use a monitor to display tasks.
- When you remove a task or add a task, it will display the tasks on the monitor.
- ]]--
- --[[ Do not edit what is below this line, UNLESS you know what you are doing! ]]--
- --[[ Tables & Variables ]]--
- local tArgs = { ... }
- local helpInputs = {"help", "?", "author", "info", "task", "tasks"}
- local helpTaskInputs = {"check", "delete", "list", "run", "add", "remove", "clear"}
- local currTask = {}
- local sides = {"left", "right", "top", "bottom", "back", "front"}
- local monitor = nil
- -- monitor variable corrected later
- local listIdentifier = 1
- -- 1, 2, 3, 4, 5... List "Identifier"
- --[[ Functions ]]--
- function cs()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function findMonitor()
- for i=1, #sides do
- if peripheral.getType(sides[i]) == "monitor" then
- monitor = peripheral.wrap(sides[i])
- monitor2 = sides[i]
- -- Monitor returned table and string error
- break
- end
- end
- end
- function bar(text)
- cs()
- textutils.slowPrint(text)
- if fs.exists("tasks") then
- if realisticLoading == true then
- if fs.getSize("tasks") > 100 then
- textutils.slowPrint("This may take five minutes to process...")
- elseif fs.getSize("tasks") < 100 and fs.getSize("tasks") > 50 then
- textutils.slowPrint("This may take a minute or two to process...")
- else
- textutils.slowPrint("This may take a bit...")
- end
- elseif realisticLoading == false then
- termX, termY = term.getSize()
- curX, curY = term.getCursorPos()
- write("[")
- term.setCursorPos(termX, curY)
- write("]")
- term.setCursorPos(curX/curX+1, curY)
- for i=1, termX-2 do
- write("=")
- if realisticLoading == true then
- if fs.exists("tasks") then
- sleep(math.random(0.0, fs.getSize("tasks") / 50))
- end
- elseif realisticLoading == false then
- sleep(math.random(0.0, 0.5))
- end
- end
- term.setCursorPos(1, curY+1)
- end
- end
- end
- function saveTasks(task)
- fetchTasks()
- if tArgs[3] == "add" then
- currTask[#currTask+1] = task
- end
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- cs()
- if tArgs[3] == "add" then
- print("'"..task.."' has been added!")
- end
- end
- function fetchTasks()
- if fs.exists("tasks") then
- local tasks = fs.open("tasks", "r")
- local data = tasks.readAll()
- tasks.close()
- data = textutils.unserialize(data)
- for i=1, #data do
- currTask[i] = data[i]
- end
- else
- cs()
- printError("You don't have a task file!")
- sleep(1)
- print("")
- print("Do you wish to create a task file?")
- print("( Y / N )")
- write("> ")
- createTaskAnswer = read()
- if createTaskAnswer == "Y" then
- shell.run(""..shell.getRunningProgram(), "?", "task", "check")
- else
- cs()
- end
- end
- end
- function removeTasks(taskNumber)
- fetchTasks()
- table.remove(currTask, taskNumber)
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- cs()
- end
- --[[ Help Centre ]]--
- if #tArgs < 1 then
- print(""..shell.getRunningProgram().." <help / ?> <help command>")
- printError(""..shell.getRunningProgram()..":111: Usage error!")
- error("Insufficient inputs")
- else
- cs()
- if tArgs[1] == "help" or tArgs[1] == "?" then
- if tArgs[2] == nil then
- print("These commands are executed as so:")
- print(""..shell.getRunningProgram().." <help / ?> <help command>")
- print("")
- print("Possible inputs:")
- textutils.pagedTabulate(helpInputs)
- else
- if tArgs[2] == "author" then
- print("This was made by RandomShovel")
- elseif tArgs[2] == "info" then
- print("This program was designed to aid the fellow minecraftian")
- elseif tArgs[2] == "task" or tArgs[2] == "tasks" then
- cs()
- if tArgs[3] == nil then
- print("Possible inputs:")
- textutils.pagedTabulate(helpTaskInputs)
- elseif tArgs[3] == "check" then
- if fs.exists("tasks") then
- print("Tasks found!")
- bar("Loading tasks...")
- cs()
- print("Tasks loaded!")
- else
- printError("Tasks not found!")
- sleep(2)
- bar("Creating file...")
- cs()
- print("File created!")
- sleep(2)
- cs()
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- print("Programs:")
- shell.run("programs")
- end
- elseif tArgs[3] == "delete" then
- bar("Deleting file...")
- cs()
- print("File deleted!")
- cs()
- print("Programs:")
- shell.run("programs")
- fs.delete("tasks")
- elseif tArgs[3] == "list" then
- print("Current tasks:")
- print("")
- fetchTasks()
- shell.run(shell.getRunningProgram(), "?", "task", "run")
- elseif tArgs[3] == "remove" then
- print("Do you know the number of your task?")
- print("( Y / N )")
- write("> ")
- response = read()
- if response == "Y" or response == "y" then
- cs()
- print("Enter task number:")
- write("> ")
- removeTasks(tonumber(read()))
- shell.run(shell.getRunningProgram(), "?", "task", "list")
- else
- cs()
- print("Please locate your task.")
- print("")
- fetchTasks()
- for i=1, #currTask do
- print(""..listIdentifier..") "..currTask[i])
- listIdentifier = listIdentifier + 1
- end
- print("")
- print("Task number:")
- write("> ")
- removeTasks(tonumber(read()))
- shell.run(shell.getRunningProgram(), "?", "task", "list")
- end
- elseif tArgs[3] == "add" then
- cs()
- print("Enter your task:")
- write("> ")
- userTask = read()
- saveTasks(userTask)
- shell.run(shell.getRunningProgram(), "?", "tasks", "list")
- elseif tArgs[3] == "clear" then
- cs()
- bar("Clearing monitor...")
- findMonitor()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- cs()
- print("Monitor cleared!")
- sleep(1)
- cs()
- end
- end
- end
- end
- end
- if tArgs[2] == "task" or tArgs[2] == "tasks" then
- if tArgs[3] == "run" and useMonitor == true then
- --[[ Locate Monitor ]]--
- findMonitor()
- print("The monitor that will be used is located on the "..monitor2.." side")
- --[[ Display Tasks ]]--
- fetchTasks()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- maxMonX, maxMonY = monitor.getSize()
- for i=1, #currTask do
- if string.len(currTask[i]) <= maxMonX then
- monitor.write(""..listIdentifier..") "..currTask[i])
- listIdentifier = listIdentifier + 1
- monitor.setCursorPos(1, i+1)
- curMonX, curMonY = monitor.getCursorPos()
- if curMonY >= maxMonY then
- error("You need a bigger monitor!")
- end
- else
- error("You need a bigger monitor!")
- end
- end
- elseif tArgs[3] == "run" and useMonitor == false then
- fetchTasks()
- cs()
- listIdentifier = 1
- for i=1, #currTask do
- print(""..listIdentifier..") "..currTask[i])
- listIdentifier = listIdentifier + 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment