I want to handle ansi characters of python pty with xtermjs. As I know there is no ansi parser better than xtermjs, xtermjs can handle interactive programs like nano and htop but others can't. so how can I parse and handle ansi charachters with xtermjs in python ?
Currently I have a hacky solution but its slow and needs run java script:
I make a HTML(contains code of xtermjs) with python, something like this :
const term = new Terminal({
convertEol:true,
});
term.open(document.getElementById("terminal"));
term.write(`[?2004h[?1049h[22;0;0t[1;24r(B[m[4l[?7h[39;49m[?1h=[?1h=[?25l[39;49m(B[m[H[2J[22;35H(B[0;7m[ New File ](B[m[H(B[0;7m GNU nano 4.8 a1.txt [1;79H(B[m
[23d(B[0;7m^G(B[m Get Help (B[0;7m^O(B[m Write Out (B[0;7m^W(B[m Where Is (B[0;7m^K(B[m Cut Text (B[0;7m^J(B[m Justify (B[0;7m^C(B[m Cur Pos
[24d(B[0;7m^X(B[m Exit[14G(B[0;7m^R(B[m Read File (B[0;7m^\(B[m Replace (B[0;7m^U(B[m Paste Text(B[0;7m^T(B[m To Spell (B[0;7m^_(B[m Go To Line
[22d[2d[39;49m(B[m[?12l[?25h`)
term.selectAll()
parsed = term.getSelection()
console.debug(parsed)
Then in Python I run this file and capture console logs with selenium!
In this way I can get a pretty output of that ugly string passed to term.write()
P.S : I can't use socket for communication. I appreciate for a better and faster solution.