PwshSpectreConsole icon indicating copy to clipboard operation
PwshSpectreConsole copied to clipboard

Emojis not visible even in unicode-supported terminal

Open JustinGrote opened this issue 1 year ago • 5 comments

PWSH 7.4, Windows Terminal, also happens in vscode. PwshSpectreConsole 2.1.1 image

JustinGrote avatar Sep 09 '24 19:09 JustinGrote

SpectreConsole checks terminal capabilities on import and sets a profile.

try running this before you import the module.

$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

i could replicate your issue in my extension terminal, i had forgot to set UTF8 in my vscode profile.

after setting that and restarting the terminal emojis worked.

if it still doesn't work, could you share the output of the below command?

& (gmo PwshSpectreConsole) { Get-SpectreProfile }

trackd avatar Sep 09 '24 22:09 trackd

That does fix it! Interesting. Would it be worth autodetecting some terminals we know have unicode support and enable this? E.g. Windows Terminal can be detected with WT_PROFILE_ID env variable

EDIT: Related: https://github.com/PowerShell/PowerShell/issues/7233

JustinGrote avatar Sep 09 '24 22:09 JustinGrote

yea showing a warning on import if someone isn't running utf8 would probably save a few people some headache.

I'm not sure changing someones codepage would be nice? there are some edge cases around WSL and similar that dont mix too well with UTF8.

But utf8 should just be the default one by now...

also at the point we could detect it Spectre has already set the profile..

and it does not appear to be entirely straightforward to force it to utf8 after the fact.. but i've only done some brief tests, maybe there is a way to get it to re-run "discovery".

right side has utf8 before import, just to show the profile image

trackd avatar Sep 09 '24 22:09 trackd

Yeah I'd say warning with a ENV variable or global setting to suppress it is probably the way to go.

JustinGrote avatar Sep 09 '24 22:09 JustinGrote

But utf8 should just be the default one by now...

I've been hoping windows terminal just bites the bullet and sets this. The annoying part is you need to include that snippet as the very first thing in the profile to avoid any other command generating output before setting the encoding settings.

When I've got some time to tinker I think I'll update the module to detect this and maybe offer something like these options on the first run:

  • Please update my profile with utf8 automatically
  • I'll update my profile manually
  • Leave my profile alone, I know I'm going to have a degraded experience

I avoided touching peoples encoding settings originally but it's kind of so odd to have to set up that it might be worth it.

ShaunLawrie avatar Sep 30 '24 07:09 ShaunLawrie

PS> pwsh -nop -c 'ipmo .\PwshSpectreConsole\PwshSpectreConsole\PwshSpectreConsole.psd1'
WARNING: Your session is currently using encoding 'OEM United States', this disables certain functionality as SpectreConsole requires UTF8 encoding, consider adding
        '$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()' to your $profile
        to suppress this warning set the environment variable '$env:IgnoreSpectreEncoding=$true'
        Note: this needs to be set before importing the module

this covers the basics atleast.

it'll be in once #50 is merged.

trackd avatar Oct 07 '24 21:10 trackd

It should spit out a pretty obvious warning now in prerelease...

image

ShaunLawrie avatar Nov 19 '24 10:11 ShaunLawrie