Double Escape

Bolt character with both ANSI color and Unicode variation selector

are a mechanism to control the display of text in computer command line tools. While this mechanism is quite old – it originated in the 80s – it is still somehow used nowadays, mostly to color the text in terminals.

The use of control codes to format text has mostly died out, and the range of ASCII characters (escape in particular) used for the escapes has mostly died out. Nowadays people expect text formatting like color, underlines and such not to be expressed in the text itself, but escaped in another language like HTML.

It turns out the idea has not died out, but merely came back, as Unicode as the notion of escape sequences to control the appearance of characters. Some characters, like for instance ⚡ bolt (26A1), can be displayed in two modes:

  • ⚡︎ Text Style
  • ⚡️ Emoji Style

If you look at the source code of this page, you will notice that there is no formatting tag around these characters, instead they are followed by a variation selector: FE0E selects the text variant, and FE0F selects the coloured, emoji variant. If you see only one type of bolt, your browser/operating system does not support variant selectors – if you see nothing, your browser/operating system is missing the font for that particular character.

Unicode variation selectors only apply to the single character they follow where ANSI escape sequences mark a range, with a start and an end. Now the question is, how do they interact? To check this I generated the bolt character in the simplest 7 ANSI colours with both variation selectors. As you can see in the image, ANSI controls the font-color, which is honoured in the text variation and ignored in the emoji (color) variation. This means that in a modern terminal, for certain characters you can get 257 color variations, 256 from ANSI and one from Emoji…

Of course you can get the same behaviour in a web-browser

⚡︎ ⚡️ ⚡︎ ⚡️
⚡︎ ⚡️ ⚡︎ ⚡️
⚡︎ ⚡️ ⚡︎ ⚡️

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: