Advertisement
DOGGYWOOF

Package deleter

Mar 29th, 2024
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. -- Function to handle navigation bar clicks
  2. function handleNavBarClick(x, y)
  3. local screenWidth, screenHeight = term.getSize()
  4. local navBarWidth = 20
  5. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  6.  
  7. if y == screenHeight then
  8. if x >= navBarStart + 5 and x <= navBarStart + 8 then
  9. -- Clicked on Home button
  10. shell.run("/disk/os/gui")
  11. return -- Terminate the program after running /disk/os/gui
  12. elseif x >= navBarStart + 10 and x <= navBarStart + 13 then
  13. -- Clicked on Recents button
  14. shell.run("/disk/os/recents")
  15. elseif x >= navBarStart + 15 and x <= navBarStart + 18 then
  16. -- Clicked on Back button
  17. -- Handle back button if needed
  18. end
  19. end
  20. end
  21.  
  22. -- Function to draw navigation bar
  23. function drawNavBar()
  24. local screenWidth, screenHeight = term.getSize()
  25. local navBarWidth = 20
  26. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  27.  
  28. -- Save current cursor position
  29. local oldX, oldY = term.getCursorPos()
  30.  
  31. -- Draw Home button
  32. term.setCursorPos(navBarStart + 5, screenHeight)
  33. term.setBackgroundColor(colors.black)
  34. term.setTextColor(colors.white)
  35. term.write(" Home ")
  36.  
  37. -- Draw Recents button
  38. term.setCursorPos(navBarStart + 10, screenHeight)
  39. term.setBackgroundColor(colors.black)
  40. term.setTextColor(colors.white)
  41. term.write(" Recents ")
  42.  
  43. -- Draw Back button
  44. term.setCursorPos(navBarStart + 15, screenHeight)
  45. term.setBackgroundColor(colors.black)
  46. term.setTextColor(colors.white)
  47. term.write(" Back ")
  48.  
  49. -- Restore cursor position
  50. term.setCursorPos(oldX, oldY)
  51. end
  52.  
  53. -- Function to list and delete packages
  54. function listAndDeletePackages()
  55. local packagesDir = "/disk/packages"
  56. local packages = fs.list(packagesDir)
  57.  
  58. -- Display package names
  59. for i, package in ipairs(packages) do
  60. term.setCursorPos(2, i + 1)
  61. print(package)
  62. end
  63.  
  64. -- Prompt user to select package for deletion
  65. print("Enter the number of the package you want to delete:")
  66. local packageNumber = tonumber(read())
  67.  
  68. -- Delete selected package
  69. if packageNumber and packageNumber > 0 and packageNumber <= #packages then
  70. local selectedPackage = packages[packageNumber]
  71. fs.delete(fs.combine(packagesDir, selectedPackage))
  72. print(selectedPackage .. " deleted successfully!")
  73. else
  74. print("Invalid package number!")
  75. end
  76. end
  77.  
  78. -- Main function
  79. function main()
  80. term.clear()
  81. drawNavBar()
  82. listAndDeletePackages()
  83. end
  84.  
  85. -- Run the main function
  86. main()
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement