paramus

FileSystem

Aug 19th, 2025 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | Gaming | 0 0
  1. local path = ""
  2. local programs = {}
  3.  
  4. function Paint()
  5.     term.setTextColor(colors.white)
  6.     term.setBackgroundColour(colors.black)
  7.     term.clear()
  8.    
  9.     term.setCursorPos(1,1)
  10.     write("<")
  11.    
  12.     term.setCursorPos(3,1)
  13.     write("+")
  14.    
  15.     term.setCursorPos(5,1)
  16.     write(path)
  17.    
  18.     term.setTextColor(colors.black)
  19.     term.setBackgroundColour(colors.white)
  20.     programs = {}
  21.     local files = fs.list(path)
  22.     for i = 1, #files do
  23.         term.setCursorPos(1,i+2)
  24.         write(files[i])
  25.         programs[i] = {files[i], i+2}
  26.     end
  27. end
  28.  
  29. function Click(x, y)
  30.     if (x==1 and y == 1) then
  31.         if (path == "") then return end
  32.         path = fs.getDir(path)
  33.         return
  34.     elseif (x==3 and y == 1) then
  35.         term.setCursorPos(6 + string.len(path),1)
  36.         local fileName = read()
  37.         if (fileName == "") then
  38.             return
  39.         elseif (string.find(fileName, "%.") == nil) then
  40.             fs.makeDir(path .. "/" .. fileName)
  41.         else
  42.             local file = fs.open(path .. "/" .. fileName, "w")
  43.             file.close()
  44.         end
  45.         return
  46.     end
  47.    
  48.     for i = 1, #programs do
  49.         if (y == programs[i][2]) then
  50.             term.clear()
  51.             term.setCursorPos(1,1)
  52.             write(programs[i][1])
  53.             if (string.find(programs[i][1], "%.") ~= nil) then
  54.                 local prog
  55.                 if (string.find(programs[i][1], ".nfp") ~= nil or string.find(programs[i][1], ".nft") ~= nil) then
  56.                     prog = shell.openTab("paint " .. path .. "/" .. programs[i][1])
  57.                 else
  58.                     prog = shell.openTab("edit " .. path .. "/" .. programs[i][1])
  59.                 end
  60.                 multishell.setFocus(prog)
  61.                 multishell.setTitle(prog, programs[i][1])
  62.             else
  63.                 path = path .. "/" .. programs[i][1]
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. while (true) do
  70.     Paint()
  71.     local event, button, x, y = os.pullEvent("mouse_click")
  72.     Click(x, y)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment