Advertisement
npexception

TickProfiler script based on Nallar's

Jan 18th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local version = 1.0
  2. if _UD and _UD.su(version, "D6ZGXc86", {...}) then return end
  3.  
  4. local monitor = peripheral.find("monitor")
  5. local oldTerm
  6.  
  7. if monitor then
  8.   oldTerm = term.redirect(monitor)
  9. else
  10.   print("No monitor found")
  11.   return
  12. end
  13.  
  14. function explode(inSplitPattern, str)
  15.   str = str .. ""
  16.   local outResults = { }
  17.   local theStart = 1
  18.   local theSplitStart, theSplitEnd = string.find( str, inSplitPattern, theStart )
  19.   while theSplitStart do
  20.   local sub = string.sub( str, theStart, theSplitStart-1 )
  21.     table.insert( outResults,  sub)
  22.     theStart = theSplitEnd + 1
  23.     theSplitStart, theSplitEnd = string.find( str, inSplitPattern, theStart )
  24.   end
  25.   table.insert( outResults, string.sub( str, theStart ) )
  26.   return outResults
  27. end
  28.  
  29. function printColouredBars(str, first)
  30.   parts = explode("|", str)
  31.   local l = #parts
  32.   for k = 1, l do
  33.     if first then
  34.       term.setTextColor(colors.blue)
  35.     end
  36.     io.write(parts[k])
  37.     if first then
  38.       term.setTextColor(colors.white)
  39.     end
  40.     if k ~= l then
  41.       term.setTextColor(colors.red)
  42.       io.write("|")
  43.       term.setTextColor(colors.white)
  44.     end
  45.   end
  46. end
  47.  
  48. function profile()
  49.   term.setCursorPos(1, 1)
  50.   local file = fs.open("profile.txt", "r")
  51.   local text = file.readAll()
  52.   file.close()
  53.   local tables = explode("\n\n", string.gsub(text, "\r\n", "\n"))
  54.   term.clear()
  55.   local i, j
  56.   for i = 1, #tables do
  57.     lines = explode("\n", tables[i] .. "")
  58.     if #lines == 1 then
  59.       term.setTextColor(colors.green)
  60.       print(lines[1])
  61.       term.setTextColor(colors.white)
  62.     else
  63.       for j = 1, #lines do
  64.         printColouredBars(lines[j] .. "\n", j == 1)
  65.       end
  66.       if i ~= #tables then
  67.         io.write("\n")
  68.       end
  69.     end
  70.   end
  71. end
  72.  
  73. while true do
  74.   profile()
  75.   sleep(60)
  76. end
  77.  
  78. term.redirect(oldTerm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement