zsh-users
 help / color / mirror / code / Atom feed
* unget a character
@ 2013-02-05 15:23 rahul
  2013-02-06  2:33 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: rahul @ 2013-02-05 15:23 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

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.

thx, rahul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unget a character
  2013-02-05 15:23 unget a character rahul
@ 2013-02-06  2:33 ` Bart Schaefer
  2013-02-06  5:03   ` rahul
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2013-02-06  2:33 UTC (permalink / raw)
  To: Zsh Users

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.)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unget a character
  2013-02-06  2:33 ` Bart Schaefer
@ 2013-02-06  5:03   ` rahul
  0 siblings, 0 replies; 3+ messages in thread
From: rahul @ 2013-02-06  5:03 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

On Wed, Feb 6, 2013 at 8:03 AM, Bart Schaefer <schaefer@brasslantern.com>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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-06  7:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-05 15:23 unget a character rahul
2013-02-06  2:33 ` Bart Schaefer
2013-02-06  5:03   ` rahul

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).