Advertisement
PrinceOfCookies

.menu

Jan 25th, 2023 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | Source Code | 0 0
  1. -- Stops Termination ability
  2. os.pullEvent = os.pullEventRaw
  3. local tscp = term.setCursorPos -- set cursor pos
  4. local tcl = term.clearLine -- clear line
  5. local tw = term.write -- write
  6. local tc = term.clear -- clear
  7. local tgs = term.getSize -- get size
  8. local tstc = term.setTextColor
  9. shell.run("cd /")
  10.  
  11. tstc(colors.white)
  12.  
  13. local w, h = tgs()
  14.  
  15. -- Centered Print function
  16.  
  17. function centerPrint(y, s)
  18.     local x = math.floor((w - string.len(s)) / 2)
  19.     tscp(x, y)
  20.     tcl()
  21.     tw(s)
  22. end
  23.  
  24. -- Draw Menu Function
  25.  
  26. local nOption = 1
  27.  
  28. local function drawMenu()
  29.     tc()
  30.     tscp(1, 1)
  31.     tstc(colors.yellow)
  32.     tw("CookieOS 1.0.0")
  33.  
  34.     tstc(colors.white)
  35.     tscp(w - 11, 1)
  36.  
  37.     if nOption == 1 then
  38.         tw("Command")
  39.     elseif nOption == 2 then
  40.         tw("Programs")
  41.     elseif nOption == 3 then
  42.         tw("Shutdown")
  43.     elseif nOption == 4 then
  44.         tw("Reboot")
  45.     elseif nOption == 5 then
  46.         tw("Uninstall")
  47.     else
  48.     end
  49. end
  50.  
  51. -- GUI
  52.  
  53. tc()
  54.  
  55. local function drawFrontend()
  56.     centerPrint(math.floor(h / 2) - 3, "")
  57.     centerPrint(math.floor(h / 2) - 2, "Start Menu")
  58.     centerPrint(math.floor(h / 2) - 1, "")
  59.     centerPrint(math.floor(h / 2) - 0, (nOption == 1 and "[ Command   ]" or " Command   "))
  60.     centerPrint(math.floor(h / 2) + 1, (nOption == 2 and "[ Programs  ]" or "Programs" ))
  61.     centerPrint(math.floor(h / 2) + 2, (nOption == 3 and "[ Shutdown  ]" or "Shutdown" ))
  62.     centerPrint(math.floor(h / 2) + 3, (nOption == 4 and "[ Reboot    ]" or "Reboot   "   ))
  63.     centerPrint(math.floor(h / 2) + 4, (nOption == 5 and "[ Uninstall ]" or "Uninstall"))
  64. end
  65.  
  66. -- Display
  67.  
  68. drawMenu()
  69. drawFrontend()
  70.  
  71. while true do
  72.     local evt, key = os.pullEvent("key")
  73.     if key == 265 then -- Up
  74.         if nOption > 1 then
  75.             nOption = nOption - 1
  76.             drawMenu()
  77.             drawFrontend()
  78.         end
  79.     elseif key == 264 then -- Down
  80.         if nOption < 5 then
  81.             nOption = nOption + 1
  82.             drawMenu()
  83.             drawFrontend()
  84.         end
  85.     elseif key == 257 then
  86.         break
  87.     end
  88. end
  89.  
  90. tc()
  91.  
  92. -- Conditions
  93.  
  94. if nOption == 1 then
  95.     shell.run("os/.secCheck")
  96. elseif nOption == 2 then
  97.     shell.run("os/.programs")
  98. elseif nOption == 3 then
  99.     os.shutdown()
  100. elseif nOption == 4 then
  101.     os.reboot()
  102. else
  103.     shell.run("os/.uninstall")
  104. end
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement