-- GUI OS v2.1 with Fixed Web Browser -- Fix background color bug + basic HTML tag stripping local term = term local colors = colors local paintutils = paintutils local screenW, screenH = term.getSize() local currentScreen = "menu" local browserUrl = "" local pageLines = {} local currentPage = 1 local totalPages = 1 local linesPerPage = screenH - 6 -- ========== UI Helpers ========== local function drawButton(x, y, w, h, text, bgColor) paintutils.drawFilledBox(x, y, x + w - 1, y + h - 1, bgColor) local textX = x + math.floor((w - #text) / 2) local textY = y + math.floor(h / 2) term.setCursorPos(textX, textY) term.setTextColor(colors.white) term.setBackgroundColor(bgColor) term.write(text) -- Reset background after drawing term.setBackgroundColor(colors.black) end local function pointInBox(px, py, x, y, w, h) return px >= x and px <= x + w - 1 and py >= y and py <= y + h - 1 end -- Strip HTML tags for readability local function stripHtml(html) local text = html:gsub("<[^>]+>", " ") text = text:gsub(" ", " ") text = text:gsub("&", "&") text = text:gsub("<", "<") text = text:gsub(">", ">") text = text:gsub("\n%s*\n", "\n") return text end -- ========== Main Menu ========== local menuButtons = { {x=3, y=4, w=22, h=3, text="Web Browser", color=colors.blue, action="browser"}, {x=3, y=8, w=22, h=3, text="File Manager", color=colors.green, action="files"}, {x=3, y=12, w=22, h=3, text="Run Program", color=colors.yellow, action="run"}, {x=3, y=16, w=22, h=3, text="Native Shell", color=colors.gray, action="shell"}, {x=3, y=20, w=22, h=3, text="Shutdown", color=colors.red, action="shutdown"}, } local function drawMenu() term.setBackgroundColor(colors.black) term.clear() paintutils.drawFilledBox(1, 1, screenW, 1, colors.gray) term.setCursorPos(2, 1) term.setTextColor(colors.white) term.setBackgroundColor(colors.gray) term.write("GUI OS v2.1") term.setBackgroundColor(colors.black) for i = 1, #menuButtons do local btn = menuButtons[i] drawButton(btn.x, btn.y, btn.w, btn.h, btn.text, btn.color) end paintutils.drawFilledBox(1, screenH, screenW, screenH, colors.gray) term.setCursorPos(2, screenH) term.setTextColor(colors.white) term.setBackgroundColor(colors.gray) term.write("Click a button to continue") term.setBackgroundColor(colors.black) end -- ========== File Manager ========== local function openFileManager() term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(1, 1) print("=== File List (Root) ===") local files = fs.list("/") for i = 1, #files do if fs.isDir(files[i]) then print("[DIR] " .. files[i]) else print("[FILE] " .. files[i]) end end print("\nPress any key to return") os.pullEvent("key") currentScreen = "menu" end -- ========== Run Program ========== local function openRunProgram() term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(1, 1) write("Enter program name: ") local prog = read() if prog ~= "" then shell.run(prog) print("\nPress any key to return") os.pullEvent("key") end currentScreen = "menu" end -- ========== Web Browser ========== local browserButtons = { {x=2, y=screenH-2, w=12, h=2, text="Enter URL", color=colors.blue, action="url"}, {x=15, y=screenH-2, w=10, h=2, text="Page Up", color=colors.green, action="up"}, {x=26, y=screenH-2, w=12, h=2, text="Page Down", color=colors.green, action="down"}, {x=39, y=screenH-2, w=10, h=2, text="Save File", color=colors.yellow, action="save"}, {x=50, y=screenH-2, w=10, h=2, text="Back", color=colors.red, action="back"}, } local function loadPage(url) browserUrl = url pageLines = {} currentPage = 1 local res, err = http.get(url) if not res then table.insert(pageLines, "Error loading page:") table.insert(pageLines, tostring(err or "Connection failed")) totalPages = 1 return end local content = res.readAll() res.close() -- Strip HTML tags if page looks like HTML if content:find(" 1 then currentPage = currentPage - 1 end elseif btn.action == "down" then if currentPage < totalPages then currentPage = currentPage + 1 end elseif btn.action == "save" then term.setCursorPos(2, screenH - 3) term.clearLine() term.setTextColor(colors.white) term.setBackgroundColor(colors.black) write("Save as filename: ") local fname = read() if fname ~= "" then local f = fs.open(fname, "w") f.write(table.concat(pageLines, "\n")) f.close() end elseif btn.action == "back" then currentScreen = "menu" end break end end end -- ========== Main Loop ========== while true do if currentScreen == "menu" then drawMenu() local _, _, x, y = os.pullEvent("mouse_click") for i = 1, #menuButtons do local btn = menuButtons[i] if pointInBox(x, y, btn.x, btn.y, btn.w, btn.h) then if btn.action == "browser" then currentScreen = "browser" elseif btn.action == "files" then openFileManager() elseif btn.action == "run" then openRunProgram() elseif btn.action == "shell" then term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(1, 1) print("Entered native shell. Type 'exit' to return.") shell.run("shell") elseif btn.action == "shutdown" then term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(1, 1) print("Shutting down...") sleep(0.5) os.shutdown() end break end end elseif currentScreen == "browser" then drawBrowser() local _, _, x, y = os.pullEvent("mouse_click") handleBrowserClick(x, y) end end