Advertisement
Guest User

.menu

a guest
Aug 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4. --Print Centered
  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. --Draw Menu Function
  13. local nOption = 1
  14.  
  15. local function drawMenu()
  16.   term.clear()
  17.   term.setCursorPos(1,1)
  18.   term.write("Notre premier OS")
  19.  
  20.   term.setCursorPos(w-11,1)
  21.   if nOption == 1 then
  22.     term.write("Commandes")
  23.   elseif nOption == 2 then
  24.     term.write('Programmes')
  25.   elseif nOption == 3 then
  26.     term.write("Enteindre")
  27.   elseif nOption == 4 then
  28.     term.write('Desinstaller')
  29.   else
  30.     end
  31. end
  32.  
  33. --GUI
  34.  
  35. term.clear()
  36. local function drawFrontend()
  37.   printCentered(math.floor(h/2) - 3, "")
  38.   printCentered(math.floor(h/2) - 2, "Menu")
  39.   printCentered(math.floor(h/2) - 1, "")
  40.   printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Commandes ]") or "Commandes")
  41.   printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[ Programmes ]") or "Programmes")
  42.   printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[ Eteindre ]") or "Eteindre")
  43.   printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[ Desinstaller ]") or "Desinstaller")
  44. end
  45.  
  46. --Display
  47.  
  48. drawMenu()
  49. drawFrontend()
  50.  
  51. while true do
  52.  local e,p = os.pullEvent()
  53.  if e == "key" then
  54.   local key = p
  55.   if key == 17 or key == 200 then
  56.      
  57.    if nOption > 1 then
  58.     nOption = nOption - 1
  59.     drawMenu()
  60.     drawFrontend()
  61.    end
  62.   elseif key == 31 or key == 208 then
  63.   if nOption < 4 then
  64.   nOption = nOption + 1
  65.   drawMenu()
  66.   drawFrontend()
  67. end
  68.     elseif key == 28 then
  69. break
  70. end
  71. end
  72. end
  73. term.clear()
  74.  
  75. --Conditions
  76. if nOption == 1 then
  77. term.setCursorPos(1,1)
  78. print("Tapez votre commande")
  79. input = read()
  80. shell.run(input)
  81. print("Programme termine :(")
  82. sleep(3)
  83. shell.run(".menu")
  84. elseif nOption == 2 then
  85. shell.run("programs")
  86. print("Appuyez sur un entrer pour continuer")
  87. input = read()
  88. shell.run(".menu")
  89. elseif nOption == 3 then
  90. os.shutdown()
  91. else
  92. shell.run("os.unistall")
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement