JustJurt

script launcher

Feb 19th, 2025 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1.  
  2. local scripts_folder = fs.list("scripts")
  3.  
  4. local scripts = {}
  5.  
  6. for i, script in ipairs(scripts_folder) do
  7.     if string.sub(script, -4) == ".lua" then
  8.         table.insert(scripts, script)
  9.     end
  10. end
  11.  
  12. term.clear()
  13. term.setCursorPos(2, 2)
  14.  
  15. print("Select script")
  16.  
  17. for i, script in ipairs(scripts) do
  18.     term.setCursorPos(4, 2 + i * 2)
  19.     print(script)
  20. end
  21.  
  22. Cursor = 1
  23.  
  24. function Move_cursor(direction)
  25.  
  26.     term.setCursorPos(2, 2 + Cursor * 2)
  27.     print(" ")
  28.  
  29.     if direction == "up" then
  30.         Cursor = Cursor - 1
  31.     elseif direction == "down" then
  32.         Cursor = Cursor + 1
  33.     end
  34.  
  35.     if Cursor < 1 then
  36.         Cursor = #scripts
  37.     elseif Cursor > #scripts then
  38.         Cursor = 1
  39.     end
  40.  
  41.     term.setCursorPos(2, 2 + Cursor * 2)
  42.     print(">")
  43. end
  44.  
  45. Move_cursor(nil)
  46.  
  47. while true do
  48.     local event, key = os.pullEvent("key")
  49.     print(keys.getName(key))
  50.     key = keys.getName(key)
  51.     Move_cursor(key)
  52.     if key == "enter" then
  53.         term.clear()
  54.         term.setCursorPos(1, 1)
  55.         shell.run("scripts/" .. scripts[Cursor])
  56.         break
  57.     end
  58. end
  59.  
Advertisement
Add Comment
Please, Sign In to add comment