Advertisement
PrinceOfCookies

uninstall.lua

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