Advertisement
FishtoastleProgramer

DankOsMenu

Apr 10th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. term.setBackgroundColor(colors.white)
  3. term.setTextColor(colors.green)
  4. local fle = fs.open("DankOs/.version","r")
  5. local Ver = fle.readLine()
  6. fle.close()
  7. local w,h = term.getSize()
  8.  
  9. function printCentered( y,s )
  10.    local x = math.floor((w - string.len(s)) / 2)
  11.    term.setCursorPos(x,y)
  12.    term.clearLine()
  13.    term.write( s )
  14. end
  15.  
  16. local nOption = 1
  17.  
  18. local function drawMenu()
  19.    term.clear()
  20.    term.setCursorPos(1,1)
  21.    term.write("DankOs alpha "..Ver.. " // ")
  22. term.setCursorPos(1,2)
  23. shell.run("id")
  24.  
  25.    term.setCursorPos(w-11,1)
  26.    if nOption == 1 then
  27.    term.write("Command")
  28. elseif nOption == 2 then
  29.    term.write("Programs")
  30. elseif nOption == 3 then
  31.    term.write("Shutdown")
  32. elseif nOption == 4 then
  33.    term.write("Uninstall")
  34. else
  35. end
  36.  
  37. end
  38.  
  39. --GUI
  40. term.clear()
  41. local function drawFrontend()
  42.    printCentered( math.floor(h/2) - 3, "")
  43.    printCentered( math.floor(h/2) - 2, "Start Menu" )
  44.    printCentered( math.floor(h/2) - 1, "")
  45.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Command ]") or "Command" )
  46.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
  47.    printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
  48.    printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Uninstall ]") or " Uninstall" )
  49.    printCentered( math.floor(h/2) + 4, "")
  50. end
  51.  
  52. --Display
  53. drawMenu()
  54. drawFrontend()
  55.  
  56. while true do
  57.  local e,p = os.pullEvent()
  58.  if e == "key" then
  59.   local key = p
  60.   if key == 17 or key == 200 then
  61.  
  62.    if nOption > 1 then
  63.     nOption = nOption - 1
  64.     drawMenu()
  65.     drawFrontend()
  66.    end
  67.   elseif key == 31 or key == 208 then
  68.   if nOption < 4 then
  69.   nOption = nOption + 1
  70.   drawMenu()
  71.   drawFrontend()
  72. end
  73. elseif key == 28 then
  74.     --End should not be here!!
  75. break
  76. end --End should be here!!
  77. end
  78. end
  79. term.clear()
  80.  
  81. --Conditions
  82. if nOption  == 1 then
  83. shell.run("DankOs/.command")
  84. elseif nOption == 2 then
  85. shell.run("DankOs/.DankPrograms")
  86. elseif nOption == 3 then
  87. os.shutdown()
  88. else
  89. shell.run("DankOs/.uninstall")
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement