Reputation: 41983
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)
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?
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?
...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
Reputation: 41983
Need to set the output encoding thusly:
System.Console.OutputEncoding = Encoding.UTF8;
Upvotes: 1