3
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.
The same question exists here http://stackoverflow.com/questions/6306728/remove-ansi-codes-when-storing-script-output
– dset0x – 2012-10-17T20:50:17.867@zmode that's not the identical, that one is about removing all ansi codes, whereas here the OP wants to "keep color escape sequences" – eis – 2012-10-17T20:55:58.943
@Tiddo Do you know how the other script would handle the color escapes? it would sound peculiar that it could handle them... – eis – 2012-10-17T21:02:00.573
@eis - The other script is ansifilter. It generates colored HTML from ansi input. By design it is able to handle color escapes, but for some reason it can't handle the movement escape characters.
– Tiddo – 2012-10-17T21:36:01.653@Tiddo ok, makes sense. – eis – 2012-10-18T08:24:33.350