note 73543 added to ref.readline
| From: | david at acz dot org | Date: | Wed, 28 Feb 2007 17:07:09 +0000 |
| Subject: | note 73543 added to ref.readline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123959@lists.php.net to get a copy of this message | ||
Readline only reads the window size on startup or on SIGWINCH. This means if the window is resized
when not in a readline() call, the next call will have odd behavior due to confusion about the
window size.
The work-around is to force Readline to re-read the window size by sending it SIGWINCH. This is
accomplished using the async interface, which installs the signal handler but returns control to
PHP.
The following function is a drop-in replacement for readline(), but re-reads the window size every
time:
<?
function xreadline($prompt)
{
global $xreadline, $xreadline_line;
$code = '$GLOBALS["xreadline"] = false;' .
'$GLOBALS["xreadline_line"] = $line;' .
'readline_callback_handler_remove();';
$cb = create_function('$line', $code);
readline_callback_handler_install($prompt, $cb);
$signal = defined("SIGWINCH") ? SIGWINCH : 28;
posix_kill(posix_getpid(), $signal);
$xreadline = true;
while ($xreadline)
readline_callback_read_char();
return is_null($xreadline_line) ? false : $xreadline_line;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 216.21.215.250
----
Manual Page -- http://www.php.net/manual/en/ref.readline.php
Edit -- https://master.php.net/note/edit/73543
Del: integrated -- https://master.php.net/note/delete/73543/integrated
Del: useless -- https://master.php.net/note/delete/73543/useless
Del: bad code -- https://master.php.net/note/delete/73543/bad+code
Del: spam -- https://master.php.net/note/delete/73543/spam
Del: non-english -- https://master.php.net/note/delete/73543/non-english
Del: in docs -- https://master.php.net/note/delete/73543/in+docs
Del: other reasons-- https://master.php.net/note/delete/73543
Reject -- https://master.php.net/note/reject/73543
Search -- https://master.php.net/manage/user-notes.php