Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colours not working in Windows #6

Closed
RubyBit opened this issue Aug 29, 2022 · 14 comments · Fixed by #7
Closed

Colours not working in Windows #6

RubyBit opened this issue Aug 29, 2022 · 14 comments · Fixed by #7
Assignees
Labels
bug Something isn't working

Comments

@RubyBit
Copy link

RubyBit commented Aug 29, 2022

Describe the bug
In a Windows command line terminal, colours are not correctly displayed, instead random letters and symbols are (which I assume is the supposed syntax for the colour). This seems to be a problem with the colored crate but I would suggest to at least when using the None option for the colours to add no such syntax at all and just the spinner with the text (looking on how its done in the source code).

To Reproduce
Steps to reproduce the behavior:

  1. Create any spinner with any color (includine the None option)
  2. Open the created binary on a windows command line terminal (not the new Windows Terminal)
  3. See error

Expected behavior
A colour should be displayed (again, probably an error with the colored crate)

Desktop:

  • OS: Windows

Additional info
This might not be able to be fixed by you (see above with the colored crate) but I like your crate so the suggested fix would be nice, so I can use the spinners without the colours :)

@RubyBit
Copy link
Author

RubyBit commented Aug 29, 2022

This might be interesting (was looking through the colored crate issues), seems to include a possible fix for at least windows 10 with the control::set_virtual_terminal function.
colored-rs/colored#59

@ad4mx
Copy link
Owner

ad4mx commented Aug 30, 2022

Hi, I'm going to fix it as soon as I can.

@ad4mx ad4mx self-assigned this Aug 31, 2022
@ad4mx ad4mx linked a pull request Aug 31, 2022 that will close this issue
@ad4mx
Copy link
Owner

ad4mx commented Aug 31, 2022

Hi @RubyBit, could you please run #7's branch's examples locally to tell me if anything changed? I want to see if I still can use the colored crate or if I should switch.

@ad4mx ad4mx added the bug Something isn't working label Aug 31, 2022
@RubyBit
Copy link
Author

RubyBit commented Sep 1, 2022

I tested it and normal (without colour) mode works nicely but the problem persists with coloured text. Testing it with the set_virtual_terminal function, the colours as well as symbols are correctly displayed!

image

I also want to mention as I failed to mention this in the bug report, this happens when a console is allocated(through AllocConsole) to my process (which doesnt have one), and the white colour could not be displayed for some reason (I tested with the white colour in a normal command prompt project and it worked fine). Nevertheless, set_virtual_terminal adds full functionality for all colours and symbols at both cases.

@ad4mx
Copy link
Owner

ad4mx commented Sep 1, 2022

I'm happy that it works now. I reckon I could include set_virtual_terminal in the code as an OS specific thing so the user doesn't have to bother with it?

@RubyBit
Copy link
Author

RubyBit commented Sep 1, 2022

Yes that would be nice and I believe easily implemented with a conditional statement using the cfg! macro. I think it is quite important here as it allows for not only colours but every symbol to be properly displayed in a windows command line prompt (thus the crate works as intended in windows).

@ad4mx
Copy link
Owner

ad4mx commented Sep 2, 2022

Right, should be added to the branch now. Could you just verify for the last time that it works without explicitly setting the virtual terminal like before?

@ad4mx
Copy link
Owner

ad4mx commented Sep 2, 2022

After that, it should be ready for a merge.

@RubyBit
Copy link
Author

RubyBit commented Sep 3, 2022

Everything seems to work but I am not sure if the branch will compile in other OSes as you use a conditional compiled function in a function which is compiled on all OSes ( I have added a comment on the code with a potential fix)

@ad4mx
Copy link
Owner

ad4mx commented Sep 3, 2022

Right, That seems to be an issue. Where did you add your comment? I can't see it anywhere.

@RubyBit
Copy link
Author

RubyBit commented Sep 3, 2022

If you go to the pull request, it is there. I was just saying to immediately set control::set_virtual_terminal(true) if the cfg! conditional is true without referring to the conditional function (thus removing the build error)

@ad4mx
Copy link
Owner

ad4mx commented Sep 6, 2022

Setting it directly in the cfg! conditional doesn't actually seem to do anything since the set_virtual_terminal function is target_os limited by default so our build environment (ubuntu) won't be able to find it.

@ad4mx
Copy link
Owner

ad4mx commented Sep 6, 2022

To me, it looks like unfortunately the user will have to set it themselves. I could, however include a note in the readme so users won't get confused.

@RubyBit
Copy link
Author

RubyBit commented Sep 6, 2022

Yes that should work and be quite straight forward.

@ad4mx ad4mx closed this as completed in #7 Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants