laravel / prompts

Beautiful and user-friendly forms for your command-line PHP applications.
https://laravel.com/docs/prompts
MIT License
533 stars 94 forks source link

Artisan arrow keys don't work #62

Closed maPer77 closed 1 year ago

maPer77 commented 1 year ago

Laravel Prompts Version

latest

Laravel Version

10.22.0

PHP Version

8.2.10

Operating System & Version

Windows 10

Terminal Application

PowerShell with SSH command

Description

The right and left keys do not work to select the option. "^[[D" appears for the left key and "^[[C" for the right key, it is not possible to select the desired option.

WindowsTerminal_F2tZgpvOyn

Steps To Reproduce

maPer77 commented 1 year ago

image image

jessarcher commented 1 year ago

Hi @maPer77,

Just to be clear, are you SSHing into a Linux machine before running php artisan migrate?

Prompts don't currently work on Windows due to platform limitations, so we configure Prompts in Laravel to fall back to Symfony prompts. If you are SSH'd into a Linux machine, the current platform detection will detect Linux and not fall back. The platform limitations relate to how we can control the terminal's behaviour using the stty command. From your screenshot, it looks like the stty exists in your environment, but it has failed, which will prevent Prompts from being able to intercept your key presses. This may be due to using a Windows terminal, but I'm not sure.

I will try to replicate the above scenario and see whether I can either fix it, or update the fallback behaviour.

In the meantime, you can configure additional scenarios when Prompts fall back using the fallbackWhen method in the boot method of your AppServiceProvider.php file. In your case, you may want to configure Prompts to always fall back when your application is in production:

\Laravel\Prompts\Prompt::fallbackWhen(app()->isProduction());

Or you can always fall back:

\Laravel\Prompts\Prompt::fallbackWhen(true);
maPer77 commented 1 year ago

Hi @jessarcher, Thanks for the answer. Yes, I'm connecting SSH to a Linux machine.

utsavsomaiya commented 1 year ago

May be stty mode set at that time ssh permission required.

sudo stty -icanon -isig -echo

Then

stty -g

@jessarcher ?

maPer77 commented 1 year ago

Hi @utsavsomaiya

I believe what is happening is that I am connected to shared hosting, I do not have permission for some things, it seems that one of those things is 'stty'.

image

This resolved it very well: \Laravel\Prompts\Prompt::fallbackWhen(true);

Thank you all.

maPer77 commented 1 year ago

The ideal would be for 'Prompt' to identify that 'stty' cannot be loaded and switch to fallback automatically. I don't know if this would be possible, it would prevent other people from having this same problem.

utsavsomaiya commented 1 year ago

Can you please run in your ssh above given command using sudo?

maPer77 commented 1 year ago

Somehow this is implemented, maybe it needs some more checks.

image

maPer77 commented 1 year ago

Can you please run in your ssh above given command using sudo?

image

jessarcher commented 1 year ago

I have a branch that will automatically trigger the fallback when the stty command fails. Will push it up soon.