Process ANSI escape codes before piping
Posted
by
Tiddo
on Super User
See other posts from Super User
or by Tiddo
Published on 2012-10-17T20:45:35Z
Indexed on
2012/10/17
23:05 UTC
Read the original article
Hit count: 349
I'm trying to pipe the output of a script (Mocha) to another script. However there is one problem: Mocha generates quite a few ansi escape characters to update the screen on the fly. These characters are also send through the pipe.
Is there a way to process the ansi sequence such that the output is the same as the final output to the screen? I do want to keep color escape sequences, but not the curser movement escapes.
Edit: I have a partial solution now (for Mocha only): so far it seems that Mocha with the spec output (the one I use) only generates color ecape characters and the CSI 0G
escape sequence. The CSI 0G
escape character means that the cursor should move back to the beginning of the line. Mocha uses this to overwrite a line completely. Therefore you could simply create a sed regexp which will delete everything up to that escape sequence on a line: sed 's/^.*\x1b\[0G//g'
. I am still looking for the complete solution though.
© Super User or respective owner