laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.32k stars 130 forks source link

Tinker lost colors #127

Closed Jervi-sir closed 3 years ago

Jervi-sir commented 3 years ago

Description:

Tinker is not using colors, all the text is white only, this issue happened when I installed a latest version of Laravel ( 8.47.0 ), I went to try some oldest versions of Laravel ( 8.46.0 and older ) tinker worked fine, text was colored fine, what should we do?

Steps To Reproduce The Issue:

It happens whenever we create a fresh Laravel project with composer

composer create-project laravel/laravel .

Samples

cmd

cmder

driesvints commented 3 years ago

Please provide a way for us to reproduce this.

bobthecow commented 3 years ago

Which PsySH version is working for you, and which is not?

Jervi-sir commented 3 years ago

@driesvints, for me it happens when ever I create a fresh Laravel project via composer, my excuses for not providing more info

Jervi-sir commented 3 years ago

@bobthecow, so far Psy Shell v0.10.8, I edited the report, please check it

bobthecow commented 3 years ago

What does running psy\info() inside tinker output in both cases?

driesvints commented 3 years ago

@bobthecow thanks for helping out here 👍

Jervi-sir commented 3 years ago

@bobthecow, Untitled

Jervi-sir commented 3 years ago

@bobthecow,, want to update you, I found a file in "vendor/psy/psysh/src/configuration.php" where a line was

const COLOR_MODE_DISABLED = 'disabled';

is it a good way to turn it into 'auto' too

bobthecow commented 3 years ago

I believe this issue is https://github.com/symfony/symfony/pull/41723, though not for any of the reasons already listed on that issue.

PsySH (and thus Tinker) treats --ansi / --no-ansi as a three-state pair of options: either you specify explicitly that you want color, or explicitly don't, or the app decides for you.

As of the latest Symfony, the built-in --ansi option is defined as "negatable". So if you don't explicitly specify --ansi, it acts like you've implicitly specified --no-ansi. So when PsySH tries to figure out whether you want color or not, the latest Symfony lies and says you don't.

One additional complication, though: Symfony Console, itself, doesn't parse those options that way, despite defining them that way. So I'm pretty convinced this is a bug in the default --ansi option definition, and we shouldn't be using negatable like this.

Anyway, it looks like that change will be reverted until Symfony 6.0 because it also caused backwards compatibility breaks (as it did for us), so we can fight that fight later 😛

In the meantime, specifying --color or --ansi to force the color on should work!

driesvints commented 3 years ago

Seems like this is also a result of https://github.com/symfony/symfony/pull/39642? Anyway, thanks for investigating this @bobthecow.

GrahamCampbell commented 3 years ago

Cool. So this will be fixed in the next round of patch releases to the symfony console component?

driesvints commented 3 years ago

@GrahamCampbell the PR @bobthecow linked to isn't merged yet.

niladam commented 3 years ago

Since this is now closed, while i personally think it should be open while we keep track of it and until it gets fixed here's a simple quickfix for people encountering this. Simply run tinker like this:

php artisan tinker --ansi - this forces the color output :)

codecapsules commented 3 years ago

@bobthecow,, want to update you, I found a file in "vendor/psy/psysh/src/configuration.php" where a line was

const COLOR_MODE_DISABLED = 'disabled';

is it a good way to turn it into 'auto' too

Thanks work like a charm !

bobthecow commented 3 years ago

Wait, are you saying you edited that file in your vendor folder?

GrahamCampbell commented 3 years ago

:trollface:

boyet007 commented 3 years ago

it works @niladam Thank you

tiagofrancafernandes commented 2 years ago

@bobthecow,, want to update you, I found a file in "vendor/psy/psysh/src/configuration.php" where a line was

const COLOR_MODE_DISABLED = 'disabled';

is it a good way to turn it into 'auto' too

Thanks! Some change now (2021)

vendor/psy/psysh/src/Configuration.php:37