zsh-users
 help / color / mirror / code / Atom feed
From: "Marc Cornellà" <hello@mcornella.com>
To: zsh-users@zsh.org
Subject: Detect typed input without swallowing characters
Date: Thu, 10 Feb 2022 22:21:44 +0100	[thread overview]
Message-ID: <CACn48Nq5hW0u9PhrTPSGOZjvohArKpVoXrGsryEM+jQpwfS-zg@mail.gmail.com> (raw)

Hi,

in Oh My Zsh we want to detect whether the user has typed characters
before showing the prompt to auto-update, so that if they have, to
skip it entirely and get them to the prompt as fast as possible.

The current solution is to detect whether there's input with `read -t
-k 1`, but this solution has the downside of swallowing one character.

I've been looking at sysread and zselect to poll stdin (fd 0), but I
believe they only tell whether stdin is ready for reading, not whether
it holds any data. These are the commands I'm using by the way:

    sysread -t 0 -i 0
    zselect -t 0 -r 0

Is there any way to do this or should I give up entirely?

Thanks!
Marc


             reply	other threads:[~2022-02-10 21:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 21:21 Marc Cornellà [this message]
2022-02-11  0:04 ` Philippe Troin
2022-02-11  9:08   ` Marc Cornellà
2022-02-11 16:15     ` Philippe Troin
2022-02-11 19:08     ` Bart Schaefer

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=CACn48Nq5hW0u9PhrTPSGOZjvohArKpVoXrGsryEM+jQpwfS-zg@mail.gmail.com \
    --to=hello@mcornella.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).