lichess-bot-devs / lichess-bot

A bridge between Lichess bots and chess engines
GNU Affero General Public License v3.0
745 stars 440 forks source link

Text color garbled after game finishes, when on verbose mode #539

Closed fabriciodosanjossilva closed 2 years ago

fabriciodosanjossilva commented 2 years ago

When using verbose mode (python lichess-bot.py -v), lichess-bot displays debug text lines, using different colors to differentiate different info. When game finishes, there is an incorrect change to default text color, leading to incorrect colored text from then on. Sometimes text color turns to dark blue, which makes text unreadable. Restarting is the only solution.

In the attached image, the default white text turns into cyan. Red arrows show incorrect color.

It seems that some color control code is set, but not unset. wrong text color

MarkZH commented 2 years ago

We discussed this problem in PR #506. It seems like CMD and PowerShell cannot handle logging messages from multiple threads without mashing messages together. However, Windows Terminal seems to have fixed this problem. Try installing that and tell us if that fixes the problem.

fabriciodosanjossilva commented 2 years ago

I tested in Windows Terminal. It worked fine. I did not have the text color issue.

If this is a known limitation of PowerShell and CMD, and it seems that it is not worth to make lichess-bot work with these terminals, then leave it that way and you may close this Github issue.

Thanks!

MarkZH commented 2 years ago

I don't know if it's a limitation of PowerShell/CMD or of the colorizing library we're using (Rich). I may file a bug report with the Rich library at some point in the future.

MarkZH commented 2 years ago

Note towards a possible solution:

The function detect_legacy_windows() in rich.console returns False for cmd.exe within windows terminal and True for cmd.exe for cmd.exe without. Maybe give the RichHandler a Console instance which should automatically detect whether a legacy terminal is needed (or use the detect function explicitly).

MarkZH commented 2 years ago

That didn't work, so I'm all out of ideas. I guess the solution to this is to use Windows Terminal.

fabriciodosanjossilva commented 2 years ago

I'm using Windows Terminal for a few days. It works fine.

Keep lichess-bot unchanged. I suggest to put a note in the instructions (README.md) mentioning that is advised to use Windows Terminal in order to avoid text formating issues.

MarkZH commented 1 year ago

This should be fixed with PRs #777 and #800.