Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fwrite(path, text)
- local file = assert(io.open(path, "w"))
- file:write(text)
- file:close()
- end
- function getText(path)
- if fs.exists(path) then
- local file = assert(io.open(path, "r"))
- return file:read("*a")
- end
- return ""
- end
- function append(path, text)
- local _text = getText(path)
- fwrite(path, text.."\n".._text)
- end
- crash = function(func,align,bcol,tcol)
- local w,h = term.getSize()
- local ok, err = pcall(func)
- term.setBackgroundColor(bcol)
- term.setTextColor(tcol)
- term.clear()
- local tmpErr = {
- "Oh No! We've Crashed!";
- " ";
- "Error Code:";
- err;
- " ";
- " ";
- "Please report this code to the dev if this is";
- "no fault of your own";
- " ";
- " ";
- "Please do refrain from modifying the base code!"
- }
- if not ok then
- if align == "left" then
- for i,v in pairs(tmpErr) do
- term.setCursorPos(1,i+1)
- print(v)
- end
- elseif align == "center" then
- for i,v in pairs(tmpErr) do
- term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
- print(v)
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,math.floor(h))
- term.clearLine()
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,math.floor(h))
- term.clearLine()
- end
- end
- custCrash = function(func,align,bcol,tcol,t,errLine)
- local w,h = term.getSize()
- local ok, err = pcall(func)
- term.setBackgroundColor(bcol)
- term.setTextColor(tcol)
- term.clear()
- if not ok then
- if align == "left" then
- for i,v in pairs(t) do
- term.setCursorPos(1,i+1)
- print(v)
- end
- term.setCursorPos(1,errLine)
- write(err)
- elseif align == "center" then
- for i,v in pairs(t) do
- term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
- print(v)
- end
- term.setCursorPos(math.floor(w-string.len(err))/2,errLine)
- write(err)
- end
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,math.floor(h))
- term.clearLine()
- end
- resolveCrash = function(func,resolvefunc)
- local w,h = term.getSize()
- local ok, err = pcall(func)
- if not ok then
- resolvefunc()
- end
- end
- saveCrash = function(func,align,bcol,tcol,t,x,y,sDir,sPath,sText,errLine)
- local w,h = term.getSize()
- local ok, err = pcall(func)
- local success = {
- "Error Log Saved to "..sDir.."/"..sPath;
- " ";
- "Please show the log to the Dev"
- }
- term.setBackgroundColor(bcol)
- term.setTextColor(tcol)
- term.clear()
- if not ok then
- if align == "left" then
- for i,v in pairs(t) do
- term.setCursorPos(1,i+1)
- print(v)
- end
- term.setCursorPos(1,errLine)
- write(err)
- elseif align == "center" then
- for i,v in pairs(t) do
- term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
- print(v)
- end
- term.setCursorPos(math.floor(w-string.len(err))/2,errLine)
- write(err)
- end
- term.setCursorPos(x,y)
- write(sText)
- local event, button, X, Y = os.pullEvent("mouse_click")
- while true do
- if X>=x and X<=string.len(sText) and Y==y and button == 1 then
- if not fs.exists(sDir) then
- fs.makeDir(sDir)
- end
- if not fs.exists(sDir.."/"..sPath) then
- fwrite(sDir.."/"..sPath," ")
- end
- append(sDir.."/"..sPath, string.rep("=",40))
- append(sDir.."/"..sPath, " ")
- append(sDir.."/"..sPath, tostring(err))
- append(sDir.."/"..sPath, " ")
- append(sDir.."/"..sPath, string.rep("=",40))
- term.setBackgroundColour(bcol)
- term.setTextColour(tcol)
- term.clear()
- if align == "left" then
- for i,v in pairs(success) do
- term.setCursorPos(1,i+1)
- print(v)
- end
- elseif align == "center" then
- for i,v in pairs(success) do
- term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
- print(v)
- end
- end
- term.setBackgroundColour(colors.black)
- term.setTextColor(1)
- term.setCursorPos(1,math.floor(h))
- term.clearLine()
- return true
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement