Advertisement
DOGGYWOOF

Untitled

Sep 23rd, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w, h = term.getSize()
  4. local nOption = 1
  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 function drawMenu()
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. term.write("Doggy OS (13.0)")
  17. term.setCursorPos(1, 2)
  18. shell.run("id")
  19.  
  20. term.setCursorPos(w - 11, 1)
  21. if nOption == 1 then
  22. term.write("Command")
  23. elseif nOption == 2 then
  24. term.write("Programs")
  25. elseif nOption == 3 then
  26. term.write("Shutdown")
  27. elseif nOption == 4 then
  28. term.write("Sign out")
  29. end
  30. end
  31.  
  32. -- Icons
  33. local icons = {
  34. "[C]", -- Command icon
  35. "[P]", -- Programs icon
  36. "[S]", -- Shutdown icon
  37. "[O]" -- Sign out icon
  38. }
  39.  
  40. -- GUI
  41. local function drawFrontend()
  42. term.clear()
  43. printCentered(math.floor(h / 2) - 3, "")
  44. printCentered(math.floor(h / 2) - 2, "Start Menu")
  45. printCentered(math.floor(h / 2) - 1, "")
  46.  
  47. for i = 1, 4 do
  48. local label = (i == 1 and "Command" or i == 2 and "Programs" or i == 3 and "Shutdown" or "Sign out")
  49. local icon = (nOption == i and " " .. icons[i] .. " " or icons[i])
  50. printCentered(math.floor(h / 2) + i - 1, (nOption == i and "[ " or "") .. label .. (nOption == i and " ]" or "") .. icon)
  51. end
  52.  
  53. printCentered(math.floor(h / 2) + 5, "")
  54. end
  55.  
  56. -- Display
  57. drawMenu()
  58. drawFrontend()
  59.  
  60. while true do
  61. local e, p = os.pullEvent()
  62. if e == "key" then
  63. local key = p
  64. if key == 17 or key == 200 then -- Up arrow
  65. if nOption > 1 then
  66. nOption = nOption - 1
  67. drawFrontend()
  68. end
  69. elseif key == 31 or key == 208 then -- Down arrow
  70. if nOption < 4 then
  71. nOption = nOption + 1
  72. drawFrontend()
  73. end
  74. elseif key == 28 then -- Enter key
  75. break
  76. end
  77. end
  78. end
  79.  
  80. term.clear()
  81.  
  82. -- Conditions
  83. if nOption == 1 then
  84. shell.run("/disk/os/home.lua")
  85. elseif nOption == 2 then
  86. term.clear()
  87. term.setCursorPos(1, 1)
  88. shell.run("/disk/os/programs")
  89. elseif nOption == 3 then
  90. shell.run("/disk/ACPI/shutdown")
  91. else
  92. shell.run("/disk/ACPI/logoff")
  93. end
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement