Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Feel free to change the values in this column
- local monside= "right"
- local header = "Task List 1.5"
- local bgcol = colors.blue
- local bgcol2 = colors.lightBlue
- local fgcol = colors.yellow
- local fgcol2 = colors.orange
- local selcol = colors.green
- local button1_text = "Delete"
- local FILENAME = "tasklist.dat"
- local tasklist
- local selection = -1
- function save()
- f = fs.open(FILENAME,"w")
- f.writeLine(textutils.serialize(tasklist))
- f.close()
- end
- function load()
- if fs.exists(FILENAME) then
- f = fs.open(FILENAME,"r")
- local readline = f.readLine()
- tasklist = textutils.unserialize(readline)
- f.close()
- else
- f = fs.open(FILENAME,"w")
- f.writeLine("{[1]=\'Make a new task\'}")
- f.close()
- tasklist = {"Make a new task"}
- end
- end
- function printLine(x)
- s = peripheral.wrap(monside)
- for i=1,x do
- s.write(" ")
- end
- end
- function drawButton(text, x, y, colT, colB)
- s = peripheral.wrap(monside)
- for i=0, 2 do
- s.setCursorPos(x, y+i)
- s.setBackgroundColor(colB)
- printLine(string.len(text)+2)
- end
- s.setCursorPos(x+1, y+1)
- s.setTextColor(colT)
- s.write(text)
- end
- function display()
- if tasklistlen == nil then tasklistlen = 0 end
- s = peripheral.wrap(monside)
- local monx, mony = s.getSize()
- s.setTextColor(fgcol2)
- s.setBackgroundColor(bgcol)
- s.clear()
- s.setCursorPos(monx/2-string.len(header)/2,1)
- s.write(header)
- if tasklist == nil then
- else
- for i=1, #tasklist do
- if i+2 >= mony-2 then break end
- s.setCursorPos(1,i+2)
- if selection == i then
- s.setBackgroundColor(selcol)
- else
- if i % 2 == 1 then
- s.setBackgroundColor(bgcol)
- else
- s.setBackgroundColor(bgcol2)
- end
- end
- printLine(monx)
- s.setCursorPos(1,i+2)
- s.setTextColor(fgcol2)
- s.write(i..". ")
- s.setTextColor(fgcol)
- s.write(tasklist[i])
- end
- if selection == -1 then
- else
- drawButton(button1_text, 1, mony-2, colors.white, colors.red)
- end
- end
- save()
- end
- function termedit()
- s = peripheral.wrap(monside)
- local monx, mony = s.getSize()
- while true do
- term.setBackgroundColor(bgcol)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(fgcol)
- write("Begin typing to add a new task..")
- local event, char = os.pullEvent("char")
- term.setCursorPos(1,3)
- write("New Task: "..char)
- local newtask = char..io.read()
- if string.len(newtask) > monx-3 then
- term.setCursorPos(1,5)
- term.setTextColor(colors.red)
- write("Text too long, limit: "..monx-3)
- else
- local notdone = true
- local i = 1
- if tasklist == nil then
- tasklist = {newtask}
- term.setCursorPos(1,5)
- write("New task added!")
- else
- while notdone do
- if tasklist[i] == nil then
- tasklist[i] = newtask
- notdone = false
- term.setCursorPos(1,5)
- write("New task added!")
- end
- i = i + 1
- end
- end
- end
- display()
- sleep(0.75)
- end
- end
- function touchscreen()
- s = peripheral.wrap(monside)
- local monx, mony = s.getSize()
- while true do
- local etype, side, tx, ty = os.pullEvent("monitor_touch")
- if #tasklist ~= nil then
- if 2 < ty and ty <= mony-2 then
- if ty-2 > #tasklist then
- selection = -1
- else
- selection = ty-2
- end
- end
- if ty > mony-3 then
- local stringlen = string.len(button1_text)
- if tx <= stringlen + 2 then
- local si = selection
- table.remove(tasklist,si)
- --[[
- tasklist[si] = nil
- j = 0
- for a = 1, #tasklist do
- if tasklist[a] == nil then j = j+1 end
- tasklist[a] = tasklist[a+j]
- end
- --]]
- else
- selection = -1
- end
- end
- display()
- end
- end
- end
- function main()
- print("programInit..")
- load()
- display()
- print("Attempting to boot parallel..")
- parallel.waitForAny(termedit, touchscreen)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- print("ProgramExit")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement