Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ad3aUsVw
- args = {...}
- HEADER_SIZE = 2;
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num*mult + 0.5)/mult;
- end
- function renderProgram(name,cline,ccol,cdata,mon,linestoRender)
- srend = os.time()
- -- render on advapi?
- program = split(cdata,"\n")
- w,l = mon.getSize()
- offsetrender = 0
- l = l-3; -- keep 3 for debug space.
- if(ccol > w-3) then
- offsetrender = ccol-w+3
- end
- start_line = math.max(0,cline-l+2);
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(1,1)
- --mon.write("Current File: ");
- mon.setTextColor(colors.red);
- mon.write(name);
- mon.setTextColor(colors.white)
- local paddedline = string.format("%03d", cline);
- local paddedcol = string.format("%03d",ccol);
- mon.write("[Line "..paddedline.."] [Col"..paddedcol.."]")
- for current_line = 0,linestoRender do
- local c = current_line + start_line+1;
- if(program[c] ~= nil) then
- toDisplay = program[c]:sub(offsetrender,offsetrender+w);
- else
- toDisplay = "";
- end
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,c+HEADER_SIZE-start_line);
- -- key 200 -> up
- -- key 203 --> LEFT
- -- KEY 205 --> RIGHT
- -- KEY 208 --> DOWN
- --mon.write(string.format("%02d", c));
- --mon.write("|");
- if(c ~= cline) then
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.write(toDisplay);
- else
- for disp = 0,w do
- r = toDisplay:sub(disp+1,disp+1);
- renderunderscore = false
- if(offsetrender + disp+1 == ccol) then
- if(r == " ") then
- mon.setBackgroundColor(colors.green)
- else
- mon.setTextColor(colors.green)
- end
- --print("USC enabled")
- --print(toDisplay:sub(disp+1,disp+1))
- --print("Writing extra at: "..disp)
- renderunderscore = true
- else
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- end
- if(#toDisplay:sub(disp+1,disp+1)== 1) then
- mon.write(toDisplay:sub(disp+1,disp+1));
- elseif((renderunderscore == true)and (#toDisplay:sub(disp+1,disp+1) == 0)) then
- mon.write("@");
- elseif (#toDisplay:sub(disp+1,disp+1) == 0) then
- mon.write("#")
- else
- end
- end
- end
- end
- mon.setCursorPos(1,l+1)
- mon.setTextColor(colors.blue);
- mon.write("Debug: "..w.." "..l.." "..offsetrender.." "..start_line)
- erend = round(os.time()-srend,4)
- mon.setCursorPos(35,1)
- mon.setTextColor(colors.green)
- mon.write(erend.." on "..#cdata.."B")
- end
- function split(str, on)
- local ret = {};
- local s, e;
- while str:find(on) do
- s, e = str:find(on);
- table.insert(ret, str:sub(0, s - 1));
- str = str:sub(e + 1);
- end
- table.insert(ret, str);
- return ret;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement