Guest User

DevFileManager

a guest
Nov 16th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local args = {...}
  2. local dir = "DevOS/SystemFiles"
  3. local w,h = term.getSize()
  4.  
  5. local endat = 0
  6.  
  7. if args[1] and fs.exists(args[1]) then
  8.   dir = args[1]
  9. end
  10. local scrol = 0
  11. function scroll()
  12.   while true do
  13.     local e,d,x,y = os.pullEvent("mouse_scroll")
  14.     if scrol ~= 0 or d ~= -1 then
  15.       if endat >= h or d == -1 then
  16.         scrol = scrol + d
  17.         redraw()
  18.       end
  19.     end
  20.   end
  21. end
  22.  
  23. function redraw()
  24.   buttonapis.clearButtons()
  25.   buttonapis.clearFunctions()
  26.   term.setBackgroundColor(colors.lightBlue)
  27.   term.setTextColor(colors.white)
  28.   term.clear()
  29.   local dirs = {}
  30.   local files = {}
  31.   for ii,vv in pairs(fs.list(dir))do --SORT
  32.     if fs.isDir(dir.."/"..vv)then
  33.       table.insert(dirs,vv)
  34.     end
  35.   end
  36.   for iii,vvv in pairs(fs.list(dir))do
  37.     if not fs.isDir(dir.."/"..vvv)then
  38.       table.insert(files,vvv)
  39.     end
  40.   end
  41.   for iiii,vvvv in pairs(files)do
  42.     table.insert(dirs,vvvv)
  43.   end
  44.   local list = dirs
  45.   x = 5
  46.   y = 2-scrol
  47.   for i,v in pairs(list)do
  48.     local image
  49.     if fs.isDir(dir.."/"..v) then
  50.       image = paintutils.loadImage("DevOS/Images/DFMFolder")
  51.       bfunctions[v] = function(x,y,name)
  52.         dir = dir.."/"..name
  53.         redraw()
  54.       end
  55.     else
  56.       image = paintutils.loadImage("DevOS/Images/DFMFile")
  57.       bfunctions[v] = function(x,y,name)
  58.         buttonapis.clearButtons()
  59.         buttonapis.clearFunctions()
  60.         redraw()
  61.       end
  62.     end
  63.     paintutils.drawImage(image,x,y)
  64.     local n = v
  65.     if #v > 8 then
  66.       n = v:sub(1,6)..".."
  67.     end
  68.     term.setCursorPos(x,y+4)
  69.     term.setBackgroundColor(colors.lightBlue)
  70.     term.setTextColor(colors.white)
  71.     term.write(n)
  72.     buttonapis.addButton(x,y,x+5,y+5,v)
  73.     x = x + 9
  74.     if x + 9 >= w then
  75.       x = 5
  76.       y = y + 7
  77.     end
  78.   end
  79.   endat = y+4
  80.   term.setCursorPos(1,1)
  81.   term.clearLine()
  82.   term.write(":/"..dir.."/")
  83. end
  84.  
  85. parallel.waitForAll(redraw,scroll)
Advertisement
Add Comment
Please, Sign In to add comment