Orion09

TouchQuartz OS

Mar 16th, 2025 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. -- Load and sort apps from the "apps" directory
  2. local apps = {}
  3. local appFiles = fs.list("apps")
  4. for i, file in ipairs(appFiles) do
  5. if not fs.isDir("apps/" .. file) and file:match("%.lua$") then
  6. local name = file:gsub("%.lua$", "")
  7. local icon = string.sub(name, 1, 1):upper()
  8. table.insert(apps, {name = name, icon = icon, program = "apps/" .. file, key = icon:lower()})
  9. end
  10. end
  11. table.sort(apps, function(a, b) return a.name < b.name end)
  12.  
  13. -- Function to draw an app icon with key mapping
  14. function drawIcon(x, y, char, color, name, key)
  15. term.setBackgroundColor(color)
  16. for i = 0, 3 do
  17. term.setCursorPos(x, y + i)
  18. term.write(" ") -- 4-character wide block
  19. end
  20. term.setCursorPos(x + 1, y + 1)
  21. term.setTextColor(colors.white)
  22. term.write(char)
  23. term.setCursorPos(x, y + 3)
  24. term.setTextColor(colors.black)
  25. term.write(string.sub(name, 1, 4)) -- Truncated name
  26. term.setCursorPos(x + 2, y + 2)
  27. term.setTextColor(colors.yellow)
  28. term.write(key) -- Display key mapping
  29. end
  30.  
  31. -- Function to draw the home screen
  32. function drawHomeScreen()
  33. term.setBackgroundColor(colors.lightBlue)
  34. term.clear()
  35. -- Draw status bar
  36. term.setBackgroundColor(colors.gray)
  37. term.setCursorPos(1, 1)
  38. term.clearLine()
  39. local timeStr = textutils.formatTime(os.time(), true)
  40. local status = "Time: " .. timeStr
  41. term.setCursorPos(26 - #status + 1, 1)
  42. term.setTextColor(colors.white)
  43. term.write(status)
  44. -- Draw app icons with key mappings
  45. for i = 1, math.min(20, #apps) do
  46. local row = math.floor((i - 1) / 5)
  47. local col = (i - 1) % 5
  48. local x = 1 + col * 5
  49. local y = 2 + row * 4
  50. drawIcon(x, y, apps[i].icon, colors.blue, apps[i].name, apps[i].key)
  51. end
  52. end
  53.  
  54. -- Function to launch an app
  55. function launchApp(app)
  56. term.setBackgroundColor(colors.black)
  57. term.clear()
  58. term.setCursorPos(1, 1)
  59. print("Launching " .. app.name .. "...")
  60. sleep(0.5) -- Brief delay for feedback
  61. shell.run(app.program)
  62. end
  63.  
  64. -- Main loop
  65. while true do
  66. drawHomeScreen()
  67. local event, param1, param2, param3 = os.pullEvent()
  68. if event == "mouse_click" then
  69. local button, x, y = param1, param2, param3
  70. if y >= 2 and y <= 17 then
  71. local row = math.floor((y - 2) / 4) + 1
  72. if row >= 1 and row <= 4 then
  73. local col = math.floor((x - 1) / 5) + 1
  74. if col >= 1 and col <= 5 and (x - 1) % 5 < 4 then
  75. local appIndex = (row - 1) * 5 + col
  76. if appIndex <= #apps then
  77. launchApp(apps[appIndex])
  78. end
  79. end
  80. end
  81. end
  82. elseif event == "key" then
  83. local key = keys.getName(param1)
  84. for _, app in ipairs(apps) do
  85. if app.key == key then
  86. launchApp(app)
  87. break
  88. end
  89. end
  90. end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment