Skip to content

Problem with colors in console for generators on Win10 #4043

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

Open
Cosolom opened this issue Apr 15, 2019 · 17 comments
Open

Problem with colors in console for generators on Win10 #4043

Cosolom opened this issue Apr 15, 2019 · 17 comments

Comments

@Cosolom
Copy link

Cosolom commented Apr 15, 2019

Describe the bug
When I run drush commands in console - i get uncolored pieces with extra symbols.
screenshot
This is cmder console in phpstorm. If I use conemu/cmder direct in folder (outside phpstorm) - no problem with colors.

System Configuration

Q A
Drush version 9.6.2
Drupal version 8.x
PHP version 7.2
OS Windows
@greg-1-anderson
Copy link
Member

To better isolate the bug, try vendor/bin/drush --version from the project root of your Drupal site and see if that produces better results.

@Cosolom
Copy link
Author

Cosolom commented Apr 15, 2019

Result the same
изображение

@weitzman
Copy link
Member

Not sure whats going on. It is symfony console that prints the text where those symbols are showing.

@Cosolom
Copy link
Author

Cosolom commented Apr 23, 2019

Maybe this issue not directly for drush, because this I have when use drupal console:
изображение
You can see that part of strings colored and part with bad format.

@Cosolom
Copy link
Author

Cosolom commented Mar 10, 2021

Problem still exists. And very insteresting thing that Drupal Console and Drush use the same Symfony Output Formatter class, but result is different. Here is example when I added debug string to the \Symfony\Component\Console\Formatter\OutputFormatter::format method
изображение

@Cosolom
Copy link
Author

Cosolom commented Mar 10, 2021

I found where is problem.
If I comment in \Drush\Config\Environment::calculateColumns next line
exec('stty size 2>&1', $columns_output, $columns_status);
then messages printed without issues

@Cosolom
Copy link
Author

Cosolom commented Mar 10, 2021

It works only for command:
vendor\drush\drush\drush.bat
I still have broken colors with Drush Launcher

@greg-1-anderson
Copy link
Member

Thanks for tracking this down. A PR to skip the call to stty size when running under Windows would be welcome.

@weitzman
Copy link
Member

We already attempt a fallback for Windows so I'm not sure what the best way is to mitigate this issue. Suggestions welcome. See function below:

https://github.com/drush-ops/drush/blob/10.x/src/Config/Environment.php#L444-L482

@Cosolom
Copy link
Author

Cosolom commented Mar 13, 2021

I can run "stty size 2>&1" in command line without any issue, but with this line in drush I'm losing coloring. I can guess that problem in one of:

  1. exec
  2. stty
  3. my local environment

This issue appear in command window which launched with command:
"C:\Windows\System32\cmd.exe" /k ""c:\cmder\vendor\init.bat""
If I run drush directly in cmder/conemu - I do not have this issue.

@Cosolom
Copy link
Author

Cosolom commented Mar 14, 2021

Unfortunately, commenting out stty does not solve all of the issue :( . For example, "generate condition" command only first part displayed without issues
изображение

@weitzman
Copy link
Member

generate is a very unusual command as it builds its own Application. If we can fix this for all other parts of drush first I think that makes sense. Can you change exec() to \Drush\Drush::shell() and see if anything improves?

@weitzman
Copy link
Member

Well we'll have to change how we use its return code as well.

@weitzman
Copy link
Member

@Cosolom If you have time, I propose a fix at #4688. You could hack your drush by hand if you dont want to deal with Composer. All changes are in one method.

@Cosolom
Copy link
Author

Cosolom commented Mar 17, 2021

Thank you @weitzman It works. But generators (not all) still have issues. I can investigate it when I will have time. But in any case thank you all. Now I can work more comfortably :)

@weitzman
Copy link
Member

Reopening for generators

@weitzman weitzman reopened this Mar 17, 2021
@weitzman weitzman changed the title Problem with colors in console on Win10 Problem with colors in console for generators on Win10 Mar 17, 2021
@Cosolom
Copy link
Author

Cosolom commented Apr 27, 2021

I found source of problem in generators. This is still the same "stty". But now it's in \Symfony\Component\Console\Terminal::hasSttyAvailable method. This method is called in \Symfony\Component\Console\Helper\QuestionHelper::doAsk. I'm not sure how is the best way to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants