Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Config ]]--
- --[[
- It's empty here...
- Looks Random didn't make me customizable!
- I need features.. Post ideas on the CC Forum!
- ]]--
- --[[ DO NOT EDIT WHAT'S BELOW UNLESS YOU KNOW WHAT YOU'RE DOING! ]]--
- --[[ Tables ]]--
- local tArgs = { ... }
- local currTask = {}
- local taskNums = {}
- local mOptions = {
- {5, "Help"},
- {6, "Add"},
- {7, "Remove"},
- {8, "Delete"},
- {9, "Check"},
- {10, "List"},
- {11, "Quit"}
- }
- --[[ Random Messages ]]--
- local footerMessages = {
- "Bug reports are useful!",
- "Menus anyone?"
- }
- --[[ Variables ]]--
- local pVersion = "1.7.10-2"
- local pHeader = "Task List v"..pVersion.." BETA"
- local pFooter = footerMessages[math.random(1, #footerMessages)]
- --[[ Functions ]]--
- local function cs()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function centerT(text, textType)
- local mx, my = term.getSize()
- local cx, cy = term.getCursorPos()
- term.setCursorPos(math.floor((mx-string.len(text))/2), cy)
- if string.lower(textType) == "print" then
- print(text)
- elseif string.lower(textType) == "write" then
- write(text)
- elseif string.lower(textType) == "swrite" then
- textutils.slowWrite(text)
- elseif string.lower(textType) == "sprint" then
- textutils.slowPrint(text)
- elseif string.lower(textType) == "error" then
- printError(text)
- end
- end
- local function dScreen()
- cs()
- centerT(pHeader, "print")
- centerT("----------------", "print")
- local mx, my = term.getSize()
- term.setCursorPos(1, my-1)
- centerT("----------------", "print")
- centerT(pFooter, "write")
- term.setCursorPos(1, 5)
- end
- local function fTasks()
- if fs.exists("tasks") then
- local tasks = fs.open("tasks", "r")
- local data = tasks.readAll()
- tasks.close()
- local nData = textutils.unserialize(data)
- if nData == "nil" then
- dScreen()
- centerT("No tasks!", "error")
- sleep(0.5)
- end
- for a=1, #nData do
- currTask[a] = nData[a]
- end
- else
- print("DOESN'T EXIST!")
- sleep(0.5)
- dScreen()
- centerT("You don't have a task file!", "error")
- print("Y | N")
- write("> ")
- local tAnswer = read()
- if string.lower(tAnswer) == "y" then
- local tasks = fs.open("tasks", "w")
- tasks.close()
- else
- cs()
- end
- end
- end
- local function tSave(task)
- dScreen()
- centerT("Saving...", "sprint")
- sleep(0.5)
- fTasks()
- for a=1, #currTask do
- if string.lower(currTask[a]) == string.lower(task) then
- dScreen()
- centerT("Task already exists!", "error")
- sleep(0.5)
- tExists = true
- break
- elseif a == #currTask then
- tExists = false
- end
- end
- if tExists == false then
- currTask[#currTask+1] = task
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- dScreen()
- centerT('"'..task..'" has been added!', "print")
- sleep(1.5)
- end
- end
- local function rTasks(tNumber)
- fTasks()
- table.remove(currTask, tNumber)
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- cs()
- end
- local function dOptions()
- dScreen()
- for a=1, #mOptions do
- print("* "..mOptions[a][2])
- end
- end
- local function checkClick(cY)
- for a=1, #mOptions do
- if cY == mOptions[a][1] then
- return mOptions[a][2]
- end
- end
- end
- local function tEnd(text1, text2)
- local cx, cy = term.getCursorPos()
- local mx, my = term.getSize()
- write(text1)
- term.setCursorPos(mx-string.len(text2), cy)
- write(text2)
- end
- local function hTHandler(text1, text2, textType2)
- local cx, cy = term.getCursorPos()
- local mx, my = term.getSize()
- write(text1)
- term.setCursorPos(15, cy)
- if string.lower(textType2) == "print" then
- print(text2)
- elseif string.lower(textType2) == "write" then
- write(text2)
- elseif string.lower(textType2) == "sprint" then
- textutils.slowPrint(text2)
- elseif string.lower(textType2) == "swrite" then
- textutils.slowWrite(text2)
- elseif string.lower(textType2) == "error" then
- printError(text2)
- end
- end
- --[[ Main ]]--
- while true do
- dScreen()
- dOptions()
- event, param1, eventX, eventY = os.pullEvent("mouse_click")
- local uOption = checkClick(eventY)
- if uOption == "Help" then
- dScreen()
- centerT("Help Section:", "print")
- print("")
- hTHandler("Add:", "Adds a task to the task file", "print")
- hTHandler("Remove:", "Removes a task from the task file", "print")
- hTHandler("Delete:", "Deletes task file", "print")
- hTHandler("Check:", "Checks for task file", "print")
- hTHandler("List:", "Lists all tasks", "print")
- hTHandler("Quit:", "Quits the program", "print")
- hTHandler("Pages:", "Click anywhere to exit, or flip pages", "print")
- print("")
- centerT("Click anywhere to return to menu", "error")
- sleep(0.5)
- os.pullEvent("mouse_click")
- elseif uOption == "Add" then
- dScreen()
- centerT("Add A Task", "print")
- centerT("Type your task here:", "error")
- write("> ")
- local uTask = read()
- tSave(uTask)
- if not tExists then
- dScreen()
- centerT("Saved!", "sprint")
- end
- sleep(0.5)
- elseif uOption == "Remove" then
- dScreen()
- fTasks()
- if #currTask > 0 then
- centerT("Remove A Task:", "print")
- centerT("Click your task:", "error")
- else
- centerT("No tasks to remove!", "error")
- end
- for a=1, #currTask do
- local cx, cy = term.getCursorPos()
- print("* "..currTask[a])
- table.insert(taskNums, a+6)
- end
- if #currTask > 0 then
- event, param1, x, y = os.pullEvent("mouse_click")
- end
- for a=1, #taskNums do
- if y == tonumber(taskNums[a]) then
- table.remove(currTask, a)
- break
- end
- end
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- elseif uOption == "Delete" then
- dScreen()
- centerT("Deleting file...", "sprint")
- fs.delete("tasks")
- sleep(0.5)
- dScreen()
- centerT("Deleted!", "error")
- sleep(0.5)
- dScreen()
- centerT("Remaking file...", "sprint")
- sleep(0.5)
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- dScreen()
- centerT("File remade!", "error")
- sleep(0.5)
- os.pullEvent("mouse_click")
- elseif uOption == "Check" then
- dScreen()
- centerT("Checking file...", "sprint")
- if fs.exists("tasks") then
- dScreen()
- centerT("File found!", "print")
- else
- dScreen()
- centerT("File not found!", "error")
- end
- dScreen()
- fTasks()
- for a=1, #currTask do
- for b=a+1, #currTask do
- if string.lower(currTask[a]) == string.lower(currTask[b]) then
- centerT("Duplicate tasks found!", "error")
- sleep(0.5)
- dScreen()
- centerT("Deleting...", "write")
- sleep(0.5)
- table.remove(currTask, a)
- local tasks = fs.open("tasks", "w")
- tasks.write(textutils.serialize(currTask))
- tasks.close()
- dScreen()
- centerT("Deleted!", "print")
- end
- end
- end
- sleep(0.5)
- os.pullEvent("mouse_click")
- elseif uOption == "List" then
- dScreen()
- fTasks()
- if #currTask <= 0 then
- centerT("No tasks to display!", "error")
- elseif #currTask > 10 then
- for a=1, 9 do
- print(a..") "..currTask[a])
- end
- tEnd("<- Previous", "Next ->")
- else
- for a=1, #currTask do
- print(a..") "..currTask[a])
- end
- end
- os.pullEvent("mouse_click")
- elseif uOption == "Quit" then
- dScreen()
- centerT("Quitting...", "sprint")
- sleep(0.5)
- cs()
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment