From: dansmith@Autodesk.COM (Daniel Smith)
Newsgroups: comp.unix.shell
Subject: Re: Curses like menu in a bourne shell script
Date: 8 Jan 93 02:37:41 GMT
Organization: Autodesk Inc., Sausalito CA, USA

In <kimcm.726436445@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:

> pm0@bale.cis.ufl.edu (Patrick Martin) writes:

> >I wish to create a bourne shell menu which will read the cursor
> >keys and scroll a highlighted bar across a list of menu items.
> >I wish for return on a menu item to select that menu item.

> That will be a problem, since the shell does not have general I/O
> routines, and what is required is a routine to read
> character-by-character, and determine if the "string" sent by the
> cursor keys, have been manually entered or entered by the key. This is
> best done i a c-program.

	Just so happens I wrote something applicable to getting
individual keystrokes...but it won't help for arrow keys or curses...

	"grabchars" allows you to get one or more characters directly
from the user.  I've used it to write csh menuing scripts.  I posted
it to comp.sources.misc long ago (version 1.95), so you can find
it in those archives.  You can also get it directly from me.

	It mostly supports BSD and some SYS V platforms.  I plan
on doing a 2.0 which allows polling (and in fact, I have that working
on the Sun), but it's shelved at the moment while I try to squeeze in
work on SoftList.

	I don't support function/arrow keys, yet.  I mention
it here as a means of implementing a simpler type of menu (where
the user types in letters).  One such menu looks like:

 
                Lookup/Edit Menu
 
                ?       help
 
        1 data files total
 
        Search by:              Actions:
 
        d       date            a       add
        f       filer           c       config/change dir
        g       globally        e       edit
        i       id num (crc)    p       print
        l       location        r       reset patterns
        m       media           v       view
        n       name
 
        your choice >> 
 

	As for curses, no, grabchars just lets you do things such as:

grabchars -q 'end of add menu help...press any key...'
set choice=`grabchars -L -q "'y' to create, anything else exits >> " | cat -v`
set cur_year=`grabchars -b -c'[0-9]' -n 2 -d $cur_year -r`

usage: grabchars                gets one keystroke
        -b                      output to stdout and stderr
        -c<valid characters>    only <valid chars> are returned
        -d<char(s)>             default char or string to return
        -e                      output to stderr instead of stdout
        -f                      flush any previous input before reading
        -h                      help screen
        -n<number>              number of characters to read
        -p<prompt>              prompt to help user
        -q<prompt>              prompt to help user (through stderr)
        -r                      RETURN key exits (use with -n)
        -s                      silent, just return status
        -t<seconds>             timeout after <seconds>
        -E                      honor erase/kill characters
        -U/-L                   upper/lower case mapping on input
grabchars -c aeiou              get one of the vowels
grabchars -c i                  get the letter 'i'
grabchars '-penter a letter '   print the prompt "enter a letter "
grabchars -n4                   get four characters
grabchars -t2                   timeout after two seconds
 
print a prompt and grab three characters...
grabchars -p 'enter three characters >> ' -n 3

				Daniel


-- 
 dansmith@autodesk.com       daniel@world.std.com       dansmith@well.sf.ca.us
        Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
Newsgroups: comp.unix.shell