Laravel Tinker - Arrow keys not working in shell
Asked Answered
A

4

15

I'm getting started with a Laravel 5 project and trying to run some experiments using 'php artisan tinker' (psy shell), but I'm running into some weirdness. In the tinker/psy shell, pressing any of the arrow keys is printing character literals to the screen rather than performing the intended behaviour (move character for left and right, cycle recent commands for up and down).

Up is outputting ^[[A. Down is outputting ^[[B. Right is outputting ^[[C. Left is outputting ^[[D.

This is probably an issue with my terminal and not a Laravel bug. I am getting the same buggy behaviour when running php -a.

I am running terminal on OSX, with an xterm emulation.

Anneal answered 26/2, 2015 at 3:2 Comment(0)
A
39

The PHP REPL does not implement readline's line editing and history capabilities. I don't know if there's a PHP module that implements it, but you can do:

rlwrap php artisan tinker

You may have to install rlwrap for your OS.

Avis answered 26/2, 2015 at 3:35 Comment(3)
Thanks! that did appear to be my problem. There does appear to be a readline php library: php.net/manual/en/book.readline.php, though rlwrap is just too easy.Anneal
It works! I've installed rlwrap and started Tinker with rlwrap php artisan tinker. I can now use my directional arrows.Consentaneous
Thanks for the tip! For those wondering how to install rlwrap on OSX easily, just install Homebrew pasting the one liner in their homepage (brew.sh) and then type in the console: brew install rlwrapRelinquish
E
6

This is due to PHP not being built with readline support. You can enable this when you compile and build PHP with the --with-readline argument.

http://php.net/manual/en/features.commandline.interactive.php

Ephemera answered 18/5, 2016 at 18:38 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewStucco
Hi Mike. This solution is exactly how I fixed the arrow and backspace problem in Linux and OSX. The link was is to documentation supporting my answer. The problem is not psysh, it's lack of readline support in PHP. If you think this needs clarification, then what was unclear to you?Ephemera
Thank you, this was actually what I was looking for.Noddy
B
3

MY os: centos I solved the problem by :

sudo yum install rlwrap
alias tinker='rlwrap php artisan tinker'

Buccaneer answered 21/6, 2019 at 6:45 Comment(0)
E
2

In my case, I need install php7-readline

sudo zypper in php7-readline                                                       
[sudo] password for root: 
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  php7-readline

1 new package to install.
Overall download size: 64.0 KiB. Already cached: 0 B. After the operation, additional 30.9 KiB will be used.
Continue? [y/n/...? shows all options] (y): 
Retrieving package php7-readline-7.2.1-1.1.x86_64                                                                 (1/1),  64.0 KiB ( 30.9 KiB unpacked)
Retrieving: php7-readline-7.2.1-1.1.x86_64.rpm ......................................................................................[done (8.4 KiB/s)]
Checking for file conflicts: ....................................................................................................................[done]
(1/1) Installing: php7-readline-7.2.1-1.1.x86_64 ................................................................................................[done]
Epithet answered 23/1, 2018 at 5:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.