Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local root = "/DreamOS/"
- local curDir = ""
- local curDirs = {
- [1] = root
- }
- for k,v in pairs(curDirs) do
- curDir = curDir..v
- end
- local selectedFile = ""
- local SFIsDir = false
- local SFPos = 0
- local sbSelected = 0
- local clipBoard = ""
- local clipBoardFileName = ""
- local clipBoardIsDir = false
- local slc = 0
- local brunning = true
- local scroll = 0
- local scrollEnabled = false
- local fileList = {}
- local notInFile = true
- local w,h = term.getSize()
- h = h - 1
- local function newFile()
- local curError = "none"
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setTextColor(colors.black)
- term.setCursorPos(1,h+1)
- write(">")
- term.setCursorPos(2,h+1)
- local newFileInput = read()
- if newFileInput == "" then
- curError = "Must specify file name."
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setTextColor(colors.red)
- print(curError)
- sleep(3)
- else
- local newFileExists = false
- for k,v in pairs(fileList) do
- if v == newFileInput and fs.isDir(curDir..v) == false then
- newFileExists = true
- end
- end
- if newFileExists then
- curError = "File exists."
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.red)
- print(curError)
- sleep(3)
- else
- local newFileOpen = fs.open(curDir..newFileInput,"w")
- newFileOpen.write(" ")
- newFileOpen.close()
- end
- end
- end
- local function newFolder()
- local curError = "none"
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setTextColor(colors.black)
- term.setCursorPos(1,h+1)
- write(">")
- term.setCursorPos(2,h+1)
- local newFileInput = read()
- if newFileInput == "" then
- curError = "Must specify folder name."
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setTextColor(colors.red)
- print(curError)
- sleep(3)
- else
- local newFileExists = false
- for k,v in pairs(fileList) do
- if v == newFileInput and fs.isDir(curDir..v) then
- newFileExists = true
- end
- end
- if newFileExists then
- curError = "Folder exists."
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.red)
- print(curError)
- sleep(3)
- else
- shell.run("mkdir",curDir..newFileInput)
- end
- end
- end
- local function editFile()
- if SFIsDir == false then
- shell.run("edit",curDir..selectedFile)
- end
- end
- local function renameFile()
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setTextColor(colors.black)
- write(">")
- write(curDir)
- local renameInput = io.read()
- shell.run("rename",curDir..selectedFile,curDir..renameInput)
- end
- local function copyFile()
- clipBoard = curDir..selectedFile
- clipBoardFileName = selectedFile
- if fs.isDir(clipBoard) then
- clipBoardIsDir = true
- end
- term.setCursorPos(1,h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setCursorPos(1,h+1)
- term.setTextColor(colors.black)
- print("Copied")
- sleep(2)
- end
- local function paste()
- shell.run("copy",clipBoard,curDir..clipBoardFileName)
- end
- local function moveFile()
- term.setCursorPos(1,10)
- local moving = true
- local selectedMoveFolder = ""
- while moving do
- sleep(0.1)
- local i = 0
- term.setBackgroundColor(colors.lightBlue)
- while i <= h-1 do
- i = i + 1
- term.setCursorPos(w-10,i)
- print(" ")
- end
- local mD = 0
- term.setBackgroundColor(colors.white)
- while mD <= h-2 do
- mD = mD + 1
- term.setCursorPos(2,mD+1)
- local mD2 = 0
- while mD2 <= (w-13) do
- mD2 = mD2 + 1
- write(" ")
- end
- end
- local moveFiles = fs.list(curDir)
- moveFilesList = {}
- -- This makes it so dirs always show first
- for k,v in pairs(moveFiles) do
- if fs.isDir(curDir..v) then
- table.insert(moveFilesList, v)
- end
- end
- for k,v in pairs(moveFilesList) do
- if fs.isDir(curDir..v) then
- if k > scroll and k <= (h-3)+scroll then
- if selectedMoveFolder == v then
- term.setBackgroundColor(colors.blue)
- local d = 0
- while d <= w-14 do
- d = d + 1
- term.setCursorPos(2+d,(k+1)-scroll)
- write(" ")
- end
- else
- term.setBackgroundColor(colors.white)
- end
- term.setCursorPos(2,(k+1)-scroll)
- term.setTextColor(colors.gray)
- write("[")
- term.setTextColor(colors.orange)
- write("\\")
- term.setTextColor(colors.gray)
- write("]")
- term.setTextColor(colors.green)
- write(v)
- end
- end
- end
- term.setCursorPos((w-7),5)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightBlue)
- write("Cancel")
- e = {os.pullEvent()}
- if e[1] == "mouse_click" and e[2] == 1 then
- for k,v in pairs(moveFilesList) do
- if e[3]>=2 and e[3]<=#v+4 and e[4]==k+1 then
- if selectedMoveFolder == v then
- shell.run("move",curDir..selectedFile,curDir..v)
- moving = false
- else
- selectedMoveFolder = v
- end
- end
- end
- if e[3] >=(w-7) and e[3] <=(w-7)+6 and e[4] == 5 then
- moving = false
- return
- end
- end
- end
- end
- local sbMenu = {
- [1] = {txt = "Edit", fileOnly = true, cmd = function() editFile() end},
- [2] = {txt = "Rename", fileOnly = false, cmd = function() renameFile() end},
- [3] = {txt = "Copy", fileOnly = false, cmd = function() copyFile() end},
- [4] = {txt = "Move", fileOnly = false, cmd = function() moveFile() end},
- [5] = {txt = "Delete", fileOnly = false, cmd = function() deleteFile() end},
- [6] = {txt = "Unselect", fileOnly = false, cmd = function() sbSelected = 0; selectedFile = ""; SFIsDir = false slc = 0; end}
- }
- local sbMenuNone = {
- [1] = {txt = "New File", cmd = function() newFile() end},
- [2] = {txt = "New Folder", cmd = function() newFolder() end},
- [3] = {txt = "Paste", cmd = function() paste() end}
- }
- local function drawFiles()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.orange)
- term.setCursorPos(2,2)
- write(curDir)
- term.setTextColor(colors.orange)
- term.setCursorPos(2,3)
- write("..")
- local files = fs.list(curDir)
- fileList = {}
- -- This makes it so dirs always show first
- for k,v in pairs(files) do
- if fs.isDir(curDir..v) then
- table.insert(fileList, v)
- end
- end
- for k,v in pairs(files) do
- if not fs.isDir(curDir..v) then
- table.insert(fileList, v)
- end
- end
- for k,v in pairs(fileList) do
- if k > scroll and k <= (h-3)+scroll then
- if selectedFile == v then
- term.setBackgroundColor(colors.blue)
- local d = 0
- while d <= w-14 do
- d = d + 1
- term.setCursorPos(2+d,(k+3)-scroll)
- write(" ")
- end
- else
- term.setBackgroundColor(colors.white)
- end
- if fs.isDir(curDir..v) then
- term.setCursorPos(2,(k+3)-scroll)
- term.setTextColor(colors.gray)
- write("[")
- term.setTextColor(colors.orange)
- write("\\")
- term.setTextColor(colors.gray)
- write("]")
- term.setTextColor(colors.green)
- write(v)
- else
- term.setCursorPos(2,(k+3)-scroll)
- term.setTextColor(colors.gray)
- write("[")
- term.setTextColor(colors.lime)
- write("=")
- term.setTextColor(colors.gray)
- write("]")
- term.setTextColor(colors.black)
- write(v)
- end
- end
- end
- if #fileList > h-1 then scrollEnabled = true; end
- end
- local function drawMain()
- -- Have to put this here so it doesn't count slc being changed in one loop
- if selectedFile == "" then slc = 0 else slc = 1 end
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(1,1)
- term.clearLine()
- term.setTextColor(colors.white)
- write("[Close]")
- -- Side bar
- term.setBackgroundColor(colors.lightBlue)
- local i = 0
- while i <= h-1 do
- i = i + 1
- term.setCursorPos(w-10,i)
- print(" ")
- end
- term.setCursorPos(1, h+1)
- term.setBackgroundColor(colors.green)
- term.clearLine()
- term.setTextColor(colors.black)
- write("DreamOS File Manager")
- term.setCursorPos(w-#selectedFile, h+1)
- write(selectedFile)
- if slc == 0 then
- for k,v in pairs(sbMenuNone) do
- if sbSelected == k then
- term.setBackgroundColor(colors.blue)
- else
- term.setBackgroundColor(colors.lightBlue)
- end
- term.setCursorPos((w-5)-#v.txt/2,(k+1))
- write(v.txt)
- end
- elseif slc == 1 then
- -- Options
- for k,v in pairs(sbMenu) do
- if sbSelected == k then
- term.setBackgroundColor(colors.blue)
- else
- term.setBackgroundColor(colors.lightBlue)
- end
- if v.fileOnly == true and SFIsDir then else
- term.setCursorPos((w-5)-#v.txt/2,(k+1))
- write(v.txt)
- end
- end
- end
- -- Scroll
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- i = 0
- while i <= (h+1)-3 do
- i = i + 1
- term.setCursorPos(1,i+1)
- if i == 1 then
- write("^")
- elseif i == (h+1)-2 then
- write("v")
- else
- write(" ")
- end
- end
- drawFiles()
- end
- while brunning do
- sleep(0.1)
- drawMain()
- if slc == 0 then
- selectedFile = ""
- SFIsDir = false
- end
- if notInFile then
- e = {os.pullEvent()}
- if e[1] == "mouse_click" and e[2] == 1 then
- for k,v in pairs(fileList) do
- if e[3]>=2 and e[3]<=w-11 and e[4] == k+3-scroll then
- if selectedFile == v then else
- selectedFile = v
- if fs.isDir(curDir..v) then
- SFIsDir = true
- else
- SFIsDir = false
- end
- if slc == 1 then slc = 0 end
- sbSelected = 0
- SFPos = k
- end
- end
- end
- if slc == 1 then
- for k,v in pairs(sbMenu) do
- if e[3]>=((w-5)-#v.txt/2) and e[3]<=((w-5)+#v.txt/2) and e[4] == k+1 then
- if sbSelected == k then
- v.cmd()
- else
- sbSelected = k
- end
- end
- end
- -- Click on file/folder
- if e[3]>=2 and e[3]<=w-14 and e[4] == (SFPos+3)-scroll then
- if SFIsDir then
- table.insert(curDirs, selectedFile.."/")
- curDir = ""
- for k,v in pairs(curDirs) do
- curDir = curDir..v
- end
- selectedFile = ""
- SFIsDir = false
- else
- term.setCursorPos(1,h+1)
- shell.run(curDir..selectedFile)
- end
- end
- elseif slc == 0 then
- for k,v in pairs(sbMenuNone) do
- if e[3]>=((w-5)-#v.txt/2) and e[3]<=((w-5)-#v.txt/2)+(#v.txt/2) and e[4] == k+1 then
- if sbSelected == k then
- v.cmd()
- else
- sbSelected = k
- end
- end
- end
- end
- if e[3]>=1 and e[3]<=7 and e[4] == 1 then
- term.clear()
- brunning = false
- elseif e[3]>=2 and e[3]<=4 and e[4]==3 then
- table.remove(curDirs,#curDirs)
- local getNewDir = ""
- for k,v in pairs(curDirs) do
- getNewDir = getNewDir..v
- end
- if string.find(getNewDir,root) then --Make sure not escaping root
- curDir = getNewDir
- else
- table.insert(curDirs,curDir)
- end
- end
- if scrollEnabled then
- if e[3]==1 and e[4] == 2 then
- if scroll > 0 then
- scroll = scroll - 1
- end
- elseif e[3]==1 and e[4] == h then
- if scroll < #fileList then
- scroll = scroll + 1
- end
- end
- end
- elseif e[1] == "mouse_scroll" then
- if e[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- end
- elseif e[2] == 1 then
- if scroll < #fileList then
- scroll = scroll + 1
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement