Advertisement
GreenHat

greenscreen

May 25th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.24 KB | None | 0 0
  1. local isDev = true  -- set this for your own development environments, it will make the BSOD print a line number.
  2.  
  3. term.setBackgorundColor(32)
  4. local function main(argc, argv)
  5.   if argc ~= 0 then
  6.         if argc == 1 then
  7.           if argv[1] == "-help" then
  8.                 print("Valid arguments -help -test")
  9.                 return true -- we want to exit but not trigger the BSOD for something this trivial
  10.           elseif argv[1] == "-test" then
  11.                 print("Tested, now running")
  12.           else
  13.                 print("Invalid argument, "..argv[1].." run with -help to see valid arguments")
  14.                 return true -- we want to exit but not trigger the BSOD for something this trivial
  15.           end
  16.         else
  17.           print("This program only supports 1 argument not "..argc)
  18.           return true -- we want to exit but not trigger the BSOD for something this trivial
  19.         end
  20.   end
  21.  
  22.   -- function calls and main code body here
  23.  
  24.   return true
  25. end
  26.  
  27. local ok, err = pcall(main, #({...}), {...})
  28.  
  29. if not ok then
  30.   -- for the following 2 functions are from my Extended String Library...
  31.   local split = function(str, pat) local t = {} local fpat = "(.-)"..pat local last_end = 1local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e + 1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
  32.   local trim = function(str) return (str:gsub("^%s*(.-)%s*$", "%1")) end
  33.  
  34.   -- localize these as they are only used here
  35.   local setColors = function(bg, txt) if not (term.isColor and term.isColor()) then return false end if txt then term.setTextColor(txt) end if bg then term.setBackgroundColor(bg) end end
  36.   local clear = function(col) if col then term.setBackgroundColor(col) end term.clear() end
  37.   local cwrite = function(msg, y, offset) local sw,sh = term.getSize() term.setCursorPos(sw/2-#msg/2, (y or (sh/2)) + (offset or 0)) write(msg) end
  38.   local errHeader = function(text, y, centre) setColors(colors.white, colors.blue) if centre then cwrite(text, y) else term.setCursorPos(1,y) print(text) end setColors(colors.blue, colors.white) end
  39.   local printMsg = function(text, y) term.setCursorPos(1,y) print(text) end
  40.   local waitForKey = function() while true do local e,k=os.pullEventRaw("key") if k == 28 or k == 156 then break end end end
  41.   local err = split(err,":")
  42.   local sw,sh = term.getSize()
  43.  
  44.   clear(colors.blue)
  45.  
  46.   -- the error headers
  47.   errHeader(" ERROR : "..( err[#err-2] and string.upper(err[#err-2]) or "<UNKNOWN>").." ", 2, true)
  48.   errHeader(" Error Description ", 7, false)
  49.   errHeader(" Reporting the Issue ", sh-7, false)
  50.  
  51.   -- BSOD content
  52.   printMsg("An error has occurred during runtime with \'"..(err[#err-2] or "<unknown>").."\' and the program has ceased working.", 4)
  53.   printMsg(trim((isDev and "Line "..(err[#err-1] and err[#err-1] or "<unknown>")..":" or "")..err[#err]) or "<No error message supplied>",9)
  54.   printMsg("If this problem persists please try updating the program with '-update' and if the problem still persists report the issue with '-report'",sh-5)
  55.  
  56.   cwrite("Press enter to quit...",sh-1)
  57.   waitForKey()
  58.  
  59.   term.clear(colors.black)
  60.   term.setCursorPos(1,1)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement