-- Simple GUI OS v1.0 for CC:Tweaked -- Native API only, no extra libraries required local term = term local colors = colors local paintutils = paintutils -- Button definition: position, size, text, color, action local buttons = { {x=3, y=4, w=20, h=3, text="File Manager", color=colors.blue, action="list"}, {x=3, y=8, w=20, h=3, text="Run Program", color=colors.green, action="run"}, {x=3, y=12, w=20, h=3, text="Native Shell", color=colors.yellow, action="shell"}, {x=3, y=16, w=20, h=3, text="Shutdown", color=colors.red, action="shutdown"}, } -- Draw single button with optional highlight effect local function drawButton(btn, highlighted) local bgColor = highlighted and colors.lightGray or btn.color paintutils.drawFilledBox(btn.x, btn.y, btn.x + btn.w - 1, btn.y + btn.h - 1, bgColor) -- Center text on button local textX = btn.x + math.floor((btn.w - #btn.text) / 2) local textY = btn.y + math.floor(btn.h / 2) term.setCursorPos(textX, textY) term.setTextColor(colors.white) term.write(btn.text) end -- Render full UI interface local function drawUI() term.clear() local screenW, screenH = term.getSize() -- Top title bar paintutils.drawFilledBox(1, 1, screenW, 1, colors.gray) term.setCursorPos(2, 1) term.setTextColor(colors.white) term.write("Simple GUI OS v1.0") -- Draw all buttons for i = 1, #buttons do drawButton(buttons[i], false) end -- Bottom status bar paintutils.drawFilledBox(1, screenH, screenW, screenH, colors.gray) term.setCursorPos(2, screenH) term.setTextColor(colors.white) term.write("Left-click a button to continue") end -- Check if click point is inside a button 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 -- ========== Feature functions ========== local function listFiles() 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") end local function runProgram() 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 end -- ========== Main loop ========== while true do drawUI() -- Wait for mouse click (auto yields CPU) local event, clickBtn, x, y = os.pullEvent("mouse_click") -- Check which button was clicked for i = 1, #buttons do local btn = buttons[i] if pointInBox(x, y, btn.x, btn.y, btn.w, btn.h) then -- Click feedback animation drawButton(btn, true) sleep(0.1) -- Execute button action if btn.action == "list" then listFiles() elseif btn.action == "run" then runProgram() 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 end