zsh-users
 help / color / mirror / code / Atom feed
From: rahul <rahul2012@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: unget a character
Date: Wed, 6 Feb 2013 10:33:09 +0530	[thread overview]
Message-ID: <CACQNQ9NJBR-m7JenqSr4Yc=F=ZtbcbXpMz8OWWYiJszkutQrPQ@mail.gmail.com> (raw)
In-Reply-To: <130205183313.ZM28561@torch.brasslantern.com>

[-- 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

      reply	other threads:[~2013-02-06  7:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-05 15:23 rahul
2013-02-06  2:33 ` Bart Schaefer
2013-02-06  5:03   ` rahul [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACQNQ9NJBR-m7JenqSr4Yc=F=ZtbcbXpMz8OWWYiJszkutQrPQ@mail.gmail.com' \
    --to=rahul2012@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).