Advertisement
ndfjay

ignore this

Feb 14th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. function fwrite(path, text)
  2.     local file = assert(io.open(path, "w"))
  3.     file:write(text)
  4.     file:close()
  5. end
  6. function getText(path)
  7.     if fs.exists(path) then
  8.         local file = assert(io.open(path, "r"))
  9.         return file:read("*a")
  10.     end
  11.     return ""
  12. end
  13. function append(path, text)
  14.     local _text = getText(path)
  15.     fwrite(path, text.."\n".._text)
  16. end
  17. crash = function(func,align,bcol,tcol)
  18. local w,h = term.getSize()
  19. local ok, err = pcall(func)
  20. term.setBackgroundColor(bcol)
  21. term.setTextColor(tcol)
  22. term.clear()
  23. local tmpErr = {
  24. "Oh No! We've Crashed!";
  25. " ";
  26. "Error Code:";
  27. err;
  28. " ";
  29. " ";
  30. "Please report this code to the dev if this is";
  31. "no fault of your own";
  32. " ";
  33. " ";
  34. "Please do refrain from modifying the base code!"
  35. }
  36.     if not ok then
  37.         if align == "left" then
  38.             for i,v in pairs(tmpErr) do
  39.                 term.setCursorPos(1,i+1)
  40.                 print(v)
  41.             end
  42.                 elseif align == "center" then
  43.                 for i,v in pairs(tmpErr) do
  44.                     term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
  45.                     print(v)
  46.                 end
  47.                 term.setBackgroundColor(colors.black)
  48.                 term.setCursorPos(1,math.floor(h))
  49.                 term.clearLine()
  50.         end
  51. term.setBackgroundColor(colors.black)
  52. term.setCursorPos(1,math.floor(h))
  53. term.clearLine()
  54.     end
  55. end
  56. custCrash = function(func,align,bcol,tcol,t,errLine)
  57. local w,h = term.getSize()
  58. local ok, err = pcall(func)
  59. term.setBackgroundColor(bcol)
  60. term.setTextColor(tcol)
  61. term.clear()
  62. if not ok then
  63.     if align == "left" then
  64.         for i,v in pairs(t) do
  65.             term.setCursorPos(1,i+1)
  66.             print(v)
  67.         end
  68.         term.setCursorPos(1,errLine)
  69.         write(err)
  70.             elseif align == "center" then
  71.             for i,v in pairs(t) do
  72.                 term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
  73.                 print(v)
  74.             end
  75.             term.setCursorPos(math.floor(w-string.len(err))/2,errLine)
  76.             write(err)
  77.         end
  78.     end
  79. term.setBackgroundColor(colors.black)
  80. term.setCursorPos(1,math.floor(h))
  81. term.clearLine()
  82. end
  83. resolveCrash = function(func,resolvefunc)
  84. local w,h = term.getSize()
  85. local ok, err = pcall(func)
  86. if not ok then
  87. resolvefunc()
  88. end
  89. end
  90. saveCrash = function(func,align,bcol,tcol,t,x,y,sDir,sPath,sText,errLine)
  91. local w,h = term.getSize()
  92. local ok, err = pcall(func)
  93. local success = {
  94. "Error Log Saved to "..sDir.."/"..sPath;
  95. " ";
  96. "Please show the log to the Dev"
  97. }
  98. term.setBackgroundColor(bcol)
  99. term.setTextColor(tcol)
  100. term.clear()
  101. if not ok then
  102.     if align == "left" then
  103.         for i,v in pairs(t) do
  104.             term.setCursorPos(1,i+1)
  105.             print(v)
  106.         end
  107.         term.setCursorPos(1,errLine)
  108.         write(err)
  109.             elseif align == "center" then
  110.             for i,v in pairs(t) do
  111.                 term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
  112.                 print(v)
  113.             end
  114.             term.setCursorPos(math.floor(w-string.len(err))/2,errLine)
  115.             write(err)
  116.         end
  117. term.setCursorPos(x,y)
  118. write(sText)
  119. local event, button, X, Y = os.pullEvent("mouse_click")
  120. while true do
  121.     if X>=x and X<=string.len(sText) and Y==y and button == 1 then
  122.         if not fs.exists(sDir) then
  123.         fs.makeDir(sDir)
  124.         end
  125.         if not fs.exists(sDir.."/"..sPath) then
  126.         fwrite(sDir.."/"..sPath," ")
  127.         end
  128.         append(sDir.."/"..sPath, string.rep("=",40))
  129.         append(sDir.."/"..sPath, " ")
  130.         append(sDir.."/"..sPath, tostring(err))
  131.         append(sDir.."/"..sPath, " ")
  132.         append(sDir.."/"..sPath, string.rep("=",40))
  133.         term.setBackgroundColour(bcol)
  134.         term.setTextColour(tcol)
  135.         term.clear()
  136.             if align == "left" then
  137.                 for i,v in pairs(success) do
  138.                     term.setCursorPos(1,i+1)
  139.                     print(v)
  140.                 end
  141.                     elseif align == "center" then
  142.                     for i,v in pairs(success) do
  143.                         term.setCursorPos(math.floor(w-string.len(v))/2, i+1)
  144.                         print(v)
  145.                     end
  146.             end
  147.         term.setBackgroundColour(colors.black)
  148.         term.setTextColor(1)
  149.         term.setCursorPos(1,math.floor(h))
  150.         term.clearLine()
  151.         return true
  152.     end
  153. end
  154. end
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement