Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Chaos Console File Manager
- --By Metallist | Under GNU GPLv3
- --Version 1.0
- --Author's Skype : metalgamestudio
- --For ComputerCraft
- local dir = "/home"
- local pos = 1
- local w,h = term.getSize()
- local filename = ""
- local screen = 0
- local ex = false
- local col = {
- ["bg"] = colours.red,
- ["bar"] = colours.gray,
- ["btn"] = colours.black,
- ["txt"] = colours.black,
- ["bt"] = colours.white
- }
- local ucc = {
- ["bg"] = colours.white,
- ["bar"] = colours.white,
- ["btn"] = colours.black,
- ["txt"] = colours.black,
- ["bt"] = colours.white
- }
- if not term.isColor() then col = ucc end
- local tfiles = {}
- function redraw()
- tfiles = fs.list(dir)
- term.setBackgroundColor(col["bg"])
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(col["bar"])
- write(dir.." ")
- term.setCursorPos(w-5,1)
- term.setBackgroundCol(col["btn"])
- term.setTextColor(col["bt"])
- write("X")
- term.setTextColor(col["txt"])
- if screen == 0 then
- term.setCursorPos(w-1,1)
- term.setBackgroundColor(col["btn"])
- term.setTextColor(col["bt"])
- term.write("^")
- term.setTextColor(col["txt"])
- term.setBackgroundColor(col["bg"])
- for i = pos, h - 2 do
- if tfiles[i] == nil then break end
- term.setCursorPos(1,i+1)
- write(tfiles[i])
- local type = ""
- if fs.isDir(tfiles[i]) then
- type = "folder"
- else
- local sp = split(tfiles[i], ".")
- if #sp == 1 then
- type = "executable"
- else
- type = sp[#sp] .. " file"
- end
- end
- term.setCursorPos(20,i+1)
- write(type)
- end
- term.setCursorPos(w - 1, h)
- term.setbackgroundColor(col["btn"])
- write(" ")
- elseif screen == 1 then
- term.setCursorPos(1,2)
- term.setTextColor(col["txt"])
- term.setBackgroundColor(col["bg"])
- print("Name: " .. filename)
- local fns = astapi.split(filename, ".")
- local type
- if #fns == 1 then
- type = "executable"
- else
- type = fns[#fns]
- end
- print("Type: "..type)
- term.setCursorPos(1,4)
- term.setBackgroundColor(col["btn"])
- write("Open")
- term.setBackgroundColor(col["bg"])
- write(" ")
- term.setBackgroundColor(col["btn"])
- write("Exit")
- term.setBackgroundColor(col["bg"])
- write(" ")
- if type == "executable" or type == "sh" then
- term.setBackgroundColor(col["btn"])
- write("Run")
- ex = true
- else
- ex = false
- end
- end
- end
- local works = true
- function increase()
- if pos < #tfiles - h + 3 then pos = pos + 1 end
- end
- function decrease()
- if pos > 1 then pos = pos -1 end
- end
- function OnMouseClick(cx,cy)
- if cx == w -5 and cy == 1 then works = false end --Exit
- if screen == 0 then
- if cx < w -2 then
- if cy == 2 then
- local d = astapi.split(dir,"/")
- local dd = ""
- for a = 1, #d -1 do
- dd = dd.."/"..d[a]
- end
- dir = dd.. "/"
- elseif cy > 2 then
- if fs.isDir(dir..tfiles[cy - 2 + pos]) then
- dir = dir .. tfiles[cy -2 +pos] .. "/"
- else
- filename = tfiles[cy - 2 + pos]
- screen = 1
- end
- end
- else
- if cy == 1 then
- increase()
- elseif cy == h -1 then
- decrease()
- end
- end
- elseif screen == 1 then
- if cy == 4 then
- if cx >= 1 and cx <= 4 then
- shell.run("edit "..filename)
- elseif cx > 5 and cx <= 9 then
- screen = 0
- elseif ex == true and cx > 10 and cx <= 13 then
- shell.run(filename)
- end
- end
- end
- end
- function mouseEvent()
- local e,b,x,y = os.pullEvent("mouse_click")
- if b == 0 then OnMouseClick(x,y) end
- end
- function msEvent()
- local e,d,sx,sy = os.pullEvent("mouse_scroll")
- if d == 1 then
- increase()
- elseif d == -1 then
- decrease()
- end
- end
- while works == true do
- parallel.waitForAll(redraw,mouseEvent,msEvent)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement