Advertisement
DOGGYWOOF

UEFI

Jun 30th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. -- Function to draw a border
  2. local function drawBorder()
  3. term.clear()
  4. local w, h = term.getSize()
  5. for y = 1, h do
  6. term.setCursorPos(1, y)
  7. term.write("|")
  8. term.setCursorPos(w, y)
  9. term.write("|")
  10. end
  11. for x = 1, w do
  12. term.setCursorPos(x, 1)
  13. term.write("-")
  14. term.setCursorPos(x, h)
  15. term.write("-")
  16. end
  17. term.setCursorPos(1, 1)
  18. term.write("+")
  19. term.setCursorPos(w, 1)
  20. term.write("+")
  21. term.setCursorPos(1, h)
  22. term.write("+")
  23. term.setCursorPos(w, h)
  24. term.write("+")
  25. end
  26.  
  27. -- Function to center text on the screen
  28. local function centerText(text, y)
  29. local w, _ = term.getSize()
  30. local x = math.floor((w - #text) / 2) + 1
  31. term.setCursorPos(x, y)
  32. term.write(text)
  33. end
  34.  
  35. -- Function to show UEFI options menu
  36. local function showMenu()
  37. drawBorder()
  38. local _, h = term.getSize()
  39. centerText("Doggy OS UEFI Options", math.floor(h / 2) - 2)
  40. centerText("1. Recovery", math.floor(h / 2))
  41. centerText("2. Bootable devices", math.floor(h / 2) + 1)
  42. centerText("3. Shutdown", math.floor(h / 2) + 2)
  43. end
  44.  
  45. -- Function to list bootable devices
  46. local function listBootableDevices()
  47. drawBorder()
  48. local _, h = term.getSize()
  49. centerText("Select Bootable Device", math.floor(h / 2) - 2)
  50.  
  51. local devices = {}
  52. for _, side in ipairs({"top", "bottom", "left", "right", "front", "back"}) do
  53. if disk.isPresent(side) and fs.exists(disk.getMountPath(side) .. "/startup.lua") then
  54. table.insert(devices, side)
  55. end
  56. end
  57.  
  58. for i, device in ipairs(devices) do
  59. centerText(i .. ". " .. device, math.floor(h / 2) - 1 + i)
  60. end
  61.  
  62. if #devices == 0 then
  63. centerText("No bootable devices found", math.floor(h / 2))
  64. os.sleep(2)
  65. showMenu()
  66. else
  67. term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
  68. term.write("Select a device number: ")
  69. local choice = tonumber(read())
  70. if choice and devices[choice] then
  71. shell.run(disk.getMountPath(devices[choice]) .. "/startup.lua")
  72. else
  73. listBootableDevices()
  74. end
  75. end
  76. end
  77.  
  78. -- Function to handle menu selection
  79. local function handleSelection()
  80. while true do
  81. local event, key = os.pullEvent("key")
  82. if key == keys.one then
  83. shell.run("/disk/boot/Recovery.lua")
  84. elseif key == keys.two then
  85. listBootableDevices()
  86. elseif key == keys.three then
  87. os.shutdown()
  88. end
  89. end
  90. end
  91.  
  92. -- Show menu
  93. showMenu()
  94. handleSelection()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement