Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- writepos, writecol, multchar, max, min, compare_coord, fill_color, render_folder, render_popup, render_time = table.unpack(require "os_library")
- local function blue_screen(msg)
- local w,h = term.getSize()
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clear()
- writepos(2,2,":( An unexpected error has occurred!")
- writepos(2,3,"We are working on fixing the problem.")
- writepos(2,5,"Error: "..msg)
- writepos(2,7,"\aOpen shell")
- writepos(2,8,"\aRestart OS")
- writepos(2,9,"\aShutdown")
- local e, btn, cx, cy
- repeat
- e, btn, cx, cy = os.pullEvent("mouse_click")
- until cy>=7 and cy<=9
- term.setCursorPos(1,h)
- if cy==7 then
- term.setBackgroundColor(colors.black)
- term.clearLine()
- elseif cy==8 then
- shell.run("reboot")
- elseif cy==9 then
- shell.run("shutdown")
- end
- end
- local function is_lua_script(name)
- local afterdot = string.match(name, "%.(.*)")
- return afterdot == "lua" or afterdot == nil
- end
- local args = {...}
- local folder = args[1]==nil and "" or args[1]
- local shift = 1
- local last_click = {0,0}
- local function main()
- while true do
- render_folder(folder,shift)
- local event = {os.pullEvent()}
- local w,h = term.getSize()
- if event[1] == "timer" then
- render_time()
- elseif event[1] == "mouse_click" then
- if event[2] == 1 then
- if event[3] == w then
- if event[4] == h then
- shift = min(shift + 1,#fs.list(folder)-h+3)
- elseif event[4] == 1 then
- shift = max(shift-1,1)
- elseif event[4] == 3 and term.isColour() then
- shell.run("fg shell")
- elseif event[4] == math.floor(h/2) then
- if folder~="" then folder = fs.combine(folder,"..") end
- shift = 1
- term.clear()
- elseif event[4] == math.floor(h/2)-1 then
- folder = "/UserFiles"
- shift = 1
- term.clear()
- elseif event[4] == 2 then
- shift = 1
- elseif event[4] == h-1 then
- shift = max(#fs.list(folder)-h+3,1)
- elseif event[4] == h-2 then
- local x,y = render_popup(3,"Create",true)
- local is_folder = false
- writepos(x,y,"\aFile")
- writepos(x,y+1,"\aFolder")
- local e, btn, cx, cy
- repeat
- e, btn, cx, cy = os.pullEvent("mouse_click")
- until cy == y or cy == y+1 or cy == y-1
- if cy == y then
- writecol(x,y,"\aFile",colors.cyan,colors.white)
- elseif cy == y+1 then
- writecol(x,y+1,"\aFolder",colors.cyan,colors.white)
- is_folder = true
- end
- if cy ~= y-1 then
- term.setCursorPos(x,y+2)
- write("> ")
- local rd = read()
- if not is_folder and rd~="" then fs.open(fs.combine(folder,rd),"w").close() else fs.makeDir(fs.combine(folder,rd)) end
- end
- term.clear()
- end
- elseif compare_coord({event[3],event[4]},{1,h}) then
- term.setCursorPos(1,h)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- write("> ")
- shell.setDir(folder)
- shell.run(read())
- shell.setDir("/")
- term.setCursorPos(1,h)
- write("Execution finished, press to continue")
- os.pullEvent("mouse_click")
- term.setBackgroundColor(colors.black)
- term.clear()
- else
- if compare_coord({event[3],event[4]},last_click) then
- last_click = {0,0}
- local sel = fs.list(folder)[event[4]+shift-2]
- if sel ~= nil and event[4] ~= 1 and event[4] ~= h then
- if sel ~= nil then
- local x,y = render_popup(7,sel,true)
- if not fs.isDir(fs.combine(folder,sel)) then
- writepos(x,y,"\aExecute")
- writepos(x,y+1,"\aEdit")
- else
- writepos(x,y,"(Folder)")
- writepos(x,y+1,"(No op.)")
- end
- writepos(x,y+2,"\aRename")
- writepos(x,y+3,"\aDelete")
- writepos(x,y+4,"\aCopy as..")
- writepos(x,y+5,"\aMove to..")
- local e, btn, cx, cy
- repeat
- e, btn, cx, cy = os.pullEvent("mouse_click")
- until cy>=y-1 and cy<=y+4
- if cy==y and not fs.isDir(fs.combine(folder,sel)) then
- term.clear()
- render_folder(folder,shift)
- fill_color(1,h,w-1,h,colors.gray)
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,h)
- shell.setDir(folder)
- shell.run(sel)
- shell.setDir("/")
- term.setCursorPos(1,h)
- write("Execution finished, press to continue")
- os.pullEvent("mouse_click")
- term.setBackgroundColor(colors.black)
- term.clear()
- elseif cy==y+1 then
- shell.run("edit "..fs.combine(folder,sel))
- elseif cy==y+2 then
- writecol(x,y+2,"\aRename",colors.cyan,colors.white)
- term.setCursorPos(x,y+6)
- write("> ")
- local newname = read()
- if newname ~= "" and newname ~= sel then
- fs.copy(fs.combine(folder,sel),fs.combine(folder,newname))
- fs.delete(fs.combine(folder,sel))
- end
- elseif cy==y+3 then
- writecol(x,y+3,"\aDelete",colors.cyan,colors.white)
- term.setCursorPos(x,y+6)
- write("Sure? Y/N ")
- if read() == "Y" then
- fs.delete(fs.combine(folder,sel))
- end
- elseif cy==y+4 then
- writecol(x,y+4,"\aCopy as..",colors.cyan,colors.white)
- term.setCursorPos(x,y+6)
- write("> ")
- local newname = read()
- if newname ~= "" and newname ~= sel then
- fs.copy(fs.combine(folder,sel),fs.combine(folder,newname))
- end
- elseif cy==y+5 then
- writecol(x,y+5,"\aMove to..",colors.cyan,colors.white)
- term.setCursorPos(x,y+6)
- write("> ")
- local newname = read()
- if newname ~= "" and fs.combine(folder,newname) ~= fs.combine(folder,sel) then
- fs.copy(fs.combine(folder,sel),fs.combine(folder,newname,sel))
- fs.delete(fs.combine(folder,sel))
- end
- end
- term.clear()
- end
- end
- else
- last_click = {event[3],event[4]}
- end
- end
- end
- elseif event[1] == "mouse_scroll" then
- shift = max(shift+event[2],1)
- if shift+h-3>#fs.list(folder) then shift = max(#fs.list(folder)-h+3,1) end
- elseif event[1] == "term_resize" or event[1] == "disk_eject" or event[1] == "disk" then
- term.clear()
- end
- end
- end
- local success, msg = pcall(main)
- if not success then blue_screen(msg) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement