Advertisement
Guest User

fexplore

a guest
Dec 20th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.64 KB | None | 0 0
  1. --[[
  2.  
  3.   FEXPLORE IS PROPERTY OF SAM GUNNER.
  4.   COPYRIGHT (C) 2014, SAM GUNNER. DO NOT COPY,
  5.   MODIFY OR REDISTRIBUTE IN ANY WAY UNLESS GIVEN
  6.   PERMISSION BY SAM GUNNER.
  7.  
  8.   - Sam Gunner
  9.  
  10. ]]--
  11.  
  12. -- Variables --
  13. local args = {...}
  14. rootDir = args[1]
  15. mode = args[2]
  16. exit = false
  17.  
  18. -- Functions --
  19. function drawMain()
  20.   term.setBackgroundColor(colors.lightGray)
  21.   term.clear()
  22.   for x=40, 51 do
  23.     paintutils.drawLine(x,1,x,19,colors.gray)
  24.   end
  25.   paintutils.drawLine(1,1,51,1,colors.gray)
  26.   term.setTextColor(colors.white)
  27.   term.setCursorPos(1,1)
  28.   if dir == nil then
  29.     write("/")
  30.   elseif dir ~= "/" then
  31.     write("/"..string.sub(dir,1,40))
  32.   else
  33.     write("/")
  34.   end
  35.  
  36. end
  37.  
  38.  
  39. function drawFiles()
  40.   if dir == nil then
  41.     if rootDir ~= nil then
  42.       dir = "/"..rootDir
  43.     else
  44.       dir = "/"
  45.     end
  46.   end
  47.   local lib = fs.list(dir)
  48.   local folds = {}
  49.   local files = {}
  50.   for n, item in pairs (lib) do
  51.     if mode == nil then
  52.       if string.sub(item,1,1) ~= "." then
  53.         local itemPath = fs.combine(dir,item)
  54.         if fs.isDir(itemPath) then
  55.           table.insert(folds,item)
  56.         else
  57.           table.insert(files,item)
  58.         end
  59.       end
  60.     else
  61.       local itemPath = fs.combine(dir, item)
  62.       if fs.isDir(itemPath) then
  63.         table.insert(folds,item)
  64.       else
  65.         table.insert(files,item)
  66.       end
  67.     end
  68.   end
  69.   foldNum = 1
  70.   table.sort(folds)
  71.   table.sort(files)
  72.   term.setCursorPos(1,2)
  73.   term.setBackgroundColor(colors.lightGray)
  74.   for n, foldPrint in pairs(folds) do
  75.     if n<18 then
  76.       write("[] "..string.sub(foldPrint,1,37).."\n")
  77.       foldNum = foldNum+1
  78.     end
  79.   end
  80.   for n, filePrint in pairs(files) do
  81.     if n<19-foldNum then
  82.       write("() "..string.sub(filePrint,1,37).."\n")
  83.     end
  84.   end
  85.   term.setBackgroundColor(colors.gray)
  86.   term.setCursorPos(40,2)
  87.   if fileFin == 2 then
  88.     if files[fileSelect] ~= nil then
  89.       write(string.sub(files[fileSelect],1,12))
  90.       testfiletest = files[fileSelect]
  91.     else
  92.     write("Was Nil")
  93.     end
  94.     term.setCursorPos(40,4)
  95.     write(" ---------- ")
  96.     term.setCursorPos(40,6)
  97.     write(">>  File  <<")
  98.     term.setCursorPos(40,9)
  99.     write("[]  Run   []")
  100.     term.setCursorPos(40,10)
  101.     write("[]  Edit  []")
  102.     term.setCursorPos(40,11)
  103.     write("[] Rename []")
  104.     term.setCursorPos(40,12)
  105.     write("[] Delete []")
  106.     term.setCursorPos(40,14)
  107.     if fs.exists(fs.combine(dir,testfiletest)) then
  108.       write(string.sub(fs.getSize(fs.combine(dir,testfiletest)),1,6).." Bytes")
  109.     end
  110.   elseif fileFin == 1 then
  111.     if folds[fileSelect] ~= nil then
  112.       write(string.sub(folds[fileSelect],1,12))
  113.       testfiletest = folds[fileSelect]
  114.     end
  115.     term.setCursorPos(40,4)
  116.     write(" ----------- ")
  117.     term.setCursorPos(40,6)
  118.     write(">> Folder <<")
  119.     term.setCursorPos(40,9)
  120.     write("[]  Open  []")
  121.     term.setCursorPos(40,10)
  122.     write("[] Rename []")
  123.     term.setCursorPos(40,11)
  124.     write("[] Delete []")
  125.   end
  126. end
  127.  
  128. function mouseAct()
  129.   local event, b, x, y = os.pullEvent("mouse_click")
  130.   if b == 1 and x==51 and y==1 then
  131.     exit = true
  132.   elseif b == 1 and x<40 and y>1 then
  133.     fileSelect, fileFin = fileSec(y)
  134.   elseif b == 1 and x>=40 and y>1 then
  135.     fileOp(b,x,y)
  136.   elseif b == 2 then
  137.     contMenu(x,y)
  138.   end
  139. end
  140.  
  141. function contMenu(x,y)
  142.   for y=y,y+4 do
  143.     paintutils.drawLine(x,y,x+10,y,colors.gray)
  144.   end
  145.   term.setCursorPos(x,y)
  146.   write("Go up")
  147.   term.setCursorPos(x,y+1)
  148.   write("New Folder")
  149.   term.setCursorPos(x,y+2)
  150.   write("New file")
  151.   term.setCursorPos(x,y+3)
  152.   write("Go to dir")
  153.   term.setCursorPos(x,y+4)
  154.   write("Exit")
  155.   local event, button, xPos, yPos = os.pullEvent("mouse_click")
  156.   if button == 1 and xPos>=x and xPos<=xPos+10 and yPos==y then
  157.     dir = fs.getDir(dir)
  158.   end
  159. end
  160.  
  161. function fileSec(yPos)
  162.   if yPos>foldNum then
  163.     local fileRet = (yPos-foldNum)
  164.     return fileRet, 2
  165.   else
  166.     return yPos-1, 1
  167.   end
  168. end
  169.  
  170. function fileOp(b,x,y)
  171.   if fileFin == 2 then
  172.   if b == 1 and x>=40 and y==10 then
  173.     shell.run("edit "..dir.."/"..testfiletest)
  174.   elseif b == 1 and x>=40 and y==11 then
  175.     paintutils.drawLine(40,17,51,17,colors.white)
  176.     term.setTextColor(colors.black)
  177.     term.setCursorPos(40,17)
  178.     local inp = read()
  179.     fs.move(testfiletest,inp)
  180.     term.setTextColor(colors.white)
  181.   elseif b == 1 and x>=40 and y==12 then
  182.     paintutils.drawLine(41,17,43,17,colors.red)
  183.     term.setCursorPos(41,17)
  184.     write("[Y]")
  185.     paintutils.drawLine(48,17,50,17,colors.green)
  186.     term.setCursorPos(48,17)
  187.     write("[N]")
  188.     while true do
  189.       local event, button, x, y = os.pullEvent("mouse_click")
  190.       if button == 1 and x>=41 and x<=43 and y==17 then
  191.         fs.delete(testfiletest)
  192.         break
  193.       elseif button == 1 and x>=48 and x<=50 and y==17 then
  194.         break
  195.       end
  196.     end
  197.   end
  198.   elseif fileFin == 1 then
  199.     if b == 1 and x>=40 and y==10 then
  200.       dir = fs.combine(dir,testfiletest)
  201.     elseif b ==1 and x>=40 and y==11 then
  202.       paintutils.drawLine(40,17,51,17,colors.white)
  203.       term.setTextColor(colors.black)
  204.       term.setCursorPos(40,17)
  205.       local inp = read()
  206.       fs.move(testfiletest,inp)
  207.       term.setTextColor(colors.white)
  208.     elseif b==1 and x>=40 and y==12 then
  209.           paintutils.drawLine(41,17,43,17,colors.red)
  210.     term.setCursorPos(41,17)
  211.     write("[Y]")
  212.     paintutils.drawLine(48,17,50,17,colors.green)
  213.     term.setCursorPos(48,17)
  214.     write("[N]")
  215.     while true do
  216.       local event, button, x, y = os.pullEvent("mouse_click")
  217.       if button == 1 and x>=41 and x<=43 and y==17 then
  218.         fs.delete(testfiletest)
  219.         break
  220.       elseif button == 1 and x>=48 and x<=50 and y==17 then
  221.         break
  222.       end
  223.     end
  224.   end
  225. end
  226. end
  227.  
  228. -- Startup --
  229. while true do
  230.   drawMain()
  231.   drawFiles()
  232.   mouseAct()
  233.   if exit == true then
  234.     break
  235.   end
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement