PhpStorm terminal : Cygwin colors does not work

梦想的初衷 提交于 2019-12-06 08:05:43

Adding second answer to provide an alternative solution to my original answer.

ANSICON Support

First download and install ANSICON

  • Extract the windows binary files (x86 or x64 directory contents) into your $PATH (D:\wamp\bin\php\php7.0.0)
  • Optionally run ansicon -i from a Windows Command Prompt to allow you to use ANSICON to add ansi color support to the Windows Command Prompt.

Next you need to wrap ANSICON for the PHPStorm terminal

"X:\path\to\ansicon.exe" -p "C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe

NOTE: Using -l or --login, as stated in the original answer, will add /usr/bin and /usr/local/bin to your $PATH and cause the terminal to use the Cygwin PHP installation making ANSICON unneeded.

Next in your ~/.bashrc file you will need to add at the bottom of the file.

export ANSICON=true

You can easily append the line by running the following command from a Cygwin terminal.

echo export ANSICON=true >> ~/.bashrc

This will ensure Symfony will find the ANSICON environment variable with a different Windows Version.

Next restart PHPStorm and open the terminal to test it out.

You need to add the -l switch to your terminal path.

Before adding the switch:

The full path should be

"C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe -l

or

"C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe --login

Be sure to close the currently opened terminal window by clicking the red X in the upper left of the terminal dialog and reopen it.

Now running the command again it should look like:

See man bash within the Cygwin terminal for more information.


UPDATE

Based on your comment about your WAMP installation. You'll need to install PHP in Cygwin for it to run correctly, which will allow the use of the posix line of functions and emulate a Linux distribution for your PHP environment. Which is generally why Cygwin is used.

How are you intending to use Cygwin with PHP?

The issue is that Cygwin is using the Windows PHP executable and the Symfony Console Component StreamOutput is detecting it as a Windows instance of PHP and and not Cygwin/Linux in order to use posix_isatty.

Here is an example of the code Symfony Console uses to render color output to the terminal.

if ('\\' === DIRECTORY_SEPARATOR) {
    static::$defaultColors = @(
        0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
        || false !== getenv('ANSICON')
        || 'ON' === getenv('ConEmuANSI')
        || 'xterm' === getenv('TERM')
    );
} elseif (function_exists('posix_isatty')) {
    $h = stream_get_meta_data($this->outputStream) + array('wrapper_type' => null);
    $h = 'Output' === $h['stream_type'] && 'PHP' === $h['wrapper_type'] ? fopen('php://stdout', 'wb') : $this->outputStream;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!