Re: [PHP] stdin buffering

2004-09-09 Thread Marek Kilimajer
Martin Holm wrote:
I'm currently working on some stuff with php-cli and got a few problem.
I want to be able to read one single character from stdin via keyboard, 
ie. pressing a button.
It works fine if I use enter as newline afterwards, but I would like to 
do it without pressing enter.
Thus, I have to turn off buffering in the input stream but I can't find 
any way to do it.

Been looking everywhere on php.net but can't find any hints.
http://www.php.net/ncurses
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] stdin buffering

2004-09-09 Thread Greg Donald
On Thu, 2004-09-09 at 14:10, Martin Holm wrote:
 I'm currently working on some stuff with php-cli and got a few problem.
 
 I want to be able to read one single character from stdin via keyboard, 
 ie. pressing a button.
 It works fine if I use enter as newline afterwards, but I would like to 
 do it without pressing enter.
 Thus, I have to turn off buffering in the input stream but I can't find 
 any way to do it.
 
 Been looking everywhere on php.net but can't find any hints.

I have never been able to find a way to disable STDIN buffering in PHP.

You may find ncurses_getch() of use however.

http://www.php.net/ncurses_getch


-- 
Greg Donald

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stdin buffering

2004-09-09 Thread Jim Grill
 On Thu, 2004-09-09 at 14:10, Martin Holm wrote:
  I'm currently working on some stuff with php-cli and got a few problem.
 
  I want to be able to read one single character from stdin via keyboard,
  ie. pressing a button.
  It works fine if I use enter as newline afterwards, but I would like to
  do it without pressing enter.
  Thus, I have to turn off buffering in the input stream but I can't find
  any way to do it.
 
  Been looking everywhere on php.net but can't find any hints.

 I have never been able to find a way to disable STDIN buffering in PHP.

 You may find ncurses_getch() of use however.

 http://www.php.net/ncurses_getch


 -- 
 Greg Donald

I'm not sure how great this solution is but here it is anyway:

exec(stty -icanon min 0 time 0);

The -icanon turns of canonical reading of stdin. The min has to do with
the minimum characters needed for a read to be complete while time sets
the read timeout (0 means no timeout and no minimum characters).

You can also turn off echo if you don't need the user to see what they type:

exec(stty -icanon -echo min 0 time 0);

If you do this and run your script it will affect your terminal. If you
happen to turn echo off just hit Ctrl c (to clear any invisible commands)
and type (blindly) stty echo to turn it back on. To see the current
terminal options do stty or stty -a to see everything. man stty is
just as much fun. :-)

Good luck,

Jim Grill

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stdin buffering

2004-09-09 Thread Greg Donald
On Thu, 2004-09-09 at 15:25, Jim Grill wrote:
 exec(stty -icanon min 0 time 0);

Nice.

I suspect 'phpSnake' will appear on freshmeat in a couple days.

:)


-- 
Greg Donald

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stdin buffering

2004-09-09 Thread Martin Holm
Greg Donald wrote:
On Thu, 2004-09-09 at 15:25, Jim Grill wrote:
 

exec(stty -icanon min 0 time 0);
   

Nice.
I suspect 'phpSnake' will appear on freshmeat in a couple days.
:)
 

thats more or less what we are trying to do. =)
pong as a start at least.
doing it all over again, this time php-style.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php