问题
I have PhpStorm 2016.2 and I added Cygwin in the Shell path as follow : "C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe
It's working well, but the colors do not work.
For exemple I have ?[32m Name
instead of having Name
colored in green.
I tried several things like adding the plugin Grep Console to have the support of ANSI Color, but didn't work.
It's really hard to work with lines with multiple ANSI colors ?[39m ?[32m Scheme ?[39m ?[32m Host ?[39m ?[32m Path
.
Do not hesitate to ask further information about the problem. Thank you.
P.S. I'm on Windows 10.
EDIT
when I do /usr/bin/which php
in PHPStorm terminal I get /cygdrive/d/wamp2/bin/php/php5.6.16/php
. I have php5.6.16 and php7.0.0 in my WAMP and I'm currently using php7.0.0.
EDIT 2 I added a $PATH for php7.0.0 so now I have /cygdrive/d/wamp2/bin/php/php7.0.0/php
when I do /usr/bin/which php
. But the main problem remains.
回答1:
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 useANSICON
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.
回答2:
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;
}
来源:https://stackoverflow.com/questions/38437960/phpstorm-terminal-cygwin-colors-does-not-work