Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lat_theme = nil
- --image files:
- local img_folder = {{16,16,},
- {16,16,16,16,16,},
- {16,16,16,16,16,},
- {16,16,16,16,16,}}
- local img_file = {{8,8,8,8,8,},
- {8,1,1,1,8,},
- {8,1,1,1,8,},
- {8,8,8,8,8,},}
- --code:
- local tArgs = { ... }
- local home
- local root
- local clipboard
- if type(lat_theme) ~= "table" then
- lat_theme = {fore=colors.cyan;
- back=colors.white;
- text=colors.black;
- selected=colors.cyan;
- dir=colors.lime;
- multiselect=colors.lightGray;
- }
- end
- if #tArgs > 0 then
- home = tArgs[1]
- else
- home = ""
- end
- if #tArgs > 1 then
- root = tArgs[2]
- else
- root = "/"
- end
- local history = {}
- local w,h = term.getSize()
- local iconw = 8
- local iconh = 7
- local nIco = math.floor((w-1)/iconw)
- --mode 1 is the list view, mode 2 is the detail view, mode 3 is the icon view
- local mode = 2
- local function mathdown(num)
- if num % 1 ~= 0 then
- return math.floor(num)
- end
- return num - 1
- end
- local function formatNumber(num)
- local extra = {"B","KB","MB"}
- local eindex = 1
- while num > 1000 do
- num = num / 1000
- num = math.floor(num)
- eindex = eindex + 1
- end
- return tostring(num..extra[eindex])
- end
- local function drawLine(y,txt,col,align)
- term.setTextColor(colors.white)
- if type(align) ~= "number" then align = 2 end
- if type(col) ~= "number" then col = colors.white end
- term.setBackgroundColor(col)
- term.setCursorPos(1,y)
- term.clearLine()
- local xpos
- xpos = align == 1 and 1 or (align == 2 and math.floor(w/2-#txt/2) or w-#txt)
- term.setCursorPos(xpos,y)
- term.write(txt)
- end
- local function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- local function diabox(txt)
- term.setBackgroundColor(lat_theme.fore)
- term.setTextColor(lat_theme.text)
- paintutils.drawFilledBox(math.floor(w/2-(#txt+2)/2),math.floor(h/2)-2,math.floor(w/2+(#txt+2)/2),math.floor(h/2)+2,lat_theme.fore)
- term.setCursorPos(math.floor(w/2-(#txt+2)/2)+1,math.floor(h/2)-1)
- term.write(txt)
- term.setCursorPos(math.floor(w/2-(#txt+2)/2)+1,math.floor(h/2)+1)
- end
- function readtextbox(txt)
- diabox(txt)
- return read()
- end
- function buttonbox(txt,buttons)
- if type(buttons) ~= "table" then
- buttons = {{" Yes ",colors.red,colors.white},{" No ",colors.gray,colors.white}}
- end
- if txt == "" or txt == nil then
- txt = " Are you sure? "
- end
- local x,y
- diabox(txt)
- for i=1,#buttons do
- x,y = term.getCursorPos()
- x = math.floor((w/2-(#txt+2)/2)+((#txt+2)/i)*(i-1)) + 1
- term.setCursorPos(x,y)
- term.setBackgroundColor(buttons[i][2])
- term.setTextColor(buttons[i][3])
- term.write(buttons[i][1])
- end
- while true do
- local _,b,x2,y2 = os.pullEvent("mouse_click")
- if b == 1 and y == y2 then
- for i=1,#buttons do
- local x = math.floor((w/2-(#txt+2)/2)+((#txt+2)/i)*(i-1)) + 1
- if x2 > x - 1 and x2 < x + #buttons[i][1] then
- return i
- end
- end
- end
- end
- end
- local function clear()
- term.setBackgroundColor(lat_theme.back)
- term.setTextColor(colors.black)
- for i=2,h-1 do
- term.setCursorPos(1,i)
- term.clearLine()
- end
- term.setCursorPos(1,1)
- end
- local function posToIndex(maxn,x,y,scroll)
- if mode < 3 then
- return y+scroll-2 < maxn and y+scroll-1 or 0
- else
- local row = mathdown((y+scroll)/iconh)
- local column = math.floor(1+x/iconw)
- local index = row*nIco+column
- if column <= nIco and index <= maxn then
- return index
- else
- return 0
- end
- end
- end
- local function IndexToPos(index,scroll,rev)
- if mode < 3 then
- return 2,index-scroll
- else
- local row = mathdown(index/nIco)
- local col = (index-1) % nIco
- local x = 2+(col)*iconw
- local y = 2+(row)*iconh - scroll
- if rev then
- return y,x
- else
- return x,y
- end
- end
- end
- local function sort(path,items)
- local tbl = {} --i'll soon make a better sorting but this is enough for now
- table.sort(items)
- --insert dirs
- for i=1,#items do
- if fs.isDir(path..items[i]) then
- tbl[#tbl+1] = items[i]
- end
- end
- for i=1,#items do
- if not fs.isDir(path..items[i]) then
- tbl[#tbl+1] = items[i]
- end
- end
- return tbl
- end
- local function list(path,scroll,selected,selection)
- if selection == nil then selection = {} end
- clear()
- term.setCursorPos(1,2)
- local items = sort(path,fs.list(path))
- local cy = 1
- local i
- if mode < 3 then
- i = scroll+1
- elseif mode == 3 then
- i = scroll-nIco
- i = i <= 0 and 1 or i
- end
- while IndexToPos(i,scroll,true) < h do
- if type(items[i]) ~= "string" then break end
- if mode < 3 then
- cy = cy + 1
- term.setCursorPos(2,cy)
- else
- local x,y = IndexToPos(i,scroll)
- term.setCursorPos(x,y)
- paintutils.drawImage(fs.isDir(path..items[i]) and img_folder or img_file,x,y)
- term.setBackgroundColor(lat_theme.back)
- term.setCursorPos(x,y+4)
- end
- if i ~= selected then
- if not fs.isDir(path..items[i]) then
- term.setTextColor(lat_theme.text)
- else
- term.setTextColor(lat_theme.dir)
- end
- else
- term.setTextColor(lat_theme.selected)
- end
- if selection[i] then
- term.setBackgroundColor(lat_theme.multiselect)
- else
- term.setBackgroundColor(lat_theme.back)
- end
- if mode < 3 then
- term.write(items[i])
- else
- local str = items[i]
- if #str > iconw-1 then
- str = str:sub(1,iconw-1)
- end
- term.write(str)
- end
- if mode == 2 then
- term.setCursorPos(math.floor(w/2),cy)
- if fs.isDir(path..items[i]) then
- term.write("-")
- else
- term.write(formatNumber(fs.getSize(path..items[i])))
- end
- end
- i = i + 1
- end
- return items
- end
- local function drawMenu(path)
- drawLine(1,"< ^ > / +",lat_theme.fore,1)
- local str = "Lattice - " .. path
- str = #str < w/2 and str or str:sub(1,math.floor(w/2)) .. "..."
- term.setCursorPos(10+math.floor((w-12)/2-#str/2),1)
- term.write(str)
- term.setCursorPos(w,1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.write("x")
- drawLine(h,path,lat_theme.fore,1)
- end
- local function popupMenu(x,y,isSelected,isDir,isMultiSelect)
- local ydir = y < h/2 and 1 or -1
- local content
- if isMultiSelect then
- content = {"Rename","Move","Copy","Delete"}
- elseif isSelected and isDir then
- content = {"Open","Unpack","Rename","Move","Copy","C.t.Clipboard","Delete"}
- elseif isSelected then
- content = {"Run","Run w/ Args","Edit","Open with...","Rename","Move","Copy","C.t.Clipboard","Delete"}
- else
- content = {"New file","New dir","New ...","Find file","P.f.Clipboard","P.f.Pastebin","Download file","Toggle view"}
- end
- for k,v in pairs(content) do
- term.setBackgroundColor(lat_theme.fore)
- term.setTextColor(colors.white)
- term.setCursorPos(x,y+k*ydir)
- for i=1,15 do term.write(" ") end
- term.setCursorPos(x+1,y+k*ydir)
- term.write(v)
- end
- term.setCursorPos(x,y)
- for i=1,15 do term.write(" ") end
- term.setCursorPos(x,y+(#content+1)*ydir)
- for i=1,15 do term.write(" ") end
- return true
- end
- local function popupEvent(popup,isSelected,isDir,isMultiSelect,...)
- local event = {...}
- local ydir = popup[2] < h/2 and 1 or -1
- if event[1] == "mouse_click" and event[2] == 1 then
- local content
- if isMultiSelect then
- content = {"r","m","c","delete"}
- elseif isSelected and isDir then
- content = {"enter","u","r","m","c","l","delete"}
- elseif isSelected then
- content = {"enter","q","e","w","r","m","c","l","delete"}
- else
- content = {"insert","n","new","find","pfcb","pfpb","df","o"}
- end
- --check if the popup has been clicked
- if event[3] >= popup[1] and event[3] <= popup[1] + 15 and event[4]*ydir >= popup[2]*ydir and event[4]*ydir <= popup[2]*ydir + #content then
- return true,content[ydir*event[4]-ydir*popup[2]]
- end
- return false
- end
- end
- local function createNewName(name,typ,path)
- if typ == nil then typ = 1 end
- if typ == 1 then return "Unpacked_" .. name end
- if typ == 2 then
- local num = ""
- local rawname = name
- while fs.exists(table.concat({path,name})) do
- num = tonumber(name:sub(#name,#name))
- if type(num) == "number" then
- num = num + 1
- name = rawname .. "_" .. tostring(num)
- else
- num = 2
- end
- end
- return table.concat({rawname,"_",tostring(num)})
- end
- return name .. "_pasted"
- end
- local function findFile(path)
- local name = readtextbox("Please enter a wildcard "..path)
- local results = fs.find(fs.combine(path,name))
- return results
- end
- local function downloadfile(path)
- clear()
- local url = readtextbox(" Please enter url ")
- clear()
- print("Progress:")
- print("Checking url")
- if url:sub(1,4) ~= "http" then
- url = "http://"..url
- print("Added http:// to your url")
- else
- print("Entered url is fine")
- end
- print("Requesting "..url)
- http.request(url)
- print("Press enter to cancel")
- local event,key
- while event ~= "http_success" and event ~= "http_failure" and not (event == "key" and key == keys.enter) do
- event,key = os.pullEvent()
- end
- if event == "http_success" then
- print("Downloading "..url)
- local httpgot = http.get(url)
- print("Done")
- local name = readtextbox("Please name the file")
- if name == nil or name == "" then return end
- while fs.exists(path..name) do name = createNewName(name,3) end
- local file = fs.open(path..name,"w")
- file.write(httpgot.readAll())
- file.close()
- httpgot.close()
- clear()
- buttonbox("File downloaded",{{"OK",colors.gray,colors.white}})
- elseif event == "http_failure" then
- buttonbox("http failure",{{"OK",colors.gray,colors.white}})
- end
- end
- local function toggleView()
- mode = mode + 1
- mode = mode > 3 and 1 or mode
- mode = mode < 1 and 3 or mode
- mode = math.floor(mode)
- end
- ------------------------------------------------------
- --actions:
- --folder:
- local function openFolder(path,history,items,selected)
- if fs.isDir(path) then
- path = path .. items[selected] .. "/"
- history[#history+1] = path
- end
- return path,history
- end
- local function unpackFolder(path,items,selected)
- if fs.isDir(path..items[selected]) then
- local con = fs.list(path..items[selected].."/")
- for i=1,#con do
- local altname = con[i]
- while fs.exists(path..altname) do altname = createNewName(altname,2,path) end
- fs.move(path..items[selected].."/"..con[i],path..altname)
- end
- fs.delete(path..items[selected])
- end
- end
- --file:
- local function runFile(path)
- if fs.exists(path) and not fs.isDir(path) then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- os.pullEvent()
- shell.run(path)
- print("Press any key to continue")
- os.pullEvent()
- end
- end
- local function runFileWArgs(path)
- if fs.exists(path) and not fs.isDir(path) then
- local args = readtextbox("Please enter all arguments to run with!")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- os.pullEvent()
- shell.run(path .. " " .. args)
- print("Press any key to continue")
- os.pullEvent()
- end
- end
- local function renamefile(path,items,selected)
- if fs.exists(path) then
- local nname = readtextbox("Please enter the new name (empty = cancel)")
- if nname ~= nil or nname ~= "" then
- if not fs.exists(path..nname) then
- fs.move(path..items[selected],path..nname)
- selected = 0
- else
- clear()
- buttonbox("File already exists",{{"OK",colors.gray,colors.white}})
- end
- end
- end
- end
- local function moveFile(path,items,selected)
- if fs.exists(path..items[selected]) then
- local dest = readtextbox("Move to (empty=cancel) "..root)
- if dest ~= nil or dest ~= "" then
- if #dest < #items[selected] or dest:sub(#dest-#items[selected],#dest) ~= items[selected] then
- if dest:sub(#dest,#dest) == "/" then dest = dest .. items[selected] else
- dest = dest .. "/" .. items[selected]
- end
- end
- if not fs.exists(root..dest) then
- fs.move(path..items[selected],root..dest)
- else
- clear()
- buttonbox("File already exists",{{"OK",colors.gray,colors.white}})
- end
- end
- end
- end
- local function copyFile(path,items,selected)
- if fs.exists(path..items[selected]) then
- local dest = readtextbox("Copy to (empty=cancel) "..root)
- if dest ~= nil or dest ~= "" then
- if #dest < #items[selected] or dest:sub(#dest-#items[selected],#dest) ~= items[selected] then
- if dest:sub(#dest,#dest) == "/" then dest = dest .. items[selected] else
- dest = dest .. "/" .. items[selected]
- end
- end
- if not fs.exists(root..dest) then
- fs.copy(path..items[selected],root..dest)
- else
- clear()
- buttonbox("File already exists",{{"OK",colors.gray,colors.white}})
- end
- end
- end
- end
- local function deleteFile(path)
- if fs.exists(path) then
- local bclicked = buttonbox()
- if bclicked == 1 then
- fs.delete(path)
- end
- end
- end
- local function newFile(path)
- local name = readtextbox("Filename: (empty=cancel) ")
- if name ~= nil or name ~= "" and not fs.exists(path..name) then
- shell.run("edit",path..name)
- end
- end
- local function newDir(path)
- local name = readtextbox("Directory's name: (empty=cancel)")
- if name ~= nil or name ~= "" and not fs.exists(path..name) then
- fs.makeDir(path..name)
- end
- end
- local function checkPath(path)
- if path:sub(#path,#path) ~= "/" then path = path .. "/" end
- if path:sub(1,1) ~= "/" then path = "/" .. path end
- if not fs.isDir(path) then
- if fs.isDir(root..home) then
- path = root..home
- elseif fs.isDir(root) then
- path = root
- else
- error("Not valid root folder",0)
- end
- end
- return path
- end
- local function shiftselect(ysc,selected,selection)
- local direction = ysc-selected
- if direction > 0 then
- direction = 1
- else
- direction = - 1
- end
- for i=selected,ysc,direction do
- selection[i] = true
- end
- return selection
- end
- local function moveFiles(path,items,selection)
- local foldername = readtextbox("Enter destination folder name "..root)
- if foldername == nil then return end
- if not fs.exists(root..foldername) then
- fs.makeDir(root..foldername)
- elseif not fs.isDir(root..foldername) then
- foldername = createNewName(foldername,2,path)
- end
- local dest = root..foldername
- dest = checkPath(dest)
- local goalk
- for k,v in pairs(selection) do
- if v then
- if fs.exists(dest..v) then
- goalk = createNewName(k,2,path)
- end
- fs.move(path..items[k],dest..items[goalk])
- end
- end
- end
- local function copyFiles(path,items,selection)
- local foldername = readtextbox("Enter destination folder name "..root)
- if foldername == nil then return end
- if not fs.exists(root..foldername) then
- fs.makeDir(root..foldername)
- elseif not fs.isDir(root..foldername) then
- foldername = createNewName(foldername,2,path)
- end
- local dest = root..foldername
- dest = checkPath(dest)
- local goalk
- for k,v in pairs(selection) do
- if v then
- if fs.exists(dest..v) then
- goalk = createNewName(k,2,path)
- end
- fs.copy(path..items[k],dest..items[goalk])
- end
- end
- end
- local function deleteFiles(path,items,selection)
- local bclicked = buttonbox()
- if bclicked == 1 then
- for k,v in pairs(selection) do
- if v then
- fs.delete(path..items[k])
- end
- end
- clear()
- buttonbox("Files deleted",{{"OK",colors.gray,colors.white}})
- end
- end
- local function renameFiles(path,items,selection)
- local strtoreplace = readtextbox("Enter pattern to replace")
- local newstr = readtextbox("Enter string to replace with")
- for k,v in pairs(selection) do
- if v then
- local nname = items[k]:gsub(strtoreplace,newstr)
- if fs.exists(path..nname) then
- createNewName(nname,2,path)
- fs.move(path..items[k],path..nname)
- end
- end
- end
- end
- local path = checkPath(root) .. home
- history[1] = path
- local scroll = 0
- local selected = 0
- local items
- local endprogram = false
- local isCtrlDown = false
- local isShiftDown = false
- local selection = {}
- local isMultiSelect = false
- local redraw = 1 -- 0 - no redraw, 1 - redraw all, 2 - redraw only files
- local popup = {x,y,isOpen}
- local index = 0
- ------------------------------------------------------
- local function fillTable(count,tbl,value)
- if not tbl then tbl = {} end
- if not value then value = false end
- if not count then error("Not valid count",2) end
- for i=1,count do
- tbl[i] = value
- end
- return tbl
- end
- local function goUp()
- end
- ------------------------------------------------------
- while not endprogram do
- repeat
- path = checkPath(path)
- if redraw == 1 or redraw == 2 then
- items = list(path,scroll,selected,selection)
- drawMenu(path)
- if popup[3] then
- popupMenu(popup[1],popup[2],selected ~= 0,fs.isDir(path..tostring(items[selected])),isMultiSelect)
- end
- redraw = 0
- end
- local e,b,x,y = os.pullEvent()
- if popup[3] then
- local response,key = popupEvent(popup,selected ~= 0,fs.isDir(path..tostring(items[selected])),isMultiSelect,e,b,x,y)
- if response then
- if keys[key] then
- os.queueEvent("key",keys[key])
- else
- os.queueEvent("action",key)
- end
- redraw = 1
- popup[3] = false
- break
- elseif response == false then
- redraw = 1
- popup[3] = false
- end
- end
- if e == "mouse_click" then
- index = posToIndex(#items,x,y,scroll)
- if b == 1 then
- if y == h then
- local npath = readtextbox("Enter new path: (empty=cancel) "..root)
- if npath ~= nil and npath ~= "" and fs.isDir(root..npath) then
- path = root .. npath
- selected = 0
- scroll = 0
- history[#history+1] = path
- end
- redraw = 1
- elseif y == 1 then
- if x == 9 then
- selected = 0
- isMultiSelect = false
- selection = fillTable(#items)
- popup = {9,2,true}
- redraw = 1
- end
- if x == 7 then
- path = root
- history[#history+1] = path
- selected = 0
- scroll = 0
- redraw = 1
- end
- if x == 3 then
- local t = split(path,"/")
- if #t > 0 then
- t[#t] = nil
- path = table.concat(t,"/")
- path = checkPath(path)
- selected = 0
- scroll = 0
- history[#history+1] = path
- end
- if path:sub(1,#root) ~= root then
- path = root
- end
- redraw = 1
- selected = 0
- isMultiSelect = false
- selection = fillTable(#items)
- end
- if x == 1 then
- while true do
- history[#history] = nil
- if #history == 0 then
- if fs.exists(root..home) then
- path = root..home
- history[1] = path
- elseif fs.exists(root) then
- path = root
- history[1] = path
- else
- error("Root folder deleted",0)
- end
- end
- if fs.exists(history[#history]) then
- path = history[#history]
- break
- end
- end
- selected = 0
- isMultiSelect = false
- selection = fillTable(#items)
- redraw = 1
- end
- if x == w then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- term.clear()
- endprogram = true
- redraw = 1
- end
- else
- if index == selected and not isCtrlDown and not isShiftDown then
- if items[selected] ~= nil then
- if fs.isDir(path..items[selected]) then
- isMultiSelect = false
- selection = fillTable(#fs.list(path..items[selected]))
- path,history = openFolder(path,history,items,selected)
- selected = 0
- scroll = 0
- redraw = 1
- else
- runFile(path..items[selected])
- redraw = 1
- end
- end
- else
- if not isCtrlDown and not isShiftDown then
- selected = index
- if isMultiSelect then
- isMultiSelect = false
- selection = fillTable(#items)
- end
- redraw = 1
- elseif isShiftDown then
- shiftselect(index,selected,selection)
- redraw = 1
- isMultiSelect = true
- elseif isCtrlDown then
- if not isMultiSelect then
- isMultiSelect = true
- if selected ~= 0 then
- selection[selected] = true
- end
- end
- selection[index] = not selection[index]
- local hasTrue = false
- for k,v in pairs(selection) do
- hasTrue = hasTrue and true or v
- end
- if not hasTrue then
- isMultiSelect = false
- isCtrlDown = false
- end
- redraw = 1
- end
- end
- end
- elseif b == 2 and y > 1 and y < h then
- if index ~= selected then
- selected = index
- end
- popup[1], popup[2],popup[3] = x,y,true
- redraw = 1
- end
- elseif e == "mouse_up" and not isCtrlDown and not isShiftDown then
- if selected == 0 then break end
- local index
- if mode > 2 then
- index = posToIndex(#items,x,y,scroll)
- else
- index = y+scroll-1
- end
- if y > 1 and y < h and index ~= selected and index < #items then
- if fs.isDir(path..items[index]) and not fs.exists(path..items[index].."/"..items[selected]) then
- if buttonbox("Move "..items[selected].." to "..items[index].."?",{{" Yes ",colors.green,colors.white},{" Cancel ",colors.gray,colors.white}}) == 1 then
- fs.move(path..items[selected],path..items[index].."/"..items[selected])
- end
- redraw = 1
- selected = 0
- isMultiSelect = false
- selection = fillTable(#items)
- end
- end
- if y == 1 then
- local t = split(path,"/")
- local roottable = split(root,"/")
- if #t > #roottable then
- t[#t] = nil
- local upperpath = table.concat(t,"/")
- upperpath = checkPath(upperpath)
- if not fs.exists(upperpath..items[selected]) then
- if buttonbox("Move "..items[selected].." to parent dir?",{{" Yes ",colors.green,colors.white},{" Cancel ",colors.gray,colors.white}}) == 1 then
- fs.move(path..items[selected],upperpath..items[selected])
- redraw = 1
- selected = 0
- isMultiSelect = false
- selection = fillTable(#items)
- end
- end
- end
- end
- elseif e == "mouse_scroll" then
- if b == 1 then
- if mode < 3 and #items - scroll > h-2 then
- scroll = scroll + 1
- elseif mode == 3 and scroll < math.ceil(#items/nIco)*iconh-(h-2) then
- scroll = scroll + 1
- end
- end
- if b == -1 and scroll > 0 then
- scroll = scroll - 1
- end
- redraw = 2
- ---------------------------------------------------
- --hotkeys:
- elseif e == "key" then
- if b == keys.f1 then
- clear()
- print("Hotkey help:")
- print([[Up/Down arrow keys + Page Up/Down = navigation
- G = Go to root folder H = Go to home folder
- Insert = new file N = New directory
- Backspace = exit 0 (number) = deselect
- Enter = Open/Run E = Edit P = Paint
- U = Unpack folder L = Copy to clipboard
- Q = Run w/ Args W = Open with...
- M = move C = copy R = rename
- Delete = delete file
- hold Ctrl/Shift + clicking = multiselect
- O (letter) = toggle view
- Right click to open popup menus
- Click '<' and '>' to go back/forward in history
- Click '^' to go up (..)
- Click '/' to go in root folder
- Press any key to go back]])
- os.pullEvent("key")
- redraw = 1
- end
- if b == keys.insert then
- newFile(path)
- redraw = 1
- elseif b == keys.delete then
- if selected ~= 0 then
- deleteFile(path..items[selected])
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.backspace then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- term.clear()
- return
- end
- if b == keys.enter then
- if selected ~= 0 then
- if fs.isDir(path..items[selected]) then
- path,history = openFolder(path,history,items,selected)
- selected = 0
- scroll = 0
- else
- runFile(path..items[selected])
- end
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.m then
- if selected ~= 0 then
- moveFile(path,items,selected)
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.c then
- if selected ~= 0 then
- copyFile(path,items,selected)
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.r then
- if selected ~= 0 then
- renamefile(path,items,selected)
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.zero then
- selected = 0
- selection = fillTable(#items)
- isMultiSelect = false
- isCtrlDown = false
- isShiftDown = false
- redraw = 1
- end
- if b == keys.up and selected > 1 then
- selected = selected - 1
- if mode < 3 and selected < scroll+1 then
- scroll = scroll - 1
- end
- redraw = 1
- end
- if b == keys.down and selected < #items then
- selected = selected + 1
- if selected > (scroll + h-3) then
- scroll = scroll + 1
- end
- redraw = 1
- end
- if b == keys.pageUp and selected then
- selected = selected - (h-3)
- scroll = selected-1
- if selected < 0 or scroll < 0 then scroll,selected = 0,1 end
- redraw = 1
- end
- if b == keys.pageDown and selected < #items-(h-2) then
- selected = selected + (h-3)
- scroll = selected-1
- if scroll > #items-(h-2) or selected > #items then scroll,selected = #items-(h-2),#items end
- if selected < 0 then scroll,selected = 0,0 end
- redraw = 1
- end
- if b == keys.g then
- path = root
- history[#history+1] = path
- selected = 0
- scroll = 0
- redraw = 1
- end
- if b == keys.h then
- if fs.exists(root .. home) then
- path = root .. home
- history[#history+1] = path
- selected = 0
- scroll = 0
- redraw = 1
- end
- end
- if b == keys.w then
- if selected ~= 0 then
- local program = readtextbox("Please choose a program: "..root)
- if program ~= nil or program ~= "" then
- shell.run(root..program,path..items[selected])
- end
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.e then
- if selected ~= 0 then
- shell.run("edit",path..items[selected])
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.u then
- if selected ~= 0 then
- unpackFolder(path,items,selected,history,scroll)
- selected = 0
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.l then
- if selected ~= 0 then
- clipboard = path .. items[selected]
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.p then
- if selected ~= 0 then
- shell.run("paint",path..items[selected])
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.n then
- local dirname = readtextbox("Please enter directory name (empty=cancel)")
- if dirname ~= nil and dirname ~= "" then
- if not fs.exists(path..dirname) then
- fs.makeDir(path..dirname)
- else
- buttonbox("PFile exists",{{"OK",colors.gray,colors.white}})
- end
- end
- redraw = 1
- end
- if b == keys.q then
- if selected ~= 0 then
- runFileWArgs(path..items[selected])
- else
- buttonbox("Please select a file",{{"OK",colors.gray,colors.white}})
- end
- redraw = 1
- end
- if b == keys.o then
- toggleView()
- redraw = 1
- end
- if b == keys.leftCtrl or b == keys.rightCtrl then
- isCtrlDown = true
- end
- if b == keys.leftShift or b == keys.rightShift then
- isShiftDown = true
- end
- elseif e == "key_up" then
- if b == keys.leftCtrl or b == keys.rightCtrl then
- isCtrlDown = false
- end
- if b == keys.leftShift or b == keys.rightShift then
- isShiftDown = false
- end
- elseif e == "action" then
- if b == "new" then
- local exc = buttonbox("Please choose a program",{{"Paint",colors.yellow,colors.black},{"Custom",colors.yellow,colors.black}})
- clear()
- local filename = readtextbox("Please enter a filename")
- if not fs.exists(path..filename) then
- if exc == 1 then
- shell.run("paint",path..filename)
- else
- clear()
- local prog = readtextbox("Please choose a program "..root)
- shell.run(prog,path..filename)
- end
- end
- elseif b == "find" then
- local results = findFile(path)
- buttonbox(#results.." results saved in current path",{{"OK",colors.gray,colors.white}})
- local file = fs.open(path..createNewName("search_results",2,path),"w")
- for k,v in pairs(results) do
- file.writeLine(v)
- end
- file.close()
- elseif b == "pfcb" then
- if type(clipboard) == "string" and fs.exists(clipboard) then
- if clipboard:sub(#clipboard,#clipboard) == "/" then clipboard = clipboard:sub(1,#clipboard-1) end
- local splitted = split(clipboard,"/")
- local name = splitted[#splitted]
- while fs.exists(path..name) do name = createNewName(name,3) end
- fs.copy(clipboard,path..name)
- buttonbox("Pasted as "..name.." in directory "..path,{{"OK",colors.gray,colors.white}})
- else
- buttonbox("File not found: "..tostring(clipboard),{{"OK",colors.gray,colors.white}})
- end
- elseif b == "pfpb" then
- local name
- repeat
- name = readtextbox("Please enter a filename")
- until not fs.exists(path..name)
- local url = readtextbox("Please enter the pastebin URL")
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clear()
- print("Downloading file: ")
- shell.run("pastebin get "..url.." "..path..name)
- print("Ended. Press any key to continue")
- os.pullEvent()
- elseif b == "df" then
- downloadfile(path)
- end
- redraw = 1
- end
- until true
- end
Add Comment
Please, Sign In to add comment