Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Main Code
- nSelect = 1
- w, h = term.getSize()
- --Fix Read
- shell.run("rom/apis/.fixread")
- --Functions
- function fileSelect()
- local function getTypes(rootLoc)
- rootLoc = rootLoc or "/"
- if rootLoc == "" then rootLoc = "/" end
- local items = fs.list(rootLoc)
- local function CheckForHiddenFiles( tFiles )
- for index,value in ipairs( tFiles ) do
- if string.sub( value, 1, 1 ) == "." then
- table.remove( tFiles, index )
- return true, tFiles
- end
- end
- return false
- end
- bCount = 0
- for b = 1, #items do
- local IsFound, items = CheckForHiddenFiles( items )
- if not IsFound then
- break
- end
- end
- local types = {}
- if not rootLock == "/" then
- table.insert(items, 1, "..")
- table.insert(types, 1, "up")
- end
- for i = 1, #items do
- if fs.isDir(rootLoc .. items[i]) then
- table.insert(types, "dir")
- else
- table.insert(types, "file")
- end
- end
- return items, types
- end
- local rootLoc = ""
- local function drawGUI(items, rootLoc, types)
- local selection = 1
- local scroll = 0
- while true do
- term.clear()
- term.setCursorPos(1,1)
- write(" | File Selection: " .. rootLoc)
- term.setCursorPos(50,1)
- write("|")
- term.setCursorPos(1,2)
- write(" +-----------------------------------------------+")
- for i = 1+scroll, #types do
- term.setCursorPos(45, (i+2)-scroll)
- write(types[i])
- end
- for d = 1+scroll, #items do
- term.setCursorPos(3, (d+2)-scroll)
- write(items[d])
- end
- local length = string.len(items[selection])
- term.setCursorPos(2, (selection+2)-scroll)
- term.write("[")
- term.setCursorPos(3+length, (selection+2)-scroll)
- term.write("]")
- event, key = os.pullEvent("key")
- if key == 208 then
- term.setCursorPos(2, (selection+2)-scroll)
- term.write(" ")
- term.setCursorPos(3+length, (selection+2)-scroll)
- term.write(" ")
- if selection == #items then
- elseif selection == scroll+16 then
- selection = selection+1
- scroll = scroll+1
- else
- selection = selection+1
- end
- elseif key == 200 then
- term.setCursorPos(2, (selection+2)-scroll)
- term.write(" ")
- term.setCursorPos(3+length, (selection+2)-scroll)
- term.write(" ")
- if selection == 1 then
- elseif selection == scroll+1 then
- selection = selection-1
- scroll = scroll-1
- else
- selection = selection-1
- end
- elseif key == 28 then
- return(items[selection])
- else
- end
- end
- end
- while fs.isDir(rootLoc) or rootLoc == ".." do
- if rootLoc == ".." then
- local rootPos = string.find(oldRootLoc:reverse(), "/")*-1
- rootLoc = oldRootLoc.sub(1, rootPos)
- end
- rootLoc = (rootLoc .. "/")
- local items, types = getTypes(rootLoc)
- local oldRootLoc = rootLoc
- rootLoc = (rootLoc .. drawGUI(items, rootLoc, types))
- end
- return rootLoc
- end
- function clear() term.clear(); term.setCursorPos(1,1) end
- function cWrite(textData, yData)
- local h,w = term.getSize()
- local xd,yd = term.getCursorPos()
- term.setCursorPos(math.ceil(w/2 - textData:len()/2), yd)
- write(textData)
- end
- function cPrint(height, value)
- local xpos = w/2 - string.len(value)/2
- term.setCursorPos(xpos, height)
- term.write(value)
- end
- --Main Code/Function
- function printMain()
- os.startTimer(1)
- local nTime = os.time()
- print(" |Apache |")
- print(" +-----------------------------------------------+")
- term.setCursorPos(36,1)
- write("Time: "..textutils.formatTime(nTime, false))
- term.setCursorPos(1,3)
- print(" ")
- cPrint(4, "+----------------+")
- if nSelect == 1 then cPrint(5, "| [*] Upload |")
- else cPrint(5, "| [ ] Upload |") end
- cPrint(6, "| |")
- if nSelect == 2 then cPrint(7, "| [*] Delete |")
- else cPrint(7, "| [ ] Delete |") end
- cPrint(8, "| |")
- if nSelect == 3 then cPrint(9, "| [*] Exit |")
- else cPrint(9, "| [ ] Exit |") end
- cPrint(10,"+----------------+")
- end
- function printMain2()
- clear()
- file = fileSelect()
- end
- while true do
- clear()
- printMain()
- event, key = os.pullEvent()
- if event == "key" then
- if key == keys.up and nSelect > 1 then nSelect = nSelect-1
- elseif key == keys.down and nSelect < 3 then nSelect = nSelect+1
- elseif key == keys.enter and nSelect == 3 then clear(); break
- elseif key == keys.enter and nSelect == 1 then printMain2() sleep(0.5) nSelect = 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement