Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load and sort apps from the "apps" directory
- local apps = {}
- local appFiles = fs.list("apps")
- for i, file in ipairs(appFiles) do
- if not fs.isDir("apps/" .. file) and file:match("%.lua$") then
- local name = file:gsub("%.lua$", "")
- local icon = string.sub(name, 1, 1):upper()
- table.insert(apps, {name = name, icon = icon, program = "apps/" .. file, key = icon:lower()})
- end
- end
- table.sort(apps, function(a, b) return a.name < b.name end)
- -- Function to draw an app icon with key mapping
- function drawIcon(x, y, char, color, name, key)
- term.setBackgroundColor(color)
- for i = 0, 3 do
- term.setCursorPos(x, y + i)
- term.write(" ") -- 4-character wide block
- end
- term.setCursorPos(x + 1, y + 1)
- term.setTextColor(colors.white)
- term.write(char)
- term.setCursorPos(x, y + 3)
- term.setTextColor(colors.black)
- term.write(string.sub(name, 1, 4)) -- Truncated name
- term.setCursorPos(x + 2, y + 2)
- term.setTextColor(colors.yellow)
- term.write(key) -- Display key mapping
- end
- -- Function to draw the home screen
- function drawHomeScreen()
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- -- Draw status bar
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1, 1)
- term.clearLine()
- local timeStr = textutils.formatTime(os.time(), true)
- local status = "Time: " .. timeStr
- term.setCursorPos(26 - #status + 1, 1)
- term.setTextColor(colors.white)
- term.write(status)
- -- Draw app icons with key mappings
- for i = 1, math.min(20, #apps) do
- local row = math.floor((i - 1) / 5)
- local col = (i - 1) % 5
- local x = 1 + col * 5
- local y = 2 + row * 4
- drawIcon(x, y, apps[i].icon, colors.blue, apps[i].name, apps[i].key)
- end
- end
- -- Function to launch an app
- function launchApp(app)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- print("Launching " .. app.name .. "...")
- sleep(0.5) -- Brief delay for feedback
- shell.run(app.program)
- end
- -- Main loop
- while true do
- drawHomeScreen()
- local event, param1, param2, param3 = os.pullEvent()
- if event == "mouse_click" then
- local button, x, y = param1, param2, param3
- if y >= 2 and y <= 17 then
- local row = math.floor((y - 2) / 4) + 1
- if row >= 1 and row <= 4 then
- local col = math.floor((x - 1) / 5) + 1
- if col >= 1 and col <= 5 and (x - 1) % 5 < 4 then
- local appIndex = (row - 1) * 5 + col
- if appIndex <= #apps then
- launchApp(apps[appIndex])
- end
- end
- end
- end
- elseif event == "key" then
- local key = keys.getName(param1)
- for _, app in ipairs(apps) do
- if app.key == key then
- launchApp(app)
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment