Advertisement
DOGGYWOOF

Untitled

Oct 16th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. -- Doggy OS Boot Manager for CC Tweaked
  2.  
  3. local w, h = term.getSize()
  4.  
  5. -- Function to center text horizontally
  6. local function centerText(y, text)
  7. local x = math.floor((w - #text) / 2)
  8. term.setCursorPos(x, y)
  9. term.write(text)
  10. end
  11.  
  12. -- ASCII art dog image
  13. local dogImage = {
  14. " |\\_/| ",
  15. " | @ @ Doggy OS ",
  16. " | <> _ ",
  17. " | _/\\------____ ((| |))",
  18. " | `--' | ",
  19. " _____|_ ___| |___.' ",
  20. "/_/_____/____/_______| "
  21. }
  22.  
  23. -- Function to draw the ASCII art
  24. local function drawASCIIArt(y, textColor)
  25. term.setTextColor(textColor)
  26. for i, line in ipairs(dogImage) do
  27. centerText(y + i - 1, line)
  28. end
  29. end
  30.  
  31. -- Function to display the "Insert bootable medium" message
  32. local function insertBootableMediumMessage()
  33. local message = "Insert bootable medium"
  34. local messageY = h - 5 -- Move the message higher (adjusted position)
  35.  
  36. while true do
  37. term.setBackgroundColor(colors.black)
  38. term.clear()
  39.  
  40. -- Draw the ASCII art
  41. drawASCIIArt(math.floor((h - #dogImage) / 2), colors.white)
  42.  
  43. -- Center and display the message
  44. centerText(messageY, message)
  45.  
  46. -- Wait briefly before clearing and redrawing
  47. os.sleep(1)
  48. end
  49. end
  50.  
  51. local function findStartupFiles()
  52. local disks = {}
  53. local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
  54.  
  55. -- Search for startup files in specified disk paths
  56. for _, diskPath in ipairs(diskPaths) do
  57. local paths = {
  58. diskPath .. "/startup",
  59. diskPath .. "/startup.lua",
  60. }
  61. for _, path in ipairs(paths) do
  62. if fs.exists(path) then
  63. table.insert(disks, {path = path, displayName = path})
  64. break
  65. end
  66. end
  67. end
  68.  
  69. -- Check /disk/ for /boot/error only
  70. if fs.exists("/disk/boot/error") then
  71. table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS"}) -- Doggy OS Device boot file
  72. end
  73.  
  74. return disks
  75. end
  76.  
  77. local function drawMenu(disks, selected, bootingMessage)
  78. term.clear()
  79. term.setCursorPos(1, 1)
  80. term.setTextColor(colors.blue)
  81. term.setBackgroundColor(colors.black)
  82.  
  83. -- Draw Header
  84. term.setCursorPos(1, 1)
  85. term.write(" ***** Doggy OS Boot Manager ***** ")
  86.  
  87. term.setCursorPos(1, 3)
  88. term.setTextColor(colors.lightGray)
  89. term.write("Use Arrow keys to navigate, Enter to boot")
  90.  
  91. term.setCursorPos(1, 5)
  92. term.setTextColor(colors.gray)
  93. term.write("======================================")
  94.  
  95. -- Draw boot options
  96. for i, disk in ipairs(disks) do
  97. term.setCursorPos(1, 6 + i)
  98. if i == selected then
  99. term.setTextColor(colors.white)
  100. term.setBackgroundColor(colors.blue)
  101. else
  102. term.setTextColor(colors.lightGray)
  103. term.setBackgroundColor(colors.black)
  104. end
  105. term.write(" [" .. i .. "] " .. disk.displayName)
  106. term.setTextColor(colors.white) -- Reset text color after writing
  107. end
  108.  
  109. term.setTextColor(colors.white)
  110. term.setBackgroundColor(colors.black)
  111.  
  112. term.setCursorPos(1, 6 + #disks + 7)
  113. term.setTextColor(colors.gray)
  114. term.write("======================================")
  115.  
  116. -- Display booting message if available
  117. if bootingMessage then
  118. term.setCursorPos(1, 8 + #disks + 7)
  119. term.setTextColor(colors.cyan)
  120. term.write(bootingMessage)
  121. end
  122. end
  123.  
  124. local function main()
  125. local disks
  126. while true do
  127. disks = findStartupFiles()
  128. if #disks > 0 then
  129. break
  130. end
  131. -- No boot files found, display the "Insert bootable medium" screen
  132. insertBootableMediumMessage()
  133. end
  134.  
  135. local selected = 1
  136. drawMenu(disks, selected, nil)
  137.  
  138. while true do
  139. local event, key = os.pullEvent("key")
  140. if key == keys.up then
  141. selected = (selected - 2) % #disks + 1
  142. elseif key == keys.down then
  143. selected = selected % #disks + 1
  144. elseif key == keys.enter then
  145. -- Update the GUI to show booting message
  146. drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...")
  147. sleep(1) -- Wait for a second to display the booting message
  148.  
  149. -- Set text color to white and background color to black before booting
  150. term.setTextColor(colors.white)
  151. term.setBackgroundColor(colors.black)
  152.  
  153. -- Boot the selected OS
  154. shell.run(disks[selected].path)
  155. break
  156. end
  157. drawMenu(disks, selected, nil) -- Refresh the menu without booting message
  158. end
  159. end
  160.  
  161. main()
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement