-- GUI OS v2.0 with Text Web Browser -- Native CC:T API only, no extra libs local term = term local colors = colors local paintutils = paintutils local screenW, screenH = term.getSize() -- System state local currentScreen = "menu" -- menu / browser local browserUrl = "" local pageLines = {} local currentPage = 1 local totalPages = 1 local linesPerPage = screenH - 6 -- ========== UI Helper Functions ========== 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.write(text) 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 -- ========== Main Menu Screen ========== 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.clear() -- Title bar paintutils.drawFilledBox(1, 1, screenW, 1, colors.gray) term.setCursorPos(2, 1) term.setTextColor(colors.white) term.write("GUI OS v2.0") -- Buttons for i = 1, #menuButtons do local btn = menuButtons[i] drawButton(btn.x, btn.y, btn.w, btn.h, btn.text, btn.color) end -- Status bar paintutils.drawFilledBox(1, screenH, screenW, screenH, colors.gray) term.setCursorPos(2, screenH) term.setTextColor(colors.white) term.write("Click a button to continue") end -- ========== File Manager ========== local function openFileManager() term.clear() term.setCursorPos(1, 1) term.setTextColor(colors.white) term.setBackgroundColor(colors.black) 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.clear() term.setCursorPos(1, 1) term.setTextColor(colors.white) term.setBackgroundColor(colors.black) 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() -- Split content into lines for line in string.gmatch(content, "[^\n]+") do table.insert(pageLines, line) end if #pageLines == 0 then table.insert(pageLines, "(empty page)") end totalPages = math.max(1, math.ceil(#pageLines / linesPerPage)) end local function drawBrowser() term.clear() term.setBackgroundColor(colors.black) term.setTextColor(colors.white) -- Address bar paintutils.drawFilledBox(1, 1, screenW, 2, colors.lightGray) term.setCursorPos(2, 1) term.setTextColor(colors.black) term.write("URL: " .. (browserUrl ~= "" and browserUrl or "(not loaded)")) -- Page content local startLine = (currentPage - 1) * linesPerPage + 1 local endLine = math.min(startLine + linesPerPage - 1, #pageLines) for i = startLine, endLine do term.setCursorPos(1, 3 + (i - startLine)) term.write(pageLines[i]:sub(1, screenW)) end -- Page info term.setCursorPos(2, screenH - 3) term.setTextColor(colors.lightGray) term.write(string.format("Page %d / %d | Lines: %d", currentPage, totalPages, #pageLines)) -- Bottom buttons for i = 1, #browserButtons do local btn = browserButtons[i] drawButton(btn.x, btn.y, btn.w, btn.h, btn.text, btn.color) end end local function handleBrowserClick(x, y) for i = 1, #browserButtons do local btn = browserButtons[i] if pointInBox(x, y, btn.x, btn.y, btn.w, btn.h) then if btn.action == "url" then term.setCursorPos(2, screenH - 3) term.clearLine() term.setTextColor(colors.white) write("Enter URL: ") local url = read() if url ~= "" then loadPage(url) end elseif btn.action == "up" then if currentPage > 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) 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.clear() term.setCursorPos(1, 1) print("Entered native shell. Type 'exit' to return.") shell.run("shell") elseif btn.action == "shutdown" then 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