Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Boot Manager for CC Tweaked
- local w, h = term.getSize()
- -- Function to center text horizontally
- local function centerText(y, text)
- local x = math.floor((w - #text) / 2)
- term.setCursorPos(x, y)
- term.write(text)
- end
- -- ASCII art dog image
- local dogImage = {
- " |\\_/| ",
- " | @ @ Doggy OS ",
- " | <> _ ",
- " | _/\\------____ ((| |))",
- " | `--' | ",
- " _____|_ ___| |___.' ",
- "/_/_____/____/_______| "
- }
- -- Function to draw the ASCII art
- local function drawASCIIArt(y, textColor)
- term.setTextColor(textColor)
- for i, line in ipairs(dogImage) do
- centerText(y + i - 1, line)
- end
- end
- -- Function to display the "Insert bootable medium" message
- local function insertBootableMediumMessage()
- local message = "Insert bootable medium"
- local messageY = h - 5 -- Move the message higher (adjusted position)
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- -- Draw the ASCII art
- drawASCIIArt(math.floor((h - #dogImage) / 2), colors.white)
- -- Center and display the message
- centerText(messageY, message)
- -- Wait briefly before clearing and redrawing
- os.sleep(1)
- end
- end
- local function findStartupFiles()
- local disks = {}
- local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
- -- Search for startup files in specified disk paths
- for _, diskPath in ipairs(diskPaths) do
- local paths = {
- diskPath .. "/startup",
- diskPath .. "/startup.lua",
- }
- for _, path in ipairs(paths) do
- if fs.exists(path) then
- table.insert(disks, {path = path, displayName = path})
- break
- end
- end
- end
- -- Check /disk/ for /boot/error only
- if fs.exists("/disk/boot/error") then
- table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS"}) -- Doggy OS Device boot file
- end
- return disks
- end
- local function drawMenu(disks, selected, bootingMessage)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.black)
- -- Draw Header
- term.setCursorPos(1, 1)
- term.write(" ***** Doggy OS Boot Manager ***** ")
- term.setCursorPos(1, 3)
- term.setTextColor(colors.lightGray)
- term.write("Use Arrow keys to navigate, Enter to boot")
- term.setCursorPos(1, 5)
- term.setTextColor(colors.gray)
- term.write("======================================")
- -- Draw boot options
- for i, disk in ipairs(disks) do
- term.setCursorPos(1, 6 + i)
- if i == selected then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- else
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- end
- term.write(" [" .. i .. "] " .. disk.displayName)
- term.setTextColor(colors.white) -- Reset text color after writing
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 6 + #disks + 7)
- term.setTextColor(colors.gray)
- term.write("======================================")
- -- Display booting message if available
- if bootingMessage then
- term.setCursorPos(1, 8 + #disks + 7)
- term.setTextColor(colors.cyan)
- term.write(bootingMessage)
- end
- end
- local function main()
- local disks
- while true do
- disks = findStartupFiles()
- if #disks > 0 then
- break
- end
- -- No boot files found, display the "Insert bootable medium" screen
- insertBootableMediumMessage()
- end
- local selected = 1
- drawMenu(disks, selected, nil)
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.up then
- selected = (selected - 2) % #disks + 1
- elseif key == keys.down then
- selected = selected % #disks + 1
- elseif key == keys.enter then
- -- Update the GUI to show booting message
- drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...")
- sleep(1) -- Wait for a second to display the booting message
- -- Set text color to white and background color to black before booting
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- -- Boot the selected OS
- shell.run(disks[selected].path)
- break
- end
- drawMenu(disks, selected, nil) -- Refresh the menu without booting message
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement