Add remove ANSI escape codes operation#2143
Conversation
GCHQDeveloper581
left a comment
There was a problem hiding this comment.
Unfortunately this is currently over-enthusiastic.
Whilst it will correctly process input containing the (binary) ANSI escape codes it will also interpret text that contains textually escaped versions of them.
Eg the literal text '\033[32;1;3;4;9mHello, \033[32;1;3;4;9mWorld!' will return 'Hello World' rather than repeating the original text.
To illustrate more clearly here is a hex message containing the codes as binary:
1b 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 48 65 6c 6c 6f 2c 20 1b 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 57 6f 72 6c 64 21
and here it is with textual (Javascript) escapes:
5c 30 33 33 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 48 65 6c 6c 6f 2c 20 5c 30 33 33 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 57 6f 72 6c 64 21
When either of these is passed as input to the recipe:
[
{ "op": "From Hex",
"args": ["Auto"] },
{ "op": "Remove ANSI Escape Codes",
"args": [] },
{ "op": "To Hex",
"args": ["Space", 0] }
]
they will produce the output:
48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21
However the second example should produce its input ie
5c 30 33 33 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 48 65 6c 6c 6f 2c 20 5c 30 33 33 5b 33 32 3b 31 3b 33 3b 34 3b 39 6d 57 6f 72 6c 64 21
This closes #2142
Currently limited to Fe escape sequences which uses ESC (0x1B)
Considerations:
Add feature switch to switch between more control/escape sequences. (i.e. C0 control codes)