SHOW:
|
|
- or go back to the newest paste.
| 1 | term.clear() | |
| 2 | writepos, writecol, multchar, max, min, compare_coord, fill_color, render_folder, render_popup, render_time = table.unpack(require "os_library") | |
| 3 | ||
| 4 | local function blue_screen(msg) | |
| 5 | local w,h = term.getSize() | |
| 6 | term.setBackgroundColor(colors.blue) | |
| 7 | term.setTextColor(colors.white) | |
| 8 | term.clear() | |
| 9 | writepos(2,2,":( An unexpected error has occurred!") | |
| 10 | writepos(2,3,"We are working on fixing the problem.") | |
| 11 | writepos(2,5,"Error: "..msg) | |
| 12 | ||
| 13 | writepos(2,7,"\aOpen shell") | |
| 14 | writepos(2,8,"\aRestart OS") | |
| 15 | writepos(2,9,"\aShutdown") | |
| 16 | local e, btn, cx, cy | |
| 17 | repeat | |
| 18 | e, btn, cx, cy = os.pullEvent("mouse_click")
| |
| 19 | until cy>=7 and cy<=9 | |
| 20 | ||
| 21 | term.setCursorPos(1,h) | |
| 22 | if cy==7 then | |
| 23 | term.setBackgroundColor(colors.black) | |
| 24 | term.clearLine() | |
| 25 | elseif cy==8 then | |
| 26 | shell.run("reboot")
| |
| 27 | elseif cy==9 then | |
| 28 | shell.run("shutdown")
| |
| 29 | end | |
| 30 | end | |
| 31 | ||
| 32 | local function is_lua_script(name) | |
| 33 | local afterdot = string.match(name, "%.(.*)") | |
| 34 | return afterdot == "lua" or afterdot == nil | |
| 35 | end | |
| 36 | local args = {...}
| |
| 37 | local folder = args[1]==nil and "" or args[1] | |
| 38 | local shift = 1 | |
| 39 | local last_click = {0,0}
| |
| 40 | ||
| 41 | local function main() | |
| 42 | while true do | |
| 43 | render_folder(folder,shift) | |
| 44 | local event = {os.pullEvent()}
| |
| 45 | local w,h = term.getSize() | |
| 46 | if event[1] == "timer" then | |
| 47 | render_time() | |
| 48 | elseif event[1] == "mouse_click" then | |
| 49 | if event[2] == 1 then | |
| 50 | if event[3] == w then | |
| 51 | if event[4] == h then | |
| 52 | shift = min(shift + 1,#fs.list(folder)-h+3) | |
| 53 | elseif event[4] == 1 then | |
| 54 | shift = max(shift-1,1) | |
| 55 | elseif event[4] == 3 and term.isColour() then | |
| 56 | shell.run("fg shell")
| |
| 57 | elseif event[4] == math.floor(h/2) then | |
| 58 | if folder~="" then folder = fs.combine(folder,"..") end | |
| 59 | shift = 1 | |
| 60 | term.clear() | |
| 61 | elseif event[4] == math.floor(h/2)-1 then | |
| 62 | folder = "/UserFiles" | |
| 63 | shift = 1 | |
| 64 | term.clear() | |
| 65 | elseif event[4] == 2 then | |
| 66 | shift = 1 | |
| 67 | elseif event[4] == h-1 then | |
| 68 | shift = max(#fs.list(folder)-h+3,1) | |
| 69 | elseif event[4] == h-2 then | |
| 70 | local x,y = render_popup(3,"Create",true) | |
| 71 | local is_folder = false | |
| 72 | writepos(x,y,"\aFile") | |
| 73 | writepos(x,y+1,"\aFolder") | |
| 74 | local e, btn, cx, cy | |
| 75 | repeat | |
| 76 | e, btn, cx, cy = os.pullEvent("mouse_click")
| |
| 77 | until cy == y or cy == y+1 or cy == y-1 | |
| 78 | if cy == y then | |
| 79 | writecol(x,y,"\aFile",colors.cyan,colors.white) | |
| 80 | elseif cy == y+1 then | |
| 81 | writecol(x,y+1,"\aFolder",colors.cyan,colors.white) | |
| 82 | is_folder = true | |
| 83 | end | |
| 84 | if cy ~= y-1 then | |
| 85 | term.setCursorPos(x,y+2) | |
| 86 | write("> ")
| |
| 87 | local rd = read() | |
| 88 | if not is_folder and rd~="" then fs.open(fs.combine(folder,rd),"w").close() else fs.makeDir(fs.combine(folder,rd)) end | |
| 89 | end | |
| 90 | term.clear() | |
| 91 | end | |
| 92 | elseif compare_coord({event[3],event[4]},{1,h}) then
| |
| 93 | term.setCursorPos(1,h) | |
| 94 | term.setBackgroundColor(colors.gray) | |
| 95 | term.clearLine() | |
| 96 | write("> ")
| |
| 97 | shell.setDir(folder) | |
| 98 | shell.run(read()) | |
| 99 | shell.setDir("/")
| |
| 100 | term.setCursorPos(1,h) | |
| 101 | - | write("Execution finished, any key to continue")
|
| 101 | + | write("Execution finished, press to continue")
|
| 102 | - | os.pullEvent("key")
|
| 102 | + | os.pullEvent("mouse_click")
|
| 103 | term.setBackgroundColor(colors.black) | |
| 104 | term.clear() | |
| 105 | else | |
| 106 | if compare_coord({event[3],event[4]},last_click) then
| |
| 107 | last_click = {0,0}
| |
| 108 | local sel = fs.list(folder)[event[4]+shift-2] | |
| 109 | if sel ~= nil and event[4] ~= 1 and event[4] ~= h then | |
| 110 | - | if fs.isDir(fs.combine(folder,sel)) then |
| 110 | + | if sel ~= nil then |
| 111 | - | folder = fs.combine(folder,sel) |
| 111 | + | local x,y = render_popup(7,sel,true) |
| 112 | - | shift = 1 |
| 112 | + | if not fs.isDir(fs.combine(folder,sel)) then |
| 113 | - | else |
| 113 | + | writepos(x,y,"\aExecute") |
| 114 | - | if is_lua_script(sel) then |
| 114 | + | writepos(x,y+1,"\aEdit") |
| 115 | - | term.setBackgroundColor(colors.gray) |
| 115 | + | else |
| 116 | - | paintutils.drawLine(1,h,w,h,colors.gray) |
| 116 | + | writepos(x,y,"(Folder)") |
| 117 | - | term.setCursorPos(1,h) |
| 117 | + | writepos(x,y+1,"(No op.)") |
| 118 | - | shell.run(fs.combine(folder,sel)) |
| 118 | + | |
| 119 | - | shell.setDir("/")
|
| 119 | + | writepos(x,y+2,"\aRename") |
| 120 | - | term.setBackgroundColor(colors.gray) |
| 120 | + | writepos(x,y+3,"\aDelete") |
| 121 | - | paintutils.drawLine(1,h,w,h,colors.gray) |
| 121 | + | writepos(x,y+4,"\aCopy as..") |
| 122 | - | term.setCursorPos(1,h) |
| 122 | + | writepos(x,y+5,"\aMove to..") |
| 123 | - | write("Execution finished, any key to continue")
|
| 123 | + | local e, btn, cx, cy |
| 124 | - | os.pullEvent("key")
|
| 124 | + | repeat |
| 125 | - | term.setBackgroundColor(colors.black) |
| 125 | + | e, btn, cx, cy = os.pullEvent("mouse_click")
|
| 126 | - | else |
| 126 | + | until cy>=y-1 and cy<=y+4 |
| 127 | if cy==y and not fs.isDir(fs.combine(folder,sel)) then | |
| 128 | term.clear() | |
| 129 | render_folder(folder,shift) | |
| 130 | - | term.clear() |
| 130 | + | fill_color(1,h,w-1,h,colors.gray) |
| 131 | term.setBackgroundColor(colors.gray) | |
| 132 | term.setCursorPos(1,h) | |
| 133 | shell.setDir(folder) | |
| 134 | shell.run(sel) | |
| 135 | shell.setDir("/")
| |
| 136 | - | elseif event[2] == 2 then |
| 136 | + | term.setCursorPos(1,h) |
| 137 | - | if event[3] ~= w and event[4] ~= 1 and event[4] ~= h then |
| 137 | + | write("Execution finished, press to continue")
|
| 138 | - | local sel = fs.list(folder)[event[4]+shift-2] |
| 138 | + | os.pullEvent("mouse_click")
|
| 139 | - | if sel ~= nil then |
| 139 | + | term.setBackgroundColor(colors.black) |
| 140 | - | local x,y = render_popup(6,sel,true) |
| 140 | + | term.clear() |
| 141 | - | if not fs.isDir(fs.combine(folder,sel)) then |
| 141 | + | elseif cy==y+1 then |
| 142 | - | if not is_lua_script(sel) then writepos(x,y,"\aExecute") |
| 142 | + | |
| 143 | - | else writepos(x,y,"\aEdit") end |
| 143 | + | elseif cy==y+2 then |
| 144 | - | else writepos(x,y,"(Folder)") end |
| 144 | + | writecol(x,y+2,"\aRename",colors.cyan,colors.white) |
| 145 | - | writepos(x,y+1,"\aRename") |
| 145 | + | term.setCursorPos(x,y+6) |
| 146 | - | writepos(x,y+2,"\aDelete") |
| 146 | + | write("> ")
|
| 147 | - | writepos(x,y+3,"\aCopy as..") |
| 147 | + | local newname = read() |
| 148 | - | writepos(x,y+4,"\aMove to..") |
| 148 | + | if newname ~= "" and newname ~= sel then |
| 149 | fs.copy(fs.combine(folder,sel),fs.combine(folder,newname)) | |
| 150 | fs.delete(fs.combine(folder,sel)) | |
| 151 | end | |
| 152 | - | until cy>=y-1 and cy<=y+4 |
| 152 | + | elseif cy==y+3 then |
| 153 | - | if cy==y and not fs.isDir(fs.combine(folder,sel)) then |
| 153 | + | writecol(x,y+3,"\aDelete",colors.cyan,colors.white) |
| 154 | - | if not is_lua_script(sel) then |
| 154 | + | term.setCursorPos(x,y+6) |
| 155 | write("Sure? Y/N ")
| |
| 156 | - | render_folder(folder,shift) |
| 156 | + | if read() == "Y" then |
| 157 | - | fill_color(1,h,w-1,h,colors.gray) |
| 157 | + | fs.delete(fs.combine(folder,sel)) |
| 158 | - | term.setBackgroundColor(colors.gray) |
| 158 | + | end |
| 159 | - | term.setCursorPos(1,h) |
| 159 | + | elseif cy==y+4 then |
| 160 | - | shell.setDir(folder) |
| 160 | + | writecol(x,y+4,"\aCopy as..",colors.cyan,colors.white) |
| 161 | - | shell.run(sel) |
| 161 | + | term.setCursorPos(x,y+6) |
| 162 | - | shell.setDir("/")
|
| 162 | + | write("> ")
|
| 163 | - | term.setCursorPos(1,h) |
| 163 | + | local newname = read() |
| 164 | - | write("Execution finished, any key to continue")
|
| 164 | + | if newname ~= "" and newname ~= sel then |
| 165 | - | os.pullEvent("key")
|
| 165 | + | fs.copy(fs.combine(folder,sel),fs.combine(folder,newname)) |
| 166 | - | term.setBackgroundColor(colors.black) |
| 166 | + | end |
| 167 | - | else |
| 167 | + | elseif cy==y+5 then |
| 168 | - | shell.run("edit "..fs.combine(folder,sel))
|
| 168 | + | writecol(x,y+5,"\aMove to..",colors.cyan,colors.white) |
| 169 | term.setCursorPos(x,y+6) | |
| 170 | - | term.clear() |
| 170 | + | write("> ")
|
| 171 | - | elseif cy==y+1 then |
| 171 | + | local newname = read() |
| 172 | - | writecol(x,y+1,"\aRename",colors.cyan,colors.white) |
| 172 | + | if newname ~= "" and fs.combine(folder,newname) ~= fs.combine(folder,sel) then |
| 173 | - | term.setCursorPos(x,y+5) |
| 173 | + | fs.copy(fs.combine(folder,sel),fs.combine(folder,newname,sel)) |
| 174 | fs.delete(fs.combine(folder,sel)) | |
| 175 | - | local newname = read() |
| 175 | + | end |
| 176 | - | if newname ~= "" and newname ~= sel then |
| 176 | + | |
| 177 | - | fs.copy(fs.combine(folder,sel),fs.combine(folder,newname)) |
| 177 | + | |
| 178 | - | fs.delete(fs.combine(folder,sel)) |
| 178 | + | |
| 179 | end | |
| 180 | - | elseif cy==y+2 then |
| 180 | + | |
| 181 | - | writecol(x,y+2,"\aDelete",colors.cyan,colors.white) |
| 181 | + | |
| 182 | - | term.setCursorPos(x,y+5) |
| 182 | + | |
| 183 | - | write("Sure? Y/N ")
|
| 183 | + | |
| 184 | - | if read() == "Y" then |
| 184 | + | |
| 185 | - | fs.delete(fs.combine(folder,sel)) |
| 185 | + | |
| 186 | shift = max(shift+event[2],1) | |
| 187 | - | elseif cy==y+3 then |
| 187 | + | |
| 188 | - | writecol(x,y+3,"\aCopy as..",colors.cyan,colors.white) |
| 188 | + | |
| 189 | - | term.setCursorPos(x,y+5) |
| 189 | + | |
| 190 | end | |
| 191 | - | local newname = read() |
| 191 | + | |
| 192 | - | if newname ~= "" and newname ~= sel then |
| 192 | + | |
| 193 | - | fs.copy(fs.combine(folder,sel),fs.combine(folder,newname)) |
| 193 | + | |
| 194 | local success, msg = pcall(main) | |
| 195 | - | elseif cy==y+4 then |
| 195 | + |