Advertisement
atlasim

cat os update prompt

Apr 19th, 2020
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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("An Update Is Available)")
  18. term.setCursorPos(1,2)
  19.    term.setCursorPos(w-11,1)
  20.    if nOption == 1 then
  21.    term.write("Yes")
  22.    elseif nOption == 2 then
  23.    term.write("No")
  24. else
  25. end
  26.  
  27. end
  28.  
  29. --GUI
  30. term.clear()
  31. local function drawFrontend()
  32.    printCentered( math.floor(h/2) - 3, "")
  33.    printCentered( math.floor(h/2) - 2, "Would you like to update Now ?" )
  34.    printCentered( math.floor(h/2) - 1, "")
  35.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[  Yes   ]") or "Yes" )
  36.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[  No    ]") or "No" )
  37.    printCentered( math.floor(h/2) + 4, "")
  38. end
  39.  
  40. --Display
  41. drawMenu()
  42. drawFrontend()
  43.  
  44. while true do
  45.  local e,p = os.pullEvent()
  46.  if e == "key" then
  47.   local key = p
  48.   if key == 17 or key == 200 then
  49.  
  50.    if nOption > 1 then
  51.     nOption = nOption - 1
  52.     drawMenu()
  53.     drawFrontend()
  54.    end
  55.   elseif key == 31 or key == 208 then
  56.   if nOption < 2 then
  57.   nOption = nOption + 1
  58.   drawMenu()
  59.   drawFrontend()
  60. end
  61. elseif key == 28 then
  62.     --End should not be here!!
  63. break
  64. end --End should be here!!
  65. end
  66. end
  67. term.clear()
  68.  
  69. --Conditions
  70. if nOption  == 1 then
  71. shell.run("pastebin run YH9cN6Aa")
  72. elseif nOption == 2 then
  73. shell.run(".os/main")
  74.  
  75. print("Error this is not supposed to happen error code 001")
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement