List Info

Thread: note 78672 added to features.commandline




note 78672 added to features.commandline
user name
2007-10-22 16:11:45
I was looking for a way to interactively get a single
character response from user. Using STDIN with fread, fgets
and such will only work after pressing enter. So I came up
with this instead:

#!/usr/bin/php -q
<?php
function inKey($vals) {
	$inKey = "";
	While(!in_array($inKey,$vals)) {
		$inKey = trim(`read -s -n1 valu;echo $valu`);
	}
	return $inKey;
}
function echoAT($Row,$Col,$prompt="") {
	// Display prompt at specific screen coords
	echo
"33[".$Row.";".$Col."H".$pro
mpt;
}
	// Display prompt at position 10,10
	echoAT(10,10,"Opt : ");

	// Define acceptable responses
	$options =
array("1","2","3","4"
;,"X");

	// Get user response
	$key = inKey($options);

	// Display user response & exit
	echoAT(12,10,"Pressed : $keyn);
?>

Hope this helps someone.
----
Server IP: 208.69.120.35
Probable Submitter: 12.192.120.19
----
Manual Page -- http://www.php.net/manual/en/features.commandline.php
Edit        -- https://master
.php.net/note/edit/78672
Del: integrated  -- h
ttps://master.php.net/note/delete/78672/integrated
Del: useless     -- http
s://master.php.net/note/delete/78672/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78672/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78672/spam
Del: non-english -- 
https://master.php.net/note/delete/78672/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78672/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78672
Reject      -- https://mast
er.php.net/note/reject/78672
Search      -- https://
master.php.net/manage/user-notes.php

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


note 78672 modified in features.commandline by james
user name
2007-10-22 18:16:04
I was looking for a way to interactively get a single
character response from user. Using STDIN with fread, fgets
and such will only work after pressing enter. So I came up
with this instead:

#!/usr/bin/php -q
<?php
function inKey($vals) {
	$inKey = "";
	While(!in_array($inKey,$vals)) {
		$inKey = trim(`read -s -n1 valu;echo $valu`);
	}
	return $inKey;
}
function echoAT($Row,$Col,$prompt="") {
	// Display prompt at specific screen coords
	echo
"33[".$Row.";".$Col."H".$pro
mpt;
}
	// Display prompt at position 10,10
	echoAT(10,10,"Opt : ");

	// Define acceptable responses
	$options =
array("1","2","3","4"
;,"X");

	// Get user response
	$key = inKey($options);

	// Display user response & exit
	echoAT(12,10,"Pressed : $keyn");
?>

Hope this helps someone.

--was--
I was looking for a way to interactively get a single
character response from user. Using STDIN with fread, fgets
and such will only work after pressing enter. So I came up
with this instead:

#!/usr/bin/php -q
<?php
function inKey($vals) {
	$inKey = "";
	While(!in_array($inKey,$vals)) {
		$inKey = trim(`read -s -n1 valu;echo $valu`);
	}
	return $inKey;
}
function echoAT($Row,$Col,$prompt="") {
	// Display prompt at specific screen coords
	echo
"33[".$Row.";".$Col."H".$pro
mpt;
}
	// Display prompt at position 10,10
	echoAT(10,10,"Opt : ");

	// Define acceptable responses
	$options =
array("1","2","3","4"
;,"X");

	// Get user response
	$key = inKey($options);

	// Display user response & exit
	echoAT(12,10,"Pressed : $keyn);
?>

Hope this helps someone.

htt
p://php.net/manual/en/features.commandline.php

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


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )