FoxOS

.menu

Dec 30th, 2020 (edited)
98
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("FoxOS by FoxWorn3365 | 2020")
  18. term.setCursorPos(1,2)
  19. shell.run("id")
  20.  
  21.    term.setCursorPos(w-11,1)
  22.    if nOption == 1 then
  23.    term.write("Utilità")
  24. elseif nOption == 2 then
  25.    term.write("Comandi")
  26. elseif nOption == 3 then
  27.    term.write("LeNet")
  28. elseif nOption == 4 then
  29.    term.write("WGet")
  30. elseif nOption == 5 then
  31.    term.write("ChatDistance")
  32. elseif nOption == 6 then
  33.    term.write("Spegni")
  34. elseif nOption == 7 then
  35.    term.write("Disintalla")
  36. else
  37. end
  38.  
  39. end
  40.  
  41. --GUI
  42. term.clear()
  43. local function drawFrontend()
  44.    printCentered( math.floor(h/2) - 3, "")
  45.    printCentered( math.floor(h/2) - 2, "Menu Principale" )
  46.    printCentered( math.floor(h/2) - 1, "")
  47.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Utilità ]") or "Utilità" )
  48.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Comandi ]") or "Comandi" )
  49.    printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ LeNet ]") or "LeNet" )
  50.    printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ WGet ]") or "WGet" )
  51.    printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ ChatDistance ]") or "ChatDistance" )
  52.    printCentered( math.floor(h/2) + 5, ((nOption == 6) and "[ Spegni ]") or "Spegni" )
  53.    printCentered( math.floor(h/2) + 6, ((nOption == 7) and "[ Disinstalla ]") or "Disinstalla" )
  54. end
  55.  
  56. --Display
  57. drawMenu()
  58. drawFrontend()
  59.  
  60. while true do
  61.  sleep(0.1)
  62.  local e,p = os.pullEvent()
  63.  if e == "key" then
  64.   local key = p
  65.   if key == 17 or key == 200 then
  66.   print("")
  67.    if nOption > 1 then
  68.     nOption = nOption - 1
  69.     drawMenu()
  70.     drawFrontend()
  71.    end
  72.   elseif key == 31 or key == 208 then
  73.   if nOption < 7 then
  74.   nOption = nOption + 1
  75.   drawMenu()
  76.   drawFrontend()
  77. end
  78. elseif key == 28 then
  79.     --End should not be here!!
  80. break
  81. end --End should be here!!
  82. end
  83. end
  84. term.clear()
  85.  
  86. --Conditions
  87. if nOption  == 1 then
  88. shell.run(".FoxOS/.utilities")
  89. elseif nOption == 2 then
  90. shell.run(".FoxOS/.commands")
  91. elseif nOption == 3 then
  92. shell.run(".FoxOS/.lenet")
  93. elseif nOption == 4 then
  94. shell.run(".FoxOS/.wget")
  95. elseif nOption == 5 then
  96. shell.run(".FoxOS/.dc")
  97. elseif nOption == 6 then
  98. os.shutdown()
  99. elseif nOption == 7 then
  100. shell.run(".FoxOS/.uninstall")
  101. else
  102. shell.run(".FoxOS/.what")
  103. end
Advertisement
Add Comment
Please, Sign In to add comment