Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- FEXPLORE IS PROPERTY OF SAM GUNNER.
- COPYRIGHT (C) 2014, SAM GUNNER. DO NOT COPY,
- MODIFY OR REDISTRIBUTE IN ANY WAY UNLESS GIVEN
- PERMISSION BY SAM GUNNER.
- - Sam Gunner
- ]]--
- -- Variables --
- local args = {...}
- rootDir = args[1]
- mode = args[2]
- exit = false
- -- Functions --
- function drawMain()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- for x=40, 51 do
- paintutils.drawLine(x,1,x,19,colors.gray)
- end
- paintutils.drawLine(1,1,51,1,colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- if dir == nil then
- write("/")
- elseif dir ~= "/" then
- write("/"..string.sub(dir,1,40))
- else
- write("/")
- end
- end
- function drawFiles()
- if dir == nil then
- if rootDir ~= nil then
- dir = "/"..rootDir
- else
- dir = "/"
- end
- end
- local lib = fs.list(dir)
- local folds = {}
- local files = {}
- for n, item in pairs (lib) do
- if mode == nil then
- if string.sub(item,1,1) ~= "." then
- local itemPath = fs.combine(dir,item)
- if fs.isDir(itemPath) then
- table.insert(folds,item)
- else
- table.insert(files,item)
- end
- end
- else
- local itemPath = fs.combine(dir, item)
- if fs.isDir(itemPath) then
- table.insert(folds,item)
- else
- table.insert(files,item)
- end
- end
- end
- foldNum = 1
- table.sort(folds)
- table.sort(files)
- term.setCursorPos(1,2)
- term.setBackgroundColor(colors.lightGray)
- for n, foldPrint in pairs(folds) do
- if n<18 then
- write("[] "..string.sub(foldPrint,1,37).."\n")
- foldNum = foldNum+1
- end
- end
- for n, filePrint in pairs(files) do
- if n<19-foldNum then
- write("() "..string.sub(filePrint,1,37).."\n")
- end
- end
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(40,2)
- if fileFin == 2 then
- if files[fileSelect] ~= nil then
- write(string.sub(files[fileSelect],1,12))
- testfiletest = files[fileSelect]
- else
- write("Was Nil")
- end
- term.setCursorPos(40,4)
- write(" ---------- ")
- term.setCursorPos(40,6)
- write(">> File <<")
- term.setCursorPos(40,9)
- write("[] Run []")
- term.setCursorPos(40,10)
- write("[] Edit []")
- term.setCursorPos(40,11)
- write("[] Rename []")
- term.setCursorPos(40,12)
- write("[] Delete []")
- term.setCursorPos(40,14)
- if fs.exists(fs.combine(dir,testfiletest)) then
- write(string.sub(fs.getSize(fs.combine(dir,testfiletest)),1,6).." Bytes")
- end
- elseif fileFin == 1 then
- if folds[fileSelect] ~= nil then
- write(string.sub(folds[fileSelect],1,12))
- testfiletest = folds[fileSelect]
- end
- term.setCursorPos(40,4)
- write(" ----------- ")
- term.setCursorPos(40,6)
- write(">> Folder <<")
- term.setCursorPos(40,9)
- write("[] Open []")
- term.setCursorPos(40,10)
- write("[] Rename []")
- term.setCursorPos(40,11)
- write("[] Delete []")
- end
- end
- function mouseAct()
- local event, b, x, y = os.pullEvent("mouse_click")
- if b == 1 and x==51 and y==1 then
- exit = true
- elseif b == 1 and x<40 and y>1 then
- fileSelect, fileFin = fileSec(y)
- elseif b == 1 and x>=40 and y>1 then
- fileOp(b,x,y)
- elseif b == 2 then
- contMenu(x,y)
- end
- end
- function contMenu(x,y)
- for y=y,y+4 do
- paintutils.drawLine(x,y,x+10,y,colors.gray)
- end
- term.setCursorPos(x,y)
- write("Go up")
- term.setCursorPos(x,y+1)
- write("New Folder")
- term.setCursorPos(x,y+2)
- write("New file")
- term.setCursorPos(x,y+3)
- write("Go to dir")
- term.setCursorPos(x,y+4)
- write("Exit")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 and xPos>=x and xPos<=xPos+10 and yPos==y then
- dir = fs.getDir(dir)
- end
- end
- function fileSec(yPos)
- if yPos>foldNum then
- local fileRet = (yPos-foldNum)
- return fileRet, 2
- else
- return yPos-1, 1
- end
- end
- function fileOp(b,x,y)
- if fileFin == 2 then
- if b == 1 and x>=40 and y==10 then
- shell.run("edit "..dir.."/"..testfiletest)
- elseif b == 1 and x>=40 and y==11 then
- paintutils.drawLine(40,17,51,17,colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(40,17)
- local inp = read()
- fs.move(testfiletest,inp)
- term.setTextColor(colors.white)
- elseif b == 1 and x>=40 and y==12 then
- paintutils.drawLine(41,17,43,17,colors.red)
- term.setCursorPos(41,17)
- write("[Y]")
- paintutils.drawLine(48,17,50,17,colors.green)
- term.setCursorPos(48,17)
- write("[N]")
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if button == 1 and x>=41 and x<=43 and y==17 then
- fs.delete(testfiletest)
- break
- elseif button == 1 and x>=48 and x<=50 and y==17 then
- break
- end
- end
- end
- elseif fileFin == 1 then
- if b == 1 and x>=40 and y==10 then
- dir = fs.combine(dir,testfiletest)
- elseif b ==1 and x>=40 and y==11 then
- paintutils.drawLine(40,17,51,17,colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(40,17)
- local inp = read()
- fs.move(testfiletest,inp)
- term.setTextColor(colors.white)
- elseif b==1 and x>=40 and y==12 then
- paintutils.drawLine(41,17,43,17,colors.red)
- term.setCursorPos(41,17)
- write("[Y]")
- paintutils.drawLine(48,17,50,17,colors.green)
- term.setCursorPos(48,17)
- write("[N]")
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if button == 1 and x>=41 and x<=43 and y==17 then
- fs.delete(testfiletest)
- break
- elseif button == 1 and x>=48 and x<=50 and y==17 then
- break
- end
- end
- end
- end
- end
- -- Startup --
- while true do
- drawMain()
- drawFiles()
- mouseAct()
- if exit == true then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement