Skip to content

Add remove ANSI escape codes operation#2143

Open
Louis-Ladd wants to merge 13 commits intogchq:masterfrom
Louis-Ladd:master
Open

Add remove ANSI escape codes operation#2143
Louis-Ladd wants to merge 13 commits intogchq:masterfrom
Louis-Ladd:master

Conversation

@Louis-Ladd
Copy link

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)

@GCHQDeveloper581 GCHQDeveloper581 self-requested a review March 2, 2026 10:26
Copy link
Contributor

@GCHQDeveloper581 GCHQDeveloper581 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Tool to remove ANSI terminal escape sequences

3 participants