Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unget a character



On Wed, Feb 6, 2013 at 8:03 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>wrote:

> On Feb 5,  8:53pm, rahul wrote:
> }
> } How can i unget a character (taken in by read -k).
> }
> } It would help me if i could unget a char in one part of my app, so it
> will
> } be available in the main loop.
>
> If you are talking about an interactive shell reading input with ZLE, you
> can do it with "zle -U".
>
> If you're in some other way reading from a stream such as standard input,
> unget is not possible.  You need a lower-level programming language with
> more direct control over things like stdio buffers.  (Unget is not an OS-
> level operation, it's implemented in stdio or the equivalent.)
>


I am writing a shell program that uses "read -k" to get keys in a loop (I
have not yet got into zle). It branches off into functions and I wanted to
get a char in one function, and then reject it if it was not correct, so
the main loop could use it.

After asking this question, I realized I could do this programmatically, by
setting the unwanted key to a variable. The main loop would first check the
variable and use that value , if blank it could do a "read".

-- 
 rahul


Messages sorted by: Reverse Date, Date, Thread, Author