Advertisement
DOGGYWOOF

Doggy OS apps launcher

Jan 25th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. -- Get the current username from the status file
  2. local function getCurrentUser()
  3. local file = fs.open(".currentusr", "r")
  4. if file then
  5. local username = file.readLine()
  6. file.close()
  7. return username
  8. else
  9. error("Failed to read current username")
  10. end
  11. end
  12.  
  13. -- List all files in the user's packages directory
  14. local function listPrograms(username)
  15. local packagePath = "/disk/users/" .. username .. "/packages"
  16. if not fs.exists(packagePath) then
  17. error("Packages directory not found")
  18. end
  19.  
  20. local programs = fs.list(packagePath)
  21. if #programs == 0 then
  22. return nil
  23. end
  24. return programs
  25. end
  26.  
  27. -- Draw the UI for the launcher
  28. local function drawUI(programs, selected)
  29. term.clear()
  30. term.setCursorPos(1, 1)
  31. print("---- Program Launcher ----")
  32. print("Use UP/DOWN to navigate, ENTER to run, Q to quit.")
  33.  
  34. -- Display programs in a list format
  35. for i, program in ipairs(programs) do
  36. if i == selected then
  37. term.setTextColor(colors.yellow)
  38. print("> " .. program)
  39. term.setTextColor(colors.white)
  40. else
  41. print(" " .. program)
  42. end
  43. end
  44. end
  45.  
  46. -- Main loop to handle user input and selection
  47. local function launcherUI(username, programs)
  48. local selected = 1
  49. drawUI(programs, selected)
  50.  
  51. while true do
  52. local event, key = os.pullEvent("key")
  53. if key == keys.up then
  54. if selected > 1 then
  55. selected = selected - 1
  56. drawUI(programs, selected)
  57. end
  58. elseif key == keys.down then
  59. if selected < #programs then
  60. selected = selected + 1
  61. drawUI(programs, selected)
  62. end
  63. elseif key == keys.enter then
  64. local selectedProgram = programs[selected]
  65. shell.run("/disk/users/" .. username .. "/packages/" .. selectedProgram)
  66. break -- After running a program, quit the launcher
  67. elseif key == keys.q then
  68. break -- Quit the launcher
  69. end
  70. end
  71. end
  72.  
  73. -- Main program execution
  74. local function main()
  75. local username = getCurrentUser()
  76. local programs = listPrograms(username)
  77.  
  78. if programs then
  79. launcherUI(username, programs)
  80. else
  81. term.clear()
  82. term.setCursorPos(1, 1)
  83. print("No programs found.")
  84. end
  85. end
  86.  
  87. -- Execute the program
  88. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement