zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Heinz Deinhart <emperor@ei.ml.org>, zsh-users@math.gatech.edu
Subject: Re: completion & read, vared
Date: Mon, 13 Jul 1998 10:37:58 -0700	[thread overview]
Message-ID: <980713103758.ZM2098@candle.brasslantern.com> (raw)
In-Reply-To: <Pine.LNX.3.96.980713130345.869A-100000@io.ei.ml.org>

On Jul 13,  1:10pm, Heinz Deinhart wrote:
} Subject: completion & read, vared
}
}  is there a way to use completion with any realine-like function ?

Not directly; "read" inputs characters one at a time, for some reason,
even when not in raw mode.

} vared uses completion, but i cant figure out how to change its behaviour.

Change its behavior how?

Try the following; it should work exactly like the "read" builtin, except
that when reading in the "ordinary" way from a terminal, it uses vared to
provide access to completion and history.

Note that this means you can't end the loop with an EOF character (ctrl-D)
because vared doesn't interpret EOFs (it attempts completion instead).  So
you have to end the loop with an interrupt (ctrl-C), which in turn means
it's not possible to interrupt any surrounding script or function when the
vared is in progress.  (There's probably some bindkey foolery that would
fix this up.)

The cryptic "${${(M)1%%\?*}#\?}" is peeling off the ?PROMPT part of the
first NAME?PROMPT parameter (see the zsh doc for the "read" builtin).

    function zleread {
      emulate zsh
      setopt localoptions
      local input opt ropt n=0
      ropt=()
      while getopts :AEe opt
      do
	case $opt in
	[?]) read $*; return $?;;
	*) ropt=($ropt -$opt); ((++n));
	esac
      done
      if [[ -t 0 ]]
      then
        shift $n
        vared -hp "${${(M)1%%\?*}#\?}" input
        print -r $input | read $ropt ${1%%\?*} $*[2,-1]
	return $?
      fi
      read $*
    }

I did notice one oddity while playing with this.  From the PS1 prompt,

	read -eu0k1

reads a line from the terminal and echoes back the first character.
However, if instead I redirect input to read like so:

	repeat 3 print x y z | read -eu0k1

then nothing is read.  I have to use

	repeat 3 print x y z | read -eu0k 1

to get the desired behavior.  Why does the source of the input affect
the option parsing?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


  reply	other threads:[~1998-07-13 17:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-13 11:10 Heinz Deinhart
1998-07-13 17:37 ` Bart Schaefer [this message]
1998-07-13 18:19   ` Heinz Deinhart
1998-07-14  1:45     ` 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=980713103758.ZM2098@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=emperor@ei.ml.org \
    --cc=zsh-users@math.gatech.edu \
    /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).