zsh-users
 help / color / mirror / code / Atom feed
* Implementing a menu (list) in a zsh script (as in command line)
@ 2012-12-31  5:29 rahul
  2012-12-31 11:00 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: rahul @ 2012-12-31  5:29 UTC (permalink / raw)
  To: zsh-users

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

I am writing an application in zsh. I typically use read -k or vared for
getting user input. However, I'd like the user to get a menu as he types or
tabs, just as it happens on the zsh command line. I'd like him to be able
to navigate the menu just as on the command line.

Currently, I've implemented this in some cases using read -k and displaying
the data again with each keystroke and the user has to type in the row
number to finally select a row. However, user cannot navigate. I'd like to
use zsh's inbuilt facilities if possible rather than reimplement.

Also in the case of using vared, I am unable to give any options (although
if it happens to be a path, then vared does allow tabbing and completion).

I did see an application that does implement something similar called
"zaw". It seems to use "zle" but I was lost reading the code. "man zle"
hasn't helped much and I could not find any simple tutorial or examples.

Also, using "read -k" can one accept control characters and arrow keys ? It
seems I would have to do multiple reads?

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

* Re: Implementing a menu (list) in a zsh script (as in command line)
  2012-12-31  5:29 Implementing a menu (list) in a zsh script (as in command line) rahul
@ 2012-12-31 11:00 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2012-12-31 11:00 UTC (permalink / raw)
  To: rahul; +Cc: zsh-users

rahul wrote:
> I am writing an application in zsh. I typically use read -k or vared for
> getting user input. However, I'd like the user to get a menu as he types or
> tabs, just as it happens on the zsh command line. I'd like him to be able
> to navigate the menu just as on the command line.

With vared, you should be able to configure a function that does
completion for your script by declaring it with zle -C:

zle -C complete-word complete-word _complete
bindkey '^I' complete-word

Looking at a script I have that does this, my _complete function starts
with:

_complete() {
  [[ "$compstate[insert]" = tab* ]] &&
      compstate[insert]="${compstate[insert]//tab /}"

I think this ensures that it does completion rather than inserting a tab
character in some cases.

You may need other tweaking, much of which may involve copying from your
.zshrc to, for example, setup menu completion as you like it loading the
complist module and so on.

The completion functions may also look a bit different to normal
completion functions if you do things like descriptions manually, e.g.
  compadd -X '%Bnames%b'

Oliver


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

end of thread, other threads:[~2012-12-31 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-31  5:29 Implementing a menu (list) in a zsh script (as in command line) rahul
2012-12-31 11:00 ` Oliver Kiddle

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