Bug #73292 [Com]: readline_info returns empty/old line_buffer info

From: Date: Wed, 29 Aug 2018 06:02:55 +0000
Subject: Bug #73292 [Com]: readline_info returns empty/old line_buffer info
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216776@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73292&edit=1 ID: 73292 Comment by: thflori at gmail dot com Reported by: me at xbug dot de Summary: readline_info returns empty/old line_buffer info Status: Assigned Type: Bug Package: Readline related Operating System: Debian PHP Version: 5.6.26 Assigned To: remi Block user comment: N Private report: N New Comment: I can confirm that the behaviour with editline wrapper completely differs from lib readline. I tried it on win 8.1 with php7.1 and 7.2; Alpine Linux 3.6 with php 7.1 and Arch with php 7.2. The only one that is working "correct" is Arch with 7.2 and the difference is clearly editline vs readline 7.0. Previous Comments: ------------------------------------------------------------------------ [2016-10-12 08:20:23] me at xbug dot de Just to give the wanted information about php and libreadline. Every php version I tested was installed from the official repository. And it seems that the ubuntu, mint and debian version uses libedit2. Ubuntu 14.04: libedit2 (3.1-20130712-2) Debian Jessie: libedit2 (3.1-20140620-2 and others) Linux Mint 18: libedit2 (3.1-20150325-1ubuntu2) ------------------------------------------------------------------------ [2016-10-12 07:54:02] me at xbug dot de Your are right, $input works like expected. But I want to go one step further and make an autocomplete for the arguments of commands. Therefore I need the whole current line to get the first word, which is the command. And this seems not be possible with the $input arg of the function, which always just contains the current underling word. For example the Shell class of the symfony console component uses the readline_info() this way, too. (https://github.com/symfony/console/blob/2.7/Shell.php#L168) ------------------------------------------------------------------------ [2016-10-12 06:52:18] remi@php.net I don't understand why you want to use readline_info() output instead of $input, which contains the pending input, and works as expected. <?php readline_completion_function( function ($input) { $words = ['albert', 'alfred', 'bob', 'remi', 'foo']; $ret = []; foreach($words as $word) { if ($input == substr($word, 0, strlen($input))) { $ret[] = $word; } } return $ret; } ); while (readline('cmd: ')); ------------------------------------------------------------------------ [2016-10-12 03:19:10] pollita@php.net There's two substantive (and likely causative) changes in the Readline extension between PHP 5.4 and PHP 5.5 (there are none between 5.5 and 5.6). https://github.com/php/php-src/commit/31d67bd35362c1ab570caccedfec3e24257b55c5 https://github.com/php/php-src/commit/b8d88bf2c588dcaec185468da8db306cd7e6ab8d Could you clarify two things: 1) Do you have libreadline or libedit installed on your system? 2) Did you compile ext/readline against libedit or libreadline? (Or did you install from stock Debian Jesse package?) In the mean time, assigning to Remi since both those commits are his. ------------------------------------------------------------------------ [2016-10-11 15:03:33] me at xbug dot de Description: ------------ Under php5.4 (ubuntu 14.04) the function readline_info returned the correct values. But since (possible 5.5) php5.6 (debian jessie) it returns empty and sometimes old values. I've tested it also under php7.0 (Mint) and the behaviour is the same as in php5.6. Test script: --------------- <?php readline_completion_function( function ($input) { $info = readline_info(); $text = substr($info['line_buffer'], 0, $info['end']); var_dump($info); if ($info['point'] !== $info['end']) { return []; } // task name? if (false === strpos($text, ' ') || !$text) { return ['one', 'three']; } // This is never called since php 5.6 $cmd = substr($text, 0, strpos($text, ' ')); if ($cmd === 'one') { return ['two']; } elseif ($cmd === 'three') { return ['four']; } return []; } ); while (true) { readline('cmd: '); } Expected result: ---------------- $ php readline.php cmd: onearray(6) { ["line_buffer"]=> string(3) "one" ["point"]=> int(3) ["end"]=> int(3) ["library_version"]=> string(16) "EditLine wrapper" ["readline_name"]=> string(0) "" ["attempted_completion_over"]=> int(0) } Actual result: -------------- $ php readline.php cmd: onearray(6) { ["line_buffer"]=> string(0) "" ["point"]=> int(3) ["end"]=> int(3) ["library_version"]=> string(16) "EditLine wrapper" ["readline_name"]=> string(0) "" ["attempted_completion_over"]=> int(0) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73292&edit=1

« previous php.bugs (#216776) next »