in reply to y/n input in a captive interface
However, if you are unable to do that you probably have to go with changing terminal settings by hand. I copied a recipe out of the 2nd edition Camel Book a long, long time ago and I haven't used it in years. It may give you a start though so here it is.
# RawTerm.pm # # Adapted from "Programming PERL", Wall/Christiansen/Schwartz, 2nd Edn +. pp.474 # package RawTerm; use Exporter; @ISA = ('Exporter'); @EXPORT = ('getone'); BEGIN { use POSIX qw(:termios_h); my($term, $oterm, $echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON; $noecho = $oterm & ~$echo; sub cbreak { $term->setlflag($noecho); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); } sub getone { my $key = ""; cbreak(); sysread(STDIN, $key, 1); cooked(); return $key; } } END { cooked(); } 1;
If I remember correctly you just call the getone() subroutine to get a single character without needing the <Enter> key. I hope this is of use.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: y/n input in a captive interface
by apotheon (Deacon) on Feb 08, 2007 at 05:04 UTC |