Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Created and Designed by PrinzJuliano,
- ]]
- w,h = term.getSize()
- running = true
- timeR = nil
- refreshRate = 0.2
- isDrawed = false
- done = false
- if not term.isColor() then
- running = false
- error("You need to have an advanced Computer")
- end
- if not fs.exists("notes.dat") then
- file = io.open("iNotes.dat","w")
- file:write("a%%Create some notes")
- file:close()
- end
- notes = {
- }
- function drawAll()
- end
- function refresh()
- notes = {}
- file = io.open("iNotes.dat","r")
- repeat
- content = file:read()
- table.insert(notes, content)
- until content == nil
- file:close()
- drawAll()
- end
- function redo()
- end
- items = {
- --last one first
- {
- name="Exit",
- func = function()
- running = false
- shell.run("clear")
- timeR = nil
- end,
- ypos = 0,
- xpos = 0, -- Changed this
- width = 0
- },
- {
- name="Delete Notes",
- func = function()
- shell.run("delete","notes.dat")
- file = io.open("iNotes.dat","w")
- file:write("a%%All notes have been deleted!")
- file:close()
- refresh()
- end,
- xpos = 0,
- ypos = 0,
- width = 0
- },
- {
- name = "Editor",
- func = function()
- shell.run("edit","iNotes.dat")
- isDrawed = false
- redo()
- refresh()
- end,
- xpos = 0,
- ypos = 0,
- width = 0
- }
- }
- function drawTask()
- term.setCursorPos(1,h-1)
- term.setBackgroundColor(colors.blue)
- term.write(string.rep(" ",w))
- term.setCursorPos(1,h)
- term.write(string.rep(" ",w))
- time = textutils.formatTime(os.time(),true)
- term.setCursorPos(w-string.len(time),h)
- term.write(time)
- term.setCursorPos(1,h-1)
- term.write("+-+")
- term.setCursorPos(1,h)
- term.write("+-+")
- term.setBackgroundColor(colors.black)
- end
- function onDrawNotes()
- term.setCursorPos(1,1)
- for i=1,table.getn(notes) do
- if notes[i]:sub(1,3) == "a%%" then
- fail = string.sub(notes[i],4,string.len(notes[i]))
- print(fail)
- else
- print(i..". "..notes[i])
- end
- if i == h-4 then
- print("...")
- break;
- end
- end
- end
- function onDrawMenu()
- term.setCursorPos(1,h-2-table.getn(items))
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- large = 0
- for i=1,table.getn(items) do
- if string.len(items[i].name) > large then
- large = string.len(items[i].name)
- end
- end
- for i=1,table.getn(items) do
- items[i].width = large;
- end
- for i=1,table.getn(items) do
- term.setCursorPos(1,h-1-i)
- term.write(string.rep(" ",large))
- term.setCursorPos(1,h-1-i)
- term.write(items[i].name)
- items[i].xpos = 1
- items[i].ypos = h-1-i
- end
- isDrawed = true
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function updateMouse(button,xpos,ypos)
- if button == 1 then
- if xpos == 1 and isDrawed == false or xpos == 2 and isDrawed == false or xpos == 3 and isDrawed == false then
- if ypos == h-1 or ypos == h then
- onDrawMenu()
- end
- elseif isDrawed then
- done = false
- for j=1, #items do
- if xpos >= items[j].xpos and xpos <= items[j].width and ypos == items[j].ypos then -- this is the way to do it :D/>
- term.clear()
- items[j].func()
- isDrawed = false
- done = true
- break
- end
- end
- if done == false then
- isDrawed = false
- drawAll()
- end
- end
- end
- end
- function drawAll()
- shell.run("clear")
- drawTask()
- onDrawNotes()
- if isDrawed == true then
- onDrawMenu()
- end
- term.setCursorPos(1,1)
- end
- function updateAll()
- e,p1,p2,p3 = os.pullEvent()
- if e == "timer" and p1 == timeR then
- drawTask()
- refresh()
- timeR = os.startTimer(refreshRate)
- elseif e == "mouse_click" then
- updateMouse(p1,p2,p3)
- end
- end
- function mainLoop()
- while running do
- drawAll()
- updateAll()
- end
- end
- function redo()
- timeR = os.startTimer(refreshRate)
- running = true
- mainLoop()
- end
- timeR = os.startTimer(refreshRate)
- refresh()
- mainLoop()
- shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement