On 1/14/12 12:49 AM, Linda Walsh wrote: > /* vim: ts=1 sw=1 et sc fo=cqwa1 tw=78 syntax=css */ > There's actually 1 parts 2 this, I ran into the 2nd while testing the > first...
Like Greg Wooledge, I wasn't able to reproduce the second issue with `read -N 1' (which I assume is actually something like `read -e -N 1' from your description. > I wanted to be able to check the keyboard if the user had 'typed' ahead, > and mean to answer an upcoming question on purpose or if it was left over > from a previous > y/n single input response. > > I wanted to do a > read -t 0.01 pre_ans As Greg said, use `read -t 0'. > > Well -- it didn't return until the user pressed a key -- so even with a key > already > loaded, and a limit of 1, telling it to return upon 1 key in the buff, it > still > didn't return until it got the 2nd key. That's where you have a bad assumption: read -N 1 means to read exactly one character from the input. It doesn't exactly mean to return when there's one character loaded into the readline buffer, it means to read at least one character and return when you have at least one character in the buffer. If it didn't mean that, how could we allow the user to erase any default intput? If you wanted readline to return immediately if you had one or more characters preloaded, why would you call read that way in the first place? It doesn't add or change anything. By default, when using readline to obtain the line, we take characters from the beginning of the returned line buffer. If we want one character, we take the first one. If you want to experiment with skipping any pre-inserted text, try changing the value initializing `rlind'. You could use something like rlind = deftext && *deftext ? strlen (deftext) : 0; before the call to edit_line. Doing that leads to other questions, though. Say a user hits return when a character has been preloaded into the buffer. Should the code retrieve the key the user pressed, or the key in the line buffer? Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/