Advertisement
Guest User

demo1

a guest
Feb 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 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.         end
  36.         mon.setTextColor(colors.white)
  37.        
  38.         mon.setCursorPos(1,c+HEADER_SIZE-start_line);
  39.         -- key 200 -> up
  40.         -- key 203 --> LEFT
  41.         -- KEY 205 --> RIGHT
  42.         -- KEY 208 --> DOWN
  43.         --mon.write(string.format("%02d", c));
  44.         --mon.write("|");
  45.         if(c ~= cline) then
  46.             mon.setBackgroundColor(colors.black)
  47.             mon.setTextColor(colors.white)
  48.             mon.write(toDisplay);
  49.         else
  50.             for disp = 0,w do
  51.                 r = toDisplay:sub(disp+1,disp+1);
  52.                 renderunderscore = false
  53.                 if(offsetrender + disp+1 == ccol) then
  54.                     if(r == " ") then
  55.                         mon.setBackgroundColor(colors.green)
  56.                     else
  57.                         mon.setTextColor(colors.green)
  58.                     end
  59.                 --print("USC enabled")
  60.                 --print(toDisplay:sub(disp+1,disp+1))
  61.                 --print("Writing extra at: "..disp)
  62.                     renderunderscore = true    
  63.                 else
  64.                     mon.setTextColor(colors.white)
  65.                     mon.setBackgroundColor(colors.black)
  66.                 end
  67.                
  68.                 if(#toDisplay:sub(disp+1,disp+1)== 1) then
  69.                     mon.write(toDisplay:sub(disp+1,disp+1));
  70.                 elseif((renderunderscore == true)and (#toDisplay:sub(disp+1,disp+1) == 0)) then
  71.                        mon.write("@");
  72.                 elseif (#toDisplay:sub(disp+1,disp+1) == 0) then
  73.                     mon.write("#")
  74.                 else
  75.                 end
  76.              end
  77.         end
  78.        
  79.     end
  80.     mon.setCursorPos(1,l+1)
  81.     mon.setTextColor(colors.blue);
  82.     mon.write("Debug: "..w.." "..l.." "..offsetrender.." "..start_line)
  83.  erend = round(os.time()-srend,4)
  84.  mon.setCursorPos(35,1)
  85.  mon.setTextColor(colors.green)
  86.  mon.write(erend.." on "..#cdata.."B") 
  87. end
  88.  
  89.  
  90. function split(str, on)
  91.   local ret = {};
  92.   local s, e;
  93.   while str:find(on) do
  94.     s, e = str:find(on);
  95.     table.insert(ret, str:sub(0, s - 1));
  96.     str = str:sub(e + 1);
  97.   end
  98.   table.insert(ret, str);
  99.   return ret;
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement