Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- 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
- --Draw menu Function
- local nOption = 1
- local function drawMenu()
- term.clear()
- term.setCursorPos(1,1)
- term.write("UnityOS")
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write("Command ")
- elseif nOption == 2 then
- term.write("Programs ")
- elseif nOption == 3 then
- term.write("Restart ")
- elseif nOption == 4 then
- term.write("Shutdown ")
- elseif nOption == 5 then
- term.write("Uninstall")
- else
- end
- end
- --GUI
- term.clear()
- local function drawFrontend()
- printCentered(math.floor(h/2) - 3, "")
- printCentered(math.floor(h/2) - 2, " Menu ")
- printCentered(math.floor(h/2) - 1, "")
- printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Commands ]") or "Commands ")
- printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs ")
- printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[ Restart ]") or "Restart ")
- printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[ Shutdown ]") or "Shutdown ")
- printCentered(math.floor(h/2) + 4, ((nOption == 5) and "[ Uninstall ]") or "Uninstall")
- printCentered(math.floor(h/2) + 5, "")
- end
- --Display
- drawMenu()
- drawFrontend()
- while true do
- local e,n = os.pullEvent("key")
- if e == "key" then
- if n == 17 or n == 200 then
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif n == 31 or n == 208 then
- if nOption < 5 then
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif n == 28 then
- break
- end
- end
- end
- term.clear()
- --Conditions
- if nOption == 1 then
- shell.run("OS/ .command")
- elseif nOption == 2 then
- shell.run("OS/.programs")
- elseif nOption == 3 then
- os.reboot()
- elseif nOption == 4 then
- os.shutdown()
- else
- shell.run("OS/ .uninstall")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement