Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --udo By Zambonie
- --Just a Quick Attempt at a todo list.
- --Though Planning to be bigger ;p
- --Added sanity checks to all pullevents by DoomRater
- --v. 0.2
- local size = {term.getSize()}
- local cur = 1
- local colorp = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
- local bg = nil
- local txt = nil
- local maxF = false
- function checkAndCreate() --Checks For a Todo Folder. If None, It will create one.
- if fs.exists("TodoFiles") then
- return
- else fs.makeDir("TodoFiles")
- return
- end
- end
- function loadTodos(file)
- local file = fs.open("TodoFiles/"..file,"r")
- local file = textutils.unserialize(file.readAll())
- return file
- end
- function drawTodo()
- term.setCursorPos(1,1)
- write(" ")
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- write(t[cur])
- local l = 0
- maxF = false
- for i = 2, size[2]-1 do
- if l == 0 then l = 1
- paintutils.drawLine(1, i, size[1], i, f[1])
- if f[i+3] ~= nil then
- term.setCursorPos(1,i)
- term.setTextColor(f[3])
- write((i-1)..". "..f[i+3])
- bg = f[2]
- txt = f[4]
- end
- elseif l == 1 then l = 0
- paintutils.drawLine(1, i, size[1], i, f[2])
- if f[i+3] ~= nil then
- term.setCursorPos(1,i)
- term.setTextColor(f[4])
- write((i-1)..". "..f[i+3])
- bg = f[1]
- txt = f[3]
- end
- end
- end
- term.setCursorPos(size[1]-2, 1)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.gray)
- write("-")
- term.setCursorPos(size[1]-4, 1)
- write("<")
- if #f-4 >= size[2]-2 then
- maxF = true
- term.setCursorPos(size[1],1)
- term.setTextColor(colors.black)
- write("+")
- end
- end
- function makeTodo()
- term.setBackgroundColor(colors.gray)
- term.clear()
- term.setTextColor(colors.lightGray)
- term.setCursorPos(1,1)
- write("Name : ")
- local name = read()
- term.setCursorPos(1,4)
- write("Line Color 1")
- for x = 1, 16 do
- paintutils.drawPixel(x, 5, colorp[x])
- end
- term.setCursorPos(1,6)
- term.setBackgroundColor(colors.gray)
- write("Line Color 2")
- for x = 1, 16 do
- paintutils.drawPixel(x, 7, colorp[x])
- end
- term.setCursorPos(1,8)
- term.setBackgroundColor(colors.gray)
- write("Text Color 1")
- for x = 1, 16 do
- paintutils.drawPixel(x, 9, colorp[x])
- end
- term.setCursorPos(1,10)
- term.setBackgroundColor(colors.gray)
- write("Text Color 2")
- for x = 1, 16 do
- paintutils.drawPixel(x, 11, colorp[x])
- end
- term.setCursorPos(1, 13)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- write("Done")
- local l1 = 1
- local l2 = 1
- local t1 = 1
- local t2 = 1
- while true do
- paintutils.drawLine(18, 5, size[1], 5, l1)
- paintutils.drawLine(18, 7, size[1], 7, l2)
- paintutils.drawLine(18, 9, size[1], 9, t1)
- paintutils.drawLine(18, 11, size[1], 11, t2)
- local e, b, x, y = os.pullEvent("mouse_click")
- if y == 5 and x <= 16 then
- l1 = colorp[x]
- elseif y == 7 and x <= 16 then
- l2 = colorp[x]
- elseif y == 9 and x <= 16 then
- t1 = colorp[x]
- elseif y == 11 and x <= 16 then
- t2 = colorp[x]
- elseif x >= 1 and x <= 4 and y == 13 then
- local nt = fs.open("TodoFiles/"..name, "w")
- nt.write("{"..l1..","..l2..","..t1..","..t2.."}")
- nt.close()
- break
- end
- end
- end
- function makeDo()
- if #f < 5 then
- term.setBackgroundColor(f[1])
- term.setTextColor(f[3])
- else
- term.setBackgroundColor(bg)
- term.setTextColor(txt)
- end
- term.setCursorPos(1, #f-4+2)
- write((#f-4+1)..". ")
- local newinput = read()
- table.insert(f, newinput)
- local fw = fs.open("TodoFiles/"..t[cur],"w")
- fw.write(textutils.serialize(f))
- fw.close()
- end
- while true do
- checkAndCreate()
- term.setBackgroundColor(colors.gray) --Setting Up Background
- term.clear()
- term.setCursorPos(size[1], 1)
- term.setTextColor(colors.lightGray)
- write("+")
- term.setCursorPos(size[1]-2, 1)
- write(">")
- term.setCursorPos(1,1)
- write("<"..cur.."/"..#fs.list("TodoFiles")..">")
- term.setCursorPos(size[1]-3, size[2])
- write("udo")
- if #fs.list("TodoFiles") == 0 then
- term.setTextColor(colors.white)
- term.setCursorPos(size[1]/2-#"No Todos Found!"/2+1, size[2]/2-1)
- write("No Todos Found!")
- term.setCursorPos(1, size[2]/2)
- write("Click Anywhere To Make one")
- os.pullEvent("mouse_click")
- makeTodo()
- elseif #fs.list("TodoFiles") ~= 0 then
- t = fs.list("TodoFiles")
- f = loadTodos(t[cur])
- local l = 0
- for i = size[2]/2-5, size[2]/2+3 do
- if l == 0 then l = 1
- paintutils.drawLine(size[1]/2-5, i, size[1]/2+2, i, f[1])
- elseif l == 1 then l = 0
- paintutils.drawLine(size[1]/2-5, i, size[1]/2+2, i, f[2])
- end
- end
- paintutils.drawLine(size[1]/2-4, size[2]/2+4, size[1]/2+3, size[2]/2+4, colors.black)
- paintutils.drawLine(size[1]/2+3, size[2]/2-4, size[1]/2+3, size[2]/2+3, colors.black)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(size[1]/2-#t[cur]/2, size[2]/2+6)
- write(t[cur])
- local e, b, x, y = os.pullEvent("mouse_click")
- if x == size[1]-2 and y == 1 then
- while true do
- drawTodo()
- local e2, b2, x2, y2 = os.pullEvent("mouse_click")
- if x2 == size[1]-4 and y2 == 1 then
- break
- elseif x2 == size[1] and y2 == 1 and not maxF then
- term.setCursorPos(size[1], 1)
- term.setTextColor(colors.lime)
- write("+")
- makeDo()
- term.setCursorPos(size[1], 1)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.gray)
- write("+")
- elseif x2 == size[1]-2 and y2 == 1 then
- term.setCursorPos(size[1]-2, 1)
- term.setTextColor(colors.red)
- write("-")
- local e3, b3, x3, y3 = os.pullEvent("mouse_click")
- if y3 ~= 1 and y3 ~= size[2] then
- if f[y3+4-1] ~= nil then
- table.remove(f, y3+4-1)
- local fw = fs.open("TodoFiles/"..t[cur],"w")
- fw.write(textutils.serialize(f))
- fw.close()
- term.setCursorPos(size[1],1)
- term.setTextColor(colors.lightGray)
- write("+")
- end
- end
- end
- end
- elseif x == 1 and y == 1 and cur ~= 1 then
- cur = cur - 1
- elseif x == 5 and y == 1 and cur ~= #fs.list("TodoFiles") then
- cur = cur + 1
- elseif x == size[1] and y == 1 then
- makeTodo()
- elseif y == size[2] and b == 2 then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- print("Thanks for using udo!")
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement