Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. local function filePicker(path)
  2. local y = 1
  3. local list = fs.list(path)
  4. local maxX, maxY = term.getSize()
  5.  
  6. term.clear()
  7. for i = y, y + maxY - 1 do
  8. if not list[i] then break end
  9. term.setCursorPos(1, i - y + 1)
  10. term.write(i .. " : " .. list[i])
  11. end
  12.  
  13. while true do
  14. local myEvent = {os.pullEvent()}
  15.  
  16. if myEvent[1] == "mouse_scroll" then
  17. if myEvent[2] == 1 and y < #list - maxY + 1 then
  18. y = y + 1
  19. elseif myEvent[2] == -1 and y ~= 0 then
  20. y = y - 1
  21. end
  22.  
  23. term.clear()
  24. for i = y, y + maxY - 1 do
  25. if not list[i] then break end
  26. term.setCursorPos(1, i - y + 1)
  27. term.write(i .. " : " .. list[i])
  28. end
  29. elseif myEvent[1] == "mouse_click" then
  30. return list[myEvent[4] + y - 1]
  31. end
  32. end
  33. end
  34.  
  35. local result = filePicker("Items/")
  36. shell.run(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement