Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. --ad3aUsVw
  2. args = {...}
  3. HEADER_SIZE = 2;
  4. function round(num, numDecimalPlaces)
  5. local mult = 10^(numDecimalPlaces or 0)
  6. return math.floor(num*mult + 0.5)/mult;
  7. end
  8. function renderProgram(name,cline,ccol,cdata,mon,linestoRender)
  9. srend = os.time()
  10. -- render on advapi?
  11. program = split(cdata,"\n")
  12. w,l = mon.getSize()
  13. offsetrender = 0
  14. l = l-3; -- keep 3 for debug space.
  15. if(ccol > w-3) then
  16. offsetrender = ccol-w+3
  17. end
  18. start_line = math.max(0,cline-l+2);
  19. mon.setTextColor(colors.white)
  20. mon.setBackgroundColor(colors.black)
  21. mon.setCursorPos(1,1)
  22. --mon.write("Current File: ");
  23. mon.setTextColor(colors.red);
  24. mon.write(name);
  25. mon.setTextColor(colors.white)
  26. local paddedline = string.format("%03d", cline);
  27. local paddedcol = string.format("%03d",ccol);
  28. mon.write("[Line "..paddedline.."] [Col"..paddedcol.."]")
  29. for current_line = 0,linestoRender do
  30. local c = current_line + start_line+1;
  31. if(program[c] ~= nil) then
  32. toDisplay = program[c]:sub(offsetrender,offsetrender+w);
  33. else
  34. toDisplay = "";
  35. for i = 0,w do
  36. toDisplay = toDisplay.." "
  37. end
  38. end
  39. mon.setTextColor(colors.white)
  40.  
  41. mon.setCursorPos(1,c+HEADER_SIZE-start_line);
  42. -- key 200 -> up
  43. -- key 203 --> LEFT
  44. -- KEY 205 --> RIGHT
  45. -- KEY 208 --> DOWN
  46. --mon.write(string.format("%02d", c));
  47. --mon.write("|");
  48. if(c ~= cline) then
  49. mon.setBackgroundColor(colors.black)
  50. mon.setTextColor(colors.white)
  51. mon.write(toDisplay);
  52. else
  53. for disp = 0,w do
  54. r = toDisplay:sub(disp+1,disp+1);
  55. renderunderscore = false
  56. if(offsetrender + disp+1 == ccol) then
  57. if(r == " ") then
  58. mon.setBackgroundColor(colors.green)
  59. else
  60. mon.setTextColor(colors.green)
  61. end
  62. --print("USC enabled")
  63. --print(toDisplay:sub(disp+1,disp+1))
  64. --print("Writing extra at: "..disp)
  65. renderunderscore = true
  66. else
  67. mon.setTextColor(colors.white)
  68. mon.setBackgroundColor(colors.black)
  69. end
  70.  
  71. if(#toDisplay:sub(disp+1,disp+1)== 1) then
  72. mon.write(toDisplay:sub(disp+1,disp+1));
  73. elseif((renderunderscore == true)and (#toDisplay:sub(disp+1,disp+1) == 0)) then
  74. mon.write("@");
  75. elseif (#toDisplay:sub(disp+1,disp+1) == 0) then
  76. mon.write(" ")
  77. else
  78. end
  79. end
  80. end
  81.  
  82. end
  83. mon.setCursorPos(1,l+1)
  84. mon.setTextColor(colors.blue);
  85. mon.write("Debug: "..w.." "..l.." "..offsetrender.." "..start_line)
  86. erend = round(os.time()-srend,4)
  87. mon.setCursorPos(35,1)
  88. mon.setTextColor(colors.green)
  89. mon.write(erend.." on "..#cdata.."B")
  90. end
  91.  
  92.  
  93. function split(str, on)
  94. local ret = {};
  95. local s, e;
  96. while str:find(on) do
  97. s, e = str:find(on);
  98. table.insert(ret, str:sub(0, s - 1));
  99. str = str:sub(e + 1);
  100. end
  101. table.insert(ret, str);
  102. return ret;
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement