Kieren Johnstone
Kieren Johnstone

Reputation: 41983

Emoji output: xterm escape sequence oddity?

I have a .NET Core app. The only thing it does is:

System.Console.Out.WriteLine("\x1b%G🍜");

When I run this on a "fresh" Powershell tab in Windows Terminal, it outputs

??

When I run it a second time in the same tab, it correctly outputs:

🍜 (ramen emoji)

Running the same line twice in one process does not work - it's ?? twice.

(If I don't include the \x1b%G escape sequence, it 'never' appears as a ramen emoji)

What I'm trying to do

Work out what it is that "enables" emojis for a terminal (be it Windows Terminal, the new conhost in Windows 11, etc).

I thought it might be \x1b%G, the xterm escape sequence to enable UTF-8. Maybe it is? ...but why not until the process exits and is started again in powershell?

Other notes

If I don't use a blank Powershell profile, but instead use one that gives fancy prompts (Set-PoshPrompt -Theme powerlevel10k_rainbow for instance)... then emojis are "activated" / "enabled". So maybe there's something that Powershell, or posh prompt does, that I can replicate?

The correct answer to this question will...

...tell me what I need to do to have emojis correctly appear in my terminal, without having to run the process twice.

Upvotes: 0

Views: 236

Answers (1)

Kieren Johnstone
Kieren Johnstone

Reputation: 41983

Need to set the output encoding thusly:

System.Console.OutputEncoding = Encoding.UTF8;

Upvotes: 1

Related Questions