diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2009-08-24 18:11:53 -0400 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2009-08-24 18:11:53 -0400 |
commit | af539291187b159b4c7ddab791536f59193c21ea (patch) | |
tree | 9fcdb563f89e5d27896a9830c57f95f9660b4869 /etc/inc/util.inc | |
parent | fcf168cb8958954606ab7b079e6cac96056aac2f (diff) | |
parent | 0f3d0ad79b7d31bbc1677f8e10486d03ad598af7 (diff) | |
download | pfsense-af539291187b159b4c7ddab791536f59193c21ea.zip pfsense-af539291187b159b4c7ddab791536f59193c21ea.tar.gz |
Merge branch 'master' of git://rcs.pfsense.org/pfsense/techneck-auto_interface into review/master
Conflicts:
etc/inc/config.inc
Diffstat (limited to 'etc/inc/util.inc')
-rw-r--r-- | etc/inc/util.inc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc index a829fc7..c289d62 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -971,5 +971,29 @@ function isAjax() { return isset ($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; } +/****f* util/timeout + * NAME + * timeout - console input with timeout countdown. Note: erases 2 char of screen for timer. Leave space. + * INPUTS + * optional, seconds to wait before timeout. Default 9 seconds. + * RESULT + * returns 1 char of user input or null if no input. + ******/ + +function timeout($timer = 9) { + while(!isset($key)) { + if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; } + else { echo chr(8). "{$timer}"; } + `/bin/stty -icanon min 0 time 25`; + $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`); + `/bin/stty icanon`; + if ($key == '') + unset($key); + $timer--; + if ($timer == 0) + break; + } + return $key; +} ?> |