spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Spinners not showing

Open LegendaryB opened this issue 3 years ago • 10 comments

Information

  • OS: Windows
  • Version: 10
  • Terminal: Windows CMD, Powershell

Describe the bug When using the spinner sample on the cmd or powershell I only get a bar displayed instead the dots.

To Reproduce Run the Spinner sample on windows

Expected behavior The dot spinner animation

Additional context I switched Spinner.Known.Default to Spinner.Known.Dot to make sure that it is really used.

LegendaryB avatar Apr 25 '21 12:04 LegendaryB

You will only get the dot spinner if the terminal is capable of showing Unicode characters and the output encoding is set to something like UTF-8.

patriksvensson avatar Apr 25 '21 13:04 patriksvensson

Thank you for the fast reply. Do you know if the Console supports unicode on windows?

I added this to set the Encoding to UTF-8: System.Console.OutputEncoding = Encoding.UTF8;

Edit: Seems like the font is the problem

LegendaryB avatar Apr 25 '21 13:04 LegendaryB

Yes it does. Try setting the encoding to UTF-8 and you should be able to see Unicode spinners.

[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

patriksvensson avatar Apr 25 '21 13:04 patriksvensson

I set both: System.Console.OutputEncoding = Encoding.UTF8; System.Console.InputEncoding = Encoding.UTF8;

But only get a question mark on the windows console. Probably because of the default font.

Edit: With the Windows Terminal it works as expected

LegendaryB avatar Apr 25 '21 13:04 LegendaryB

Also having this issue.

In Windows Terminal only the line spinner will show, unless I force UTF8 inside the project with System.Console.OutputEncoding = Encoding.UTF8; after forcing, dots spinner shows fine.

In regular Command Prompt, forcing adds an invalid character, like UTF8 isn't supported.

Perhaps there's an issue with UTF8 encoding detection? or maybe this is windows terminal adding UTF8 ontop of the command prompt itself.

Twinki14 avatar May 10 '21 15:05 Twinki14

The stdout encoding needs to be set to UTF-8 or UTF-16 to display UTF-8 characters. Try running dotnet example info and see what encoding is being used.

patriksvensson avatar May 10 '21 15:05 patriksvensson

Using Windows Terminal with a Command Prompt instance image

In command prompt itself image

Twinki14 avatar May 10 '21 15:05 Twinki14

@Twinki14 I can't reproduce the strange output in your second image. What do your console settings look like?

image

patriksvensson avatar May 10 '21 16:05 patriksvensson

I can reproduce the line break issue on my machine with main. I think I've chased it down and we'll get that fixed real soon.

But regarding the spinner - that seems like the default and desired behavior. For example, if you are overriding the encoding and getting a question mark when displaying, that to me indicates that the defaults capability detection did its job and we fell back to the safe renderer. From a library perspective, forcing the issue ourselves isn't going to be a great idea for exactly this reason. I.e. we need to make safe defaults so that y'all as developers don't get issues asking why your spinner has question marks from users not using Windows Terminal.

phil-scott-78 avatar May 10 '21 20:05 phil-scott-78

I can reproduce the line break issue on my machine with main. I think I've chased it down and we'll get that fixed real soon.

But regarding the spinner - that seems like the default and desired behavior. For example, if you are overriding the encoding and getting a question mark when displaying, that to me indicates that the defaults capability detection did its job and we fell back to the safe renderer. From a library perspective, forcing the issue ourselves isn't going to be a great idea for exactly this reason. I.e. we need to make safe defaults so that y'all as developers don't get issues asking why your spinner has question marks from users not using Windows Terminal.

Regarding the spinner, after running the info example it appears to be acting just as intended. I think the confusion here is that for running a command prompt instance, inside of/with Windows Terminal, there's support for utf8 that doesn't appear to be detected by spectre.console, but i'm also not sure if there's a way you could detect that.

I'm guessing Windows Terminal has it's own utf8 support, but only "on-top" / the way it wraps of the underlying command prompt instance.

Twinki14 avatar May 11 '21 12:05 Twinki14

This work for me:

  1. Open cmd -> Properties -> font -> font-style = Cascadia Mono
  2. Add this code:
System.Console.OutputEncoding = Encoding.UTF8;
System.Console.InputEncoding = Encoding.UTF8;

behnamasaei avatar Oct 07 '22 09:10 behnamasaei

This work for me:

1. Open cmd -> Properties -> font -> font-style = Cascadia Mono

2. Add this code:
System.Console.OutputEncoding = Encoding.UTF8;
System.Console.InputEncoding = Encoding.UTF8;

I can confirm this approach works here too

IanDavidJensen avatar Mar 21 '23 12:03 IanDavidJensen

I'm going ahead and close this issue. The main problem has been resolved (as described in https://github.com/spectreconsole/spectre.console/issues/391#issuecomment-1271332735) by

  • ensuring Encoding has been set to UTF-8
  • using a font that can show the spinners.

If someone feels this does not resolve the initial issue, do not hesitate to open a new issue.

nils-a avatar Dec 26 '23 21:12 nils-a

Hey,

i have the same issue, but with .net 8.0, which nativly support UTF-8. Setting is the same like in issue https://github.com/spectreconsole/spectre.console/issues/113 Same code worked with previous dotnet versions just perfect.

lengschder97 avatar Jan 31 '24 06:01 lengschder97

@lengschder97 This has nothing to do with .NET, but the output encoding of the terminal you're using.

patriksvensson avatar Jan 31 '24 10:01 patriksvensson