24

I have no idea why but my Git Bash terminal is showing 34m and random numbers in places. Here's a screenshot. enter image description here

Thanks for any help.

Phillip Y.
  • 517
  • 5
  • 18
  • 1
    I'm not 100% sure, but you need to change terminal color mode to 256-color. This will fix your output. – Noproblem Nov 05 '15 at 06:44
  • ^^ I don't think so. `32m`, `34;4m` are available in 8 bit palette as well... & looking at OP's `PS1`, 8 bit palette seems to be working. – anishsane Nov 05 '15 at 07:44
  • The only thing that has worked for me (I tried the ANSICON solution too) was appending `--no-ansi` to my `php artisan` commands. To save typing, I edited my .profile file to include `alias artisan="php artisan --no-ansi"`. With this I can type commands such as `artisan storage:link` without getting any funny business in the output. – Michael Novello Oct 27 '19 at 09:41
  • 1
    The only solution that has worked for me is to install version 2.10.1. You can find this release by searching explicitly. – Mycodingproject Oct 31 '19 at 13:37

8 Answers8

15

Try changing Git Bash options for terminal to xterm-256color. Credit goes to: http://www.techhelp.pw/git-bash-using-laravel-artisan-displays-escaped-characters/

Placid
  • 1,400
  • 3
  • 22
  • 33
9

Another option is to run the Laravel scripts with the --no-ansi switch, which disables the ANSI codes altogether.

Pieter van den Ham
  • 4,381
  • 3
  • 26
  • 41
  • 2
    This has been the only solution that has worked for me. I've tried the whole color out put several different ways but it doesn't wanna work. I'm on a Windows10 machine. Thanks Pete! – cbloss793 Sep 08 '17 at 19:35
9

None of the solutions listed have worked for me, adding these lines in Git/etc/bash.bashrc solved the problem.

# remove the winpty PHP aliases
unalias $(alias | grep winpty | grep php | cut -d"=" -f1 | cut -d" " -f2)

# support ansi color
export ANSICON=true

I have found the solution at https://blog.kmelia.net/testing/coloration-dans-git-bash/123

I'm using git bash for windows on Windows 10, my git version is 2.21.0

Hope this helps

Maxime Dezette
  • 126
  • 1
  • 5
  • 1
    This works for me on windows 10 + git 2.23. All else fails – yespbs Oct 29 '19 at 08:13
  • This php alias (`alias php='winpty php.exe'`) that comes with Git Bash on Windows explains why the colors work when composer calls commands with [`@php`](https://getcomposer.org/doc/articles/scripts.md#executing-php-scripts) (which references the currently running php) but the same commands don't have colors when called manually from a terminal. Related: https://github.com/git-for-windows/git/issues/519 – Travis Britz Nov 06 '19 at 06:45
  • Worked for me on win 10 + git 2.24. 'xterm-256color' did nothing. – Shafiq al-Shaar Nov 08 '19 at 13:09
4

It seems like color codes that are not shown correctly:

[34m is blue foreground and [39m is default foreground color.

But you will need a prefixed escape character:

In Bash, the <Esc> character can be obtained with the following syntaxes:

  • \e
  • \033
  • \x1B

See more here: http://misc.flogisoft.com/bash/tip_colors_and_formatting


The same problem is also discussed here: ANSI color escape sequences seem broken for arc in git bash on windows

Basically there are mentioned to hackish fixes:

php artisan tinker | cat 
php artisan tinker | echo -e

A few other resource:

ANSI color in git is not displayed correctly
In Git Bash on Windows 7, Colors display as code when running Cucumber or rspec

Community
  • 1
  • 1
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
  • There is more to it than this. Way more, because *the OP has a configuration problem, not a code problem*. PsySH uses these codes, rendering this answer moot. See: https://github.com/JakubOnderka/PHP-Console-Color/blob/master/src/JakubOnderka/PhpConsoleColor/ConsoleColor.php#L276 – Amelia Nov 05 '15 at 09:17
  • @Amelia This is correct, I simply comment this for information to give OP some tools to continue hems search. But because this doesn't render good as a comment i decided to post as an answer. – Andreas Louv Nov 05 '15 at 10:01
  • This issue is actually a pretty common one, and it stems from the fact that git-bash masquerades as cygwin (which understands color codes) but its native programs (echo, cat, ls, etc) all translate colors into something understandable by cmd.exe (which doesn't understand color codes). Kudos on the update, too. – Amelia Nov 05 '15 at 10:18
  • 1
    @andlrc If I try `php artisan tinker | cat` or `php artisan tinker | echo -e` I've got `output is not a tty` – zhekaus Aug 31 '16 at 07:13
1

To Resolve Color issues Download and install this https://github.com/adoxa/ansicon

Steps for Installation:

1)Extract The folder and Navigate to x86/64 (Depends upon your system)
2)Open Cmd
3)ansicon.exe -I

Simple :)

1

It's a GIT version compatibility issue.
In my case, remove the latest version and download and install the GIT version 2.10. problem solved. https://github.com/git-for-windows/git/releases/tag/v2.10.0.windows.1

Ikram Ud Daula
  • 1,213
  • 14
  • 21
0

This is a known issue, you should revert the symfony console version

https://github.com/laravel/framework/issues/30216

composer require symfony/console:4.3.4

For more information follow the ticket on the symfony github repo: https://github.com/symfony/symfony/issues/33915

Got my information here: https://laracasts.com/discuss/channels/laravel/php-artisan-not-working-4

ArneDB
  • 33
  • 6
0

only updating the Symfony packages with this command -> composer update symfony/*