Z1maV1

.UninstallDialog

May 14th, 2022 (edited)
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 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("Confirm")
  24. elseif nOption == 2 then
  25.    term.write("Cancel")
  26. else
  27. end
  28.  
  29. end
  30.  
  31. --GUI
  32. term.clear()
  33. local function drawFrontend()
  34.    printCentered( math.floor(h/2) - 2, "")
  35.    printCentered( math.floor(h/2) - 1, "Uninstall System" )
  36.    printCentered( math.floor(h/2) + 0, "")
  37.    printCentered( math.floor(h/2) + 1, ((nOption == 1) and "[ Confirm ]") or "Confirm" )
  38.    printCentered( math.floor(h/2) + 2, ((nOption == 2) and "[ Cancel  ]") or "Cancel " )
  39.    printCentered( math.floor(h/2) + 3, "")
  40. end
  41.  
  42. --Display
  43. drawMenu()
  44. drawFrontend()
  45.  
  46. while true do
  47.     local e,p = os.pullEvent("key")
  48.         if p == keys.up then
  49.             if nOption > 1 then
  50.                 nOption = nOption - 1
  51.                 drawMenu()
  52.                 drawFrontend()
  53.             end
  54.         elseif p == keys.down then
  55.             if nOption < 2 then
  56.                 nOption = nOption + 1
  57.                 drawMenu()
  58.                 drawFrontend()
  59.             end
  60.         elseif p == keys.enter then
  61.             break
  62.         end
  63. end
  64. term.clear()
  65.  
  66. --Conditions
  67. if nOption  == 1 then
  68. shell.run("/bin/.uninstall")
  69. else
  70. shell.run("/bin/main")
  71. end
Advertisement
Add Comment
Please, Sign In to add comment