Z1maV1

.shutdown

May 15th, 2022 (edited)
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4.  
  5. function printCentered( y,s )
  6.    local x = math.floor((w - string.len(s)) / 2)
  7.    term.setCursorPos(x,y)
  8.    term.clearLine()
  9.    term.write( s )
  10. end
  11.  
  12. local nOption = 1
  13.  
  14. local function drawMenu()
  15.    term.clear()
  16.    term.setCursorPos(1,1)
  17.    term.write("Diamond OS // 1.2.1 //")
  18. term.setCursorPos(1,2)
  19. shell.run("id")
  20.  
  21.    term.setCursorPos(w-11,1)
  22.    if nOption == 1 then
  23.    term.write("Shutdown")
  24. elseif nOption == 2 then
  25.    term.write("Reboot")
  26. elseif nOption == 3 then
  27.    term.write("Sleep")
  28. else
  29.    term.write("Back")
  30. end
  31. end
  32.  
  33. --GUI
  34. term.clear()
  35. local function drawFrontend()
  36.    printCentered( math.floor(h/2) - 2, "")
  37.    printCentered( math.floor(h/2) - 1, "Shutdown dialog" )
  38.    printCentered( math.floor(h/2) + 0, "")
  39.    printCentered( math.floor(h/2) + 1, ((nOption == 1) and "[ Shutdown ]") or "Shutdown" )
  40.    printCentered( math.floor(h/2) + 2, ((nOption == 2) and "[  Reboot  ]") or "Reboot " )
  41.    printCentered( math.floor(h/2) + 3, ((nOption == 3) and "[  Sleep   ]") or "Sleep ")
  42.    printCentered( math.floor(h/2) + 4, ((nOption == 4) and "[   Back   ]") or "Back" )
  43.    printCentered( math.floor(h/2) + 5, "")
  44. end
  45.  
  46. --Display
  47. drawMenu()
  48. drawFrontend()
  49.  
  50. while true do
  51.     local e,p = os.pullEvent("key")
  52.         if p == keys.up then
  53.             if nOption > 1 then
  54.                 nOption = nOption - 1
  55.                 drawMenu()
  56.                 drawFrontend()
  57.             end
  58.         elseif p == keys.down then
  59.             if nOption < 4 then
  60.                 nOption = nOption + 1
  61.                 drawMenu()
  62.                 drawFrontend()
  63.             end
  64.         elseif p == keys.enter then
  65.             break
  66.         end
  67. end
  68. term.clear()
  69.  
  70. --Conditions
  71. if nOption  == 1 then
  72. os.shutdown()
  73. elseif nOption == 2 then
  74. os.reboot()
  75. elseif nOption == 3 then
  76. shell.run("/bin/.sleep")
  77. else
  78. shell.run("/bin/main")
  79. end
Advertisement
Add Comment
Please, Sign In to add comment