Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CUI(m)
- n=1
- l=#m
- while true do
- term.clear()
- term.setCursorPos(1,2)
- for i=1, l, 1 do
- if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
- end
- print("Select a number[arrow up/arrow down]")
- a, b= os.pullEventRaw()
- if a == "key" then
- if b==200 and n>1 then n=n-1 end
- if b==208 and n<=l then n=n+1 end
- if b==28 then break end
- end
- end
- term.clear() term.setCursorPos(1,1)
- return n
- end
- function displayMenu()
- local options={
- "TODO List",
- "Ender Dictionary",
- "Shit Post",
- "Exit"
- }
- local n=CUI(options)
- return n
- end
- function checkLock(doc)
- local file = fs.open("Locked.lua","r")
- local check = file.readLine()
- file.close()
- print(doc)
- if (check=="none") then
- local modem = peripheral.wrap("back")
- modem.open(998)
- modem.transmit(999,998,doc)
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- print(message)
- if (message == "Locked") then
- return "Remote"
- else
- return "none"
- end
- elseif (""..check==""..doc) then
- saveAndUnlockDoc(doc)
- return "Local"
- end
- end
- function saveAndUnlockDoc(doc)
- local modem = peripheral.wrap("back")
- modem.open(994)
- local file = fs.open(doc..".lua","r")
- modem.transmit(995,994,doc..""..file.readAll())
- file.close()
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- print(message)
- if (message =="Success") then
- local lFile = fs.open("Locked.lua","w")
- lFile.write("none")
- lFile.close()
- print("Doc Saved")
- a, b= os.pullEvent("key")
- return
- else
- print("Doc Failed to save try again")
- a, b= os.pullEvent("key")
- return
- end
- end
- function editAndLockDoc(doc)
- local modem = peripheral.wrap("back")
- modem.open(996)
- modem.transmit(997,996,doc)
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local file = fs.open(doc..".lua","w")
- file.write(message)
- file.close()
- local lFile = fs.open("Locked.lua","w")
- lFile.write(doc.."")
- lFile.close()
- error("Document saved locally as "..doc..".lua Please make edits then come back to save and release lock")
- end
- while true do
- local task = displayMenu()
- if(task=="Exit")then
- error("Exited");
- end
- local lockedBy = checkLock(task)
- print(lockedBy)
- if (lockedBy=="none") then
- editAndLockDoc(task)
- elseif (lockedBy=="Local") then
- print("Document was locked by you")
- else
- print("Document is currently locked by another user")
- print("Press any key to go back to menu")
- a, b= os.pullEvent("key")
- end
- end
Add Comment
Please, Sign In to add comment