Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- JHC's Quick Note Program
- -- Prevent Termination
- os.pullEvent = os.pullEventRaw
- -- Functions
- function readFile(Name)
- local file = fs.open(Name, "r")
- local fileLine = {}
- i = 1
- while true do
- line = file.readLine()
- if not line then break end
- fileLine[i] = line
- i=i+1
- end
- file.close()
- return fileLine
- end
- function setup()
- local setupFile = fs.open(".setup", "w")
- term.clear()
- term.setCursorPos(1,1)
- term.write("Monitor Side? (top, left, right, bottom)")
- local input = read()
- setupFile.writeLine(input)
- term.setCursorPos(1,2)
- term.write("Name?")
- input = read()
- setupFile.writeLine(input)
- term.setCursorPos(1,3)
- term.write("Pass?")
- input = read("*")
- setupFile.writeLine(input)
- setupFile.close()
- end
- function readVariables()
- variables = readFile(".setup")
- monSide = variables[1]
- user = variables[2]
- pass = variables[3]
- end
- function menu()
- term.clear()
- term.setCursorPos(1,1)
- term.write("1. Refresh Display")
- term.setCursorPos(1,2)
- term.write("2. Add Notes")
- term.setCursorPos(1,3)
- term.write("3. Delete Line")
- term.setCursorPos(1,4)
- term.write("4. Quit")
- term.setCursorPos(1,5)
- end
- function refreshDisplay()
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("#".. user .." NOTES")
- if fs.exists(".notes") then
- list = readFile(".notes")
- local monPos = 2
- for i=1, #list do
- mon.setCursorPos(1,monPos)
- mon.write(i..". "..list[i])
- monPos = monPos+1
- end
- else
- mon.setCursorPos(1,2)
- mon.write("No Notes")
- end
- end
- function addNote()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Note? ")
- local note = read()
- local noteFile = fs.open(".notes", "a")
- noteFile.writeLine(note)
- noteFile.close()
- end
- function deleteLine()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Enter line number: ")
- local input = read()
- local notes = readFile(".notes")
- table.remove(notes, tonumber(input))
- local output = fs.open(".notes", "w")
- for i=1, #notes do
- output.writeLine(notes[i])
- end
- output.close()
- end
- function password()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Password: ")
- local passInput = read("*")
- if passInput == pass then
- return true
- else
- return false
- end
- end
- -- ########### PROGRAM ########### --
- -- Check for Setup File
- if not fs.exists(".setup") then
- setup()
- end
- readVariables()
- mon = peripheral.wrap(monSide)
- mon.clear()
- mon.setTextScale(.5)
- refreshDisplay()
- -- Main Loop
- while true do
- menu()
- local input = read()
- if input == "1" then
- refreshDisplay()
- elseif input == "2" then
- addNote()
- refreshDisplay()
- elseif input == "3" then
- if password() then
- deleteLine()
- else
- term.setCursorPos(1,3)
- term.write("Incorrect Password")
- os.sleep(1)
- end
- refreshDisplay()
- elseif input == "4" then
- if password() == true then
- return
- else
- term.setCursorPos(1,3)
- term.write("Incorrect Password")
- os.sleep(1)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement