I normally consider console-based captive interfaces "evil", though once in a while they're quite useful (Debian's debfoster tool comes to mind). As such, I haven't really dealt with this issue before. Yesterday, however, I found myself writing something with a captive interface as glue for a set of separate tools and utilities because I was tired of having to rethink what I'm doing every time I want to download a YouTube video (yes, really). I do so rarely enough that the series of steps I generally take isn't cemented in my mind, but commonly enough that it's still annoying to have to remind myself every time.
The wall I've run into is in answering yes or no to questions. To make this script really slick, I want to take a y/n/Enter keystroke as input, and not have to use the Enter key as a cue that input is done when entering either a y or n answer. Single-keystroke input is what I'm after.
The caveat is that I don't want to use an entire module that isn't part of the core Perl distribution, either. Thus, Term::Readkey doesn't seem to be the answer I seek. I also don't want to have to rely on system-specific shell commands, however -- I want to do it with Perl, not with bash or tcsh.
This doesn't seem like the sort of thing that should be terribly difficult, but I'm having a lot of trouble figuring out how it can be accomplished. Am I missing some global variable that, set to an empty string, would solve the endline requirement for input from STDIN? Is there a core function, or a function in a core module, that can be fit into this round hole?
Is there simply no way to do it without going outside the core Perl distribution (or reproducing a significant chunk of Term::Readkey)?
|
- apotheon
CopyWrite Chad Perrin |
In reply to y/n input in a captive interface by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |