Reputation: 3552
When using laravel artisan commands, I don't get the expected color output.
If you look at http://laravel.com/docs/4.2/commands , it says "To send output to the console, you may use the info, comment, question and error methods. Each of these methods will use the appropriate ANSI colors for their purpose."
But using terminals mintty or cmd, I don't get those colors.
For instance, $this->error('Something went wrong!');
should output the text with a red background.
What is missing so that I get this color functionality ?
Upvotes: 2
Views: 4296
Reputation: 113
Reference from symfony/console: 2.*|3.*|4.*
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - Windows before 10.0.10586 without Ansicon, ConEmu or Mintty
* - non tty consoles
*
* @return bool true if the stream supports colorization, false otherwise
*/
protected function hasColorSupport()
{
if (DIRECTORY_SEPARATOR === '\\') {
return
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');
}
return function_exists('posix_isatty') && @posix_isatty($this->stream);
}
If you using ternimal in a linux/macos client, you need install and enable php_posix
extention to make posix_isatty()
available in remote server.
$ yum install php-process
If you using window, the value of DIRECTORY_SEPARATOR
is \\
. Martin's
answer should work because getenv('ANSICON')
will return ture.
Upvotes: 0
Reputation: 6674
I know it's an old answer, but the other answers here aren't really SO quality
As you've discovered, the native Windows command line doesn't support ANSI colors. Here you can find another SO answer with more details and useful links, but here is a crucial excerpt:
ANSI.SYS also works in NT-derived systems for 16-bit legacy programs executing under the NTVDM.
The Win32 console does not natively support ANSI escape sequences at all. Software such as Ansicon can however act as a wrapper around the standard Win32 console and add support for ANSI escape sequences.
As mentioned in the excerpt, the software Ansicon is used to add support for ANSI colors to windows terminals. I haven't used it, but it seems to add functionality to existing consoles.
ANSICON provides ANSI escape sequences for Windows console programs. It provides much the same functionality as ANSI.SYS does for MS-DOS.
That said, you seem to need to run the ansicon
command when you want ANSI color coding:
For example, to display file.ans using black on cyan as the default color:
ansicon -m30 -t file.ans
As you can see it supports ANSI colors, but it also has many other neat features built-in. It emulates some Unix functionality, too.
Cmder is by far my personal favorite.
Upvotes: 3
Reputation: 84
That's a magic of terminal on linux. that why i love linux. just for fun. Because you use windows. As default, cmd only have black and white. you can use ansicon to show command color. In my case, i use git bash for run laravel command. it also shows color.
Upvotes: -1