|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-10-11 15:03 UTC] 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)
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 07:00:01 2025 UTC |
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: '));