Z1maV1

main

May 14th, 2022 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --main file ver 13--
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. local w,h = term.getSize()
  5.  
  6. function printCentered( y,s )
  7.    local x = math.floor((w - string.len(s)) / 2)
  8.    term.setCursorPos(x,y)
  9.    term.clearLine()
  10.    term.write( s )
  11. end
  12.  
  13. local nOption = 1
  14.  
  15. local function drawMenu()
  16.    term.clear()
  17.    term.setCursorPos(1,1)
  18.    term.write("Diamond OS // 1.2.1 // ")
  19. term.setCursorPos(1,2)
  20. shell.run("id")
  21.  
  22.    term.setCursorPos(w-11,1)
  23.    if nOption == 1 then
  24.    term.write("Terminal")
  25. elseif nOption == 2 then
  26.    term.write("Programs")
  27. elseif nOption == 3 then
  28.    term.write("Shutdown")
  29. elseif nOption == 4 then
  30.    term.write("Uninstall")
  31. elseif nOption == 5 then
  32.    term.write("About")
  33. else
  34. end
  35.  
  36. end
  37.  
  38. --GUI
  39. term.clear()
  40. local function drawFrontend()
  41.    printCentered( math.floor(h/2) - 3, "")
  42.    printCentered( math.floor(h/2) - 2, "Start Menu" )
  43.    printCentered( math.floor(h/2) - 1, "")
  44.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Terminal ]") or "Terminal" )
  45.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
  46.    printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
  47.    printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Uninstall]") or " Uninstall" )
  48.    printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[   About  ]") or " About" )
  49.    printCentered( math.floor(h/2) + 5, "")
  50. end
  51.  
  52. --Display
  53. drawMenu()
  54. drawFrontend()
  55.  
  56. while true do
  57.     local e,p = os.pullEvent("key")
  58.         if p == keys.up then
  59.             if nOption > 1 then
  60.                 nOption = nOption - 1
  61.                 drawMenu()
  62.                 drawFrontend()
  63.             end
  64.         elseif p == keys.down then
  65.             if nOption < 5 then
  66.                 nOption = nOption + 1
  67.                 drawMenu()
  68.                 drawFrontend()
  69.             end
  70.         elseif p == keys.enter then
  71.             break
  72.         end
  73. end
  74. term.clear()
  75.  
  76. --Conditions
  77. if nOption  == 1 then
  78. shell.run("/bin/.command")
  79. elseif nOption == 2 then
  80. shell.run("/bin/.programs")
  81. elseif nOption == 3 then
  82. shell.run("/bin/.shutdown")
  83. elseif nOption == 4 then
  84. shell.run("/bin/.UninstallDialog")
  85. elseif nOption == 5 then
  86. shell.run("/bin/.about")
  87. end
Advertisement
Add Comment
Please, Sign In to add comment