Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TODO LIST (c)GoldProgramming 2014
- --Csstform & M1cr0man
- os.loadAPI(shell.resolve("GS/GSAPI"))
- --Setup basic variables
- local titleEnd, theme, settings, x, y = 2, {[1] = "default", [2] = "blue.gst", [3] = "dark.gst"}, {};
- local xmax, ymax = term.getSize()
- local themes = {[1]="default",[2]="blue.gst",[3]="dark.gst"}
- theme = GSAPI.loadTheme()
- if theme == "" then
- theme = {[1]="Default",[2]=colors.brown,[3]=colors.lightGray,[4]=colors.yellow,[5]="",[6]=colors.black,[7]=colors.red}
- end
- local todo = {}
- xmax, ymax = term.getSize()
- --All inclusive print function
- function printex(bgNumber, colourNumber, x, y, text)
- if term.isColour() then
- term.setBackgroundColor(theme[bgNumber])
- term.setTextColor(theme[colourNumber])
- end
- term.setCursorPos(x, y)
- print(text)
- end
- --Draws background fillings
- function drawBG()
- if not term.isColour() then return end
- term.setBackgroundColor(theme[4])
- term.clear()
- term.setBackgroundColor(theme[2])
- for y = 1, titleEnd do
- term.setCursorPos(1, y)
- term.clearLine()
- end
- term.setBackgroundColor(theme[3])
- for y = ymax - titleEnd + 1, ymax do
- term.setCursorPos(1, y)
- term.clearLine()
- end
- end
- --Load last saved list on user request
- function loadLast()
- if fs.exists("tdl.list") then
- drawBG()
- printex(2, 7, 1, 1, "Would you like to load your previously saved todo list? (y/n)")
- input = select(2, os.pullEvent("char")):lower()
- if input == "y" then
- local file = fs.open("tdl.list", "r")
- local data = file.readAll()
- file.close()
- todo = textutils.unserialize(data)
- end
- end
- end
- --Main function. All running happens here
- function main()
- drawBG()
- printex(2, 7, 1, 1, "TODO LIST: ")
- --List the list
- for i,v in ipairs(todo) do
- printex(4, 6, 1, 2 + i, v)
- if 2 + i == ymax then break end
- end
- printex(3, 6, 1, ymax, "1-9 add/delete | E exit | S settings")
- --Setup actions
- local menu = false
- local actions = {
- ["s"] = function()
- if menu then return end
- printex(2, 6, 1, 1, "[1] Save List\n[2] Change Theme\n[3] Exit")
- menu = true
- end,
- ["1menu"] = function()
- local file = fs.open("tdl.list", "w")
- file.write(textutils.serialize(todo))
- file.close()
- end,
- ["2menu"] = function()
- term.clear()
- for i, v in ipairs(themes) do
- printex(2, 6, 1, i, "["..i.."]"..v)
- end
- local key;
- repeat key = tonumber(select(2, os.pullEvent("char"))) until key
- settings = {[1] = "", [2] = themes[key] or "default"}
- local file = fs.open("GS/universal.settings", "w")
- file.write(textutils.serialize(settings))
- file.close()
- end,
- ["edit"] = function(index)
- if not todo[index] then
- term.clear()
- term.setCursorPos(1,1)
- print("What do you need to do?")
- input = read()
- tostring(input)
- todo[index] = "["..index.."]" .. input
- local file = fs.open("tdl.list", "w")
- file.write(textutils.serialize(todo))
- file.close()
- else todo[index] = nil end
- end
- }
- --Get input, run according action
- repeat
- drawBG()
- key = select(2, os.pullEvent("char")):lower()
- if menu and actions[key.."menu"] then
- actions[key]()
- menu = false
- elseif tonumber(key) and tonumber(key) > 0 then actions["edit"](tonumber(key))
- elseif actions[key] then actions[key]() end
- until (not menu and key == "e") or (menu and key == "3")
- end
- --Run the program
- loadLast()
- main()
- if (term.isColor()) then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement