Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local selFile = ""
- local fPath = "/cozy/programs/"
- local fDefault = fPath
- local fPrePath = fPath
- local bgcolor = colors.cyan
- local tbcolor = colors.gray
- local tccolor = colors.white
- local printoff = 0
- local mfoff = 0
- local fs_ver = "v1.0 Alpha"
- inRun = true
- inContext=false
- local contextMenu = {
- ["____________"] = {yoff = 1, bcol=colors.black,tcol=colors.white,fcmd = function() end};
- ["Run File "] = {yoff = 2, bcol=colors.black,tcol=colors.white,fcmd = function() os.run({},selFile) inContext = false; inRun = true; fileSystem() ;end};
- ["Edit File "] = {yoff = 3, bcol=colors.black,tcol=colors.white,fcmd = function() shell.run("edit",selFile); inContext = false; inRun = true; fileSystem() end};
- ["New File "] = {yoff = 4, bcol=colors.black,tcol=colors.white,fcmd = function()
- f=fs.open(fPath.."/.temp","w")
- f.writeLine(" ")
- f.close()
- selFile = fPath.."/.temp"
- loadFS(fPath)
- ea.scp(4,contextY);
- ea.stc(colors.black)
- ea.sbc(colors.white);
- print(" ")
- ea.scp(5,contextY)
- nFn = read()
- if(not fs.exists(fPath.."/"..nFn) and nFn ~= "")then
- fs.move(selFile,fPath..nFn);
- inRun = true;
- inContext = false;
- fileSystem()
- else
- inRun = true;
- inContext = false;
- fileSystem()
- fs.delete(fPath..".temp")
- loadFS(fPath)
- end
- end};
- ["Rename File "] = {yoff = 5, bcol=colors.black,tcol=colors.white,fcmd = function() ea.scp(4,contextY); ea.stc(colors.black) ea.sbc(colors.white); print(" ") ea.scp(5,contextY) nFn = read() if(not fs.exists(fPath..nFn) and nFn ~= "")then fs.move(selFile,fPath..nFn); end inRun = true; inContext = false; fileSystem() end};
- ["Delete File "] = {yoff = 6, bcol=colors.black,tcol=colors.white,fcmd = function() if(fs.exists(selFile))then fs.delete(selFile); inContext = false; inRun = true; fileSystem(); end end};
- ["------------"] = {yoff = 7, bcol=colors.black,tcol=colors.white,fcmd = function() end};
- }
- local w,h = term.getSize()
- os.loadAPI("ea")
- os.loadAPI("cozy_string")
- function clear() ea.sbc(bgcolor); term.clear() end
- clear()
- --]] FILE SYSTEM [[--
- local filetable = {}
- function loadFS(fsl)
- mfoff = 0
- if(filetable ~= {})then filetable = {}
- for k, v in pairs(fs.list(fsl)) do
- if(fs.isDir(fsl..v))then isdir=true; else isdir = false; end
- if(not filetable[v])then
- filetable[v] = v
- filetable[v] = {offset = k, dir = isdir};
- mfoff = mfoff + 1
- end
- end
- end
- end
- function drawMenu(x,y)
- for k, v in pairs(contextMenu)do
- ea.sbc(v.bcol)
- ea.stc(v.tcol)
- ea.scp(x+2,y+v.yoff)
- print(k)
- end
- end
- function fileSystem()
- while inRun do
- clear()
- ea.scp(1,2)
- moff = 14
- loadFS(fPath)
- ea.sbc(colors.white)
- term.clear()
- ea.sbc(tbcolor)
- ea.scp(1,1)
- term.clearLine()
- ea.stc(colors.yellow)
- ea.scp(1,1)
- print("Cozy File Manager")
- ea.scp(w-#fs_ver,1)
- print(os_ver)
- ea.stc(colors.lightGray)
- ea.sbc(colors.white)
- print(fPath)
- print("[BACK] [EXIT]")
- for k, v in pairs(filetable) do
- if(v.offset-printoff < moff and v.offset >= printoff)then
- if( ((v.offset)-printoff)+3 < 4)then addl = 4 else addl = ( (v.offset) - printoff )+3 end
- if(v.dir)then ea.stc(colors.green); ea.sbc(colors.gray); ea.scp(1,addl); write("[=]"); ea.stc(colors.black); ea.sbc(colors.white); print(" "..k) end
- if(not v.dir)then ea.stc(colors.orange); ea.sbc(colors.gray); ea.scp(1,addl); write("-~-"); ea.sbc(colors.white); ea.stc(colors.black); if(fPath..k == selFile)then ea.sbc(colors.lightBlue) else ea.sbc(colors.white) end; print(" "..k) end
- end
- if(mfoff-printoff > moff)then
- ea.stc(colors.lightGray)
- ea.scp(10,3)
- print("+")
- end
- if(printoff+1 > 1)then
- ea.stc(colors.lightGray)
- ea.scp(11,3)
- print("-")
- end
- end
- mi = {os.pullEvent()}
- if(mi[1] == "mouse_click" and mi[2] == 1)then
- fBi = 1
- for k, v in pairs(filetable) do
- if(mi[3] >= 1 and mi[3] <= 4+#k and mi[4] == (v.offset-printoff)+3)then
- if(v.dir)then fPrePath = fPath; fPath = fPath..k.."/"; selFile = ""; loadFS(fPath); printoff = 0 end
- if(selFile == fPath..k)then ea.stc(colors.white); ea.sbc(colors.black); ea.scp(1,1); os.run({},fPath..k); else selFile = ""; selFile = fPath..k; end
- end
- end
- if( mi[3] >= 1 and mi[3] <= 6 and mi[4] == 3)then
- fPrePath = cozy_string.split(fPrePath,"/",(cozy_string.pathLen(fPath)-fBi))
- fPath = fPrePath;
- printoff = 0
- selFile = ""
- loadFS(fPath)
- fBi = 0
- end
- if( mi[3] >= w-6 and mi[3] <= w and mi[4] == 3)then inRun=false; isRun=true; ea.sbc(colors.black) ea.stc(colors.white) ea.scp(1,1) end
- else
- fBi = 1
- if(mi[1] == "key" or mi[1] == "mouse_scroll")then
- ea.scp(1,1)
- pfc = mfoff
- if(mi[2] == keys.up or mi[2] == -1)then if(printoff > 0)then printoff = printoff - 1 end end
- if(mi[2] == keys.down or mi[2] == 1)then if(printoff < mfoff-moff)then printoff = printoff + 1 end end
- end
- end
- if(mi[1] == "mouse_click" and mi[2] == 2)then
- for k, v in pairs(filetable) do
- if(mi[3] >= 1 and mi[3] <= #k+5 and mi[4] == (v.offset-printoff)+3 and not v.dir)then
- if(selFile == fPath..k)then
- if(mi[4] >= h-9)then
- prntedY = ((v.offset-printoff)+3)-8
- else
- prntedY = (v.offset-printoff)+3
- end
- drawMenu(1,prntedY)
- contextY = prntedY
- inContext = true
- inRun = false
- fileSystem()
- else
- selFile = fPath..k
- end
- end
- end
- end
- end
- while inContext and not inRun do
- m = {os.pullEvent()}
- if(m[1] == "mouse_click")then
- if(m[2] == 2)then inContext = false; inRun = true; fileSystem() end
- for k, v in pairs(contextMenu) do
- if(m[2] == 1 and m[3] >=3 and m[4] == v.yoff+contextY)then
- v.fcmd()
- end
- end
- end
- end
- end
- fileSystem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement