Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {
- { name = "Command", x = 2, y = 3, width = 15, height = 1, color = colors.gray, command = "/disk/os/home.lua" },
- { name = "Programs", x = 2, y = 5, width = 15, height = 1, color = colors.gray, command = "/disk/os/programs" },
- { name = "Power Menu", x = 2, y = 7, width = 15, height = 1, color = colors.gray, command = "showPowerMenu" }
- }
- local function drawButton(button)
- term.setBackgroundColor(button.color)
- term.setTextColor(colors.white)
- term.setCursorPos(button.x, button.y)
- term.clearLine()
- term.write(" " .. button.name .. " ")
- end
- local function drawPowerMenu()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(2, 8)
- term.clearLine()
- term.write(" Shut Down ")
- term.setCursorPos(2, 9)
- term.clearLine()
- term.write(" Reboot ")
- term.setCursorPos(2, 10)
- term.clearLine()
- term.write(" Lock ")
- end
- local function drawHomescreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.write(" Doggy OS 12.0 ")
- term.setBackgroundColor(colors.black)
- for _, button in ipairs(buttons) do
- drawButton(button)
- end
- end
- local function handleAppClick(x, y)
- for _, button in ipairs(buttons) do
- if x >= button.x and x <= (button.x + button.width - 1) and y == button.y then
- term.setBackgroundColor(colors.black) -- Reset background color
- return button.command
- end
- end
- return nil
- end
- local function handlePowerMenuClick(x, y)
- if x >= 2 and x <= 16 then
- if y == 8 then
- term.setBackgroundColor(colors.black) -- Reset background color
- return "shutdown"
- elseif y == 9 then
- term.setBackgroundColor(colors.black) -- Reset background color
- return "reboot"
- elseif y == 10 then
- term.setBackgroundColor(colors.black) -- Reset background color
- return "lock"
- end
- end
- term.setBackgroundColor(colors.black) -- Reset background color
- return nil
- end
- local function launchApp(command)
- term.clear()
- term.setCursorPos(1, 1)
- -- Terminate the program
- os.pullEvent = os.pullEventRaw
- -- Launch the command or show power menu
- if command == "/disk/os/home.lua" or command == "/disk/os/programs" then
- shell.run(command)
- elseif command == "showPowerMenu" then
- drawPowerMenu()
- local event, _, x, y = os.pullEvent("mouse_click")
- local powerMenuCommand = handlePowerMenuClick(x, y)
- if powerMenuCommand then
- if powerMenuCommand == "shutdown" then
- os.shutdown()
- elseif powerMenuCommand == "reboot" then
- os.reboot()
- elseif powerMenuCommand == "lock" then
- shell.run("/disk/os/lock")
- end
- end
- else
- shell.run("start " .. command)
- end
- -- Re-enable the event handling
- os.pullEvent = os.pullEventRaw
- end
- local function homescreen()
- while true do
- drawHomescreen()
- local event, _, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- local appCommand = handleAppClick(x, y)
- if appCommand then
- launchApp(appCommand)
- return -- Terminate the program after launching the app or showing power menu
- end
- end
- end
- end
- homescreen()
Add Comment
Please, Sign In to add comment