note 71157 added to function.ncurses-getch
| From: | petrathrochdotinfo at osu1 dot php dot net | Date: | Tue, 14 Nov 2006 10:11:25 +0000 |
| Subject: | note 71157 added to function.ncurses-getch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119712@lists.php.net to get a copy of this message | ||
While function ncurses_nodelay() is still not implemented and if you need a non-blocking getch,
following code might help.
$init = ncurses_init();
$full = ncurses_newwin (0,0,0,0);
ncurses_wborder($full,0,0,0,0,0,0,0,0);
ncurses_wrefresh($full);
$running = true;
$fp = fopen("php://stdin","r"); //open direct input stream for reading
stream_set_blocking($fp,0); //set non-blocking mode
while ($running) {
while (($buf = fgets($fp, 4096)) != false) { //fgets is required if we want to handle escape
sequenced keys
$buffer .= $buf;
}
if ($buffer != "") {
switch ($buffer) {
case " ": { //exit on space key
ncurses_end();
exit;
}
default: {
ncurses_mvwaddstr($full,2,2,"$buffer"); //display input
}
}
$buffer = ""; //empty buffer
}
// You can do something interesting here, while we're not waiting for an input
ncurses_mvwaddstr($full,4,4,microtime(true));
ncurses_wrefresh($full);
usleep(1); //reduce cpu usage
}
----
Server IP: 66.163.161.117
Probable Submitter: 80.187.222.51
----
Manual Page -- http://www.php.net/manual/en/function.ncurses-getch.php
Edit -- https://master.php.net/note/edit/71157
Del: integrated -- https://master.php.net/note/delete/71157/integrated
Del: useless -- https://master.php.net/note/delete/71157/useless
Del: bad code -- https://master.php.net/note/delete/71157/bad+code
Del: spam -- https://master.php.net/note/delete/71157/spam
Del: non-english -- https://master.php.net/note/delete/71157/non-english
Del: in docs -- https://master.php.net/note/delete/71157/in+docs
Del: other reasons-- https://master.php.net/note/delete/71157
Reject -- https://master.php.net/note/reject/71157
Search -- https://master.php.net/manage/user-notes.php