Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- save file as .menu in root
- -- most of the code from Homelab youtube tut 1
- os.pullEvent = os.pullEventRaw -- prevents CTRL + T bypass
- local w,h = term.getSize()
- function printCentered (y,s)
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write(s)
- end
- term.setTextColour(colours.orange)
- local nOption = 1
- local function drawMenu()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Nexus OS")
- term.setCursorPos(w-8,1)
- if nOption == 1 then
- term.write("Root")
- elseif nOption == 2 then
- term.write("Programs")
- elseif nOption == 3 then
- term.write("Shutdown")
- elseif nOption == 4 then
- term.setTextColour(colours.red)
- term.write("Terminate System")
- term.setTextColour(colours.orange)
- else
- end
- end
- --GUI
- term.clear()
- local function drawFrontend()
- printCentered(math.floor(h/2) - 3, "")
- printCentered(math.floor(h/2) - 2, "Start Menu")
- printCentered(math.floor(h/2) - 1, "")
- printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Root ]") or "Root")
- printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs")
- printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown")
- term.setTextColour(colours.red)
- printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[ Terminate System ]") or "Terminate System")
- term.setTextColour(colours.orange)
- end
- --Display
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == keys.up and nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- elseif key == keys.down and nOption < 4 then
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- elseif key == keys.enter then
- break
- end
- end
- end
- --Conditions
- if nOption == 1 then
- shell.run("os/.root")
- elseif nOption == 2 then
- shell.run("os/.programs")
- elseif nOption == 3 then
- os.shutdown()
- elseif nOption == 4 then
- shell.run("os/terminate")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement