Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompting doesn't support arrow keys #996

Closed
danielbachhuber opened this issue Feb 6, 2014 · 8 comments
Closed

Prompting doesn't support arrow keys #996

danielbachhuber opened this issue Feb 6, 2014 · 8 comments

Comments

@danielbachhuber
Copy link
Member

Trying to go to the beginning of the field instead produces unexpected characters:

image

Might be a problem upstream.

@scribu
Copy link
Member

scribu commented Feb 6, 2014

Requires the readline library.

@rodrigoprimo
Copy link
Contributor

@scribu I have php5-readline installed but I can't use the arrow keys as well. Is anything else necessary?

@scribu
Copy link
Member

scribu commented Sep 21, 2014

Run php -i | grep -A2 readline to make sure.

@rodrigoprimo
Copy link
Contributor

$ php -i | grep -A2 readline
/etc/php5/cli/conf.d/20-readline.ini,
/etc/php5/cli/conf.d/20-xdebug.ini

--
readline

Readline Support => enabled

@danielbachhuber
Copy link
Member Author

@rodrigoprimo I'm still of the mind this is an application-level problem. Haven't had time to dive into it further.

@rodrigoprimo
Copy link
Contributor

I think I found the source of the problem. Turns out php-cli-tools is not using using readline(), it uses fgets(STDIN) instead:

https://github.com/wp-cli/php-cli-tools/blob/master/lib/cli/Streams.php#L130

The following seem to fix this issue:

diff --git a/lib/cli/Streams.php b/lib/cli/Streams.php
index b750636..081a6bd 100755
--- a/lib/cli/Streams.php
+++ b/lib/cli/Streams.php
@@ -126,6 +126,8 @@ class Streams {

                if( $format ) {
                        fscanf( static::$in, $format . "\n", $line );
+               } else if ( function_exists( 'readline' ) ) {
+                       $line = readline();
                } else {
                        $line = fgets( static::$in );
                }

But another problem is created, if you use the left arrow to go to the beginning of what you typed, the cursor goes to the beginning of the line, before the question presented to the user. I think this happens because readline() expects the question as a parameter. So we will need to change that as well.

@danielbachhuber
Copy link
Member Author

@rodrigoprimo can you file an issue in php-cli-tools?

@rodrigoprimo
Copy link
Contributor

Sure: wp-cli/php-cli-tools#72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants