-
Add the font file named
ColoredConsole-Bold.ttf
in the repo via the Mac OS application Font Book. -
Back to Xcode. Go to “Preference” ⇢ “Texts & Colors” ⇢ “Executable console Output,” click the font icon below, then set font to “Colored Console Bold.”
It’s been nearly 3 years since the issue “Xcode 8 kills code colors” was raised on the venerable XcodeColors project. Since then we’ve been limited to using emojis to add color to our console.
Recently I wondered, has the answer been staring us in the face all that time. While Xcode doesn’t allow styled text, it does respect colored glyphes such as 😊. That very ticket makes a bunch of suggestions for using them in the console.
ColoredConsole-Bold
is a font, based on FiraMono-Bold which adds ligatures for enabling colored variants of the ASCII character set. Here’s the default color range:
The 5 colors are enabled by suffixing the character with one of the Variation Selectors 6-10 (FE06
, FE07
, FE08
, FE09
and FE0A
).
You can have different colors and modifier codepoints by changing and running ./colorify.pl
. I have not documented this (yet).
This workaround is amazing. The creativity that lead to thinking about solving the issue this way is beautiful on its own.
But should you use it?
Probably not.
The output of the text you want to write has to be modified before being sent to the console. This means you cannot copy-paste it!
To be precise, you can copy it, and it will appear normal in a standard text editor. If you open the text in an hex editor though, you’ll see each char is actually 4 chars long.
Searching any text copied from this modified output will not yield any result in a normal (unmodified) text.
Finally, another issue is you cannot use the font you want, of course. You have to use a font which enables ligatures (and modify it to have the ligatures you want), or add said ligatures in the font you want to use.
IMHO, the current workaround for the loss of the colors in Xcode’s console (using emojis) is probably the best, and that’s what we decided to use in our logger for Command Line Tools (but we do use colors when the output console is a terminal).