home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5309 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  3.9 KB

  1. Path: sparky!uunet!autodesk!dansmith
  2. From: dansmith@Autodesk.COM (Daniel Smith)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Curses like menu in a bourne shell script
  5. Message-ID: <18340@autodesk.COM>
  6. Date: 8 Jan 93 02:37:41 GMT
  7. References: <38155@uflorida.cis.ufl.edu> <kimcm.726436445@login.dkuug.dk>
  8. Organization: Autodesk Inc., Sausalito CA, USA
  9. Lines: 87
  10.  
  11. In <kimcm.726436445@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:
  12.  
  13. > pm0@bale.cis.ufl.edu (Patrick Martin) writes:
  14.  
  15. > >I wish to create a bourne shell menu which will read the cursor
  16. > >keys and scroll a highlighted bar across a list of menu items.
  17. > >I wish for return on a menu item to select that menu item.
  18.  
  19. > That will be a problem, since the shell does not have general I/O
  20. > routines, and what is required is a routine to read
  21. > character-by-character, and determine if the "string" sent by the
  22. > cursor keys, have been manually entered or entered by the key. This is
  23. > best done i a c-program.
  24.  
  25.     Just so happens I wrote something applicable to getting
  26. individual keystrokes...but it won't help for arrow keys or curses...
  27.  
  28.     "grabchars" allows you to get one or more characters directly
  29. from the user.  I've used it to write csh menuing scripts.  I posted
  30. it to comp.sources.misc long ago (version 1.95), so you can find
  31. it in those archives.  You can also get it directly from me.
  32.  
  33.     It mostly supports BSD and some SYS V platforms.  I plan
  34. on doing a 2.0 which allows polling (and in fact, I have that working
  35. on the Sun), but it's shelved at the moment while I try to squeeze in
  36. work on SoftList.
  37.  
  38.     I don't support function/arrow keys, yet.  I mention
  39. it here as a means of implementing a simpler type of menu (where
  40. the user types in letters).  One such menu looks like:
  41.  
  42.  
  43.                 Lookup/Edit Menu
  44.  
  45.                 ?       help
  46.  
  47.         1 data files total
  48.  
  49.         Search by:              Actions:
  50.  
  51.         d       date            a       add
  52.         f       filer           c       config/change dir
  53.         g       globally        e       edit
  54.         i       id num (crc)    p       print
  55.         l       location        r       reset patterns
  56.         m       media           v       view
  57.         n       name
  58.  
  59.         your choice >> 
  60.  
  61.  
  62.     As for curses, no, grabchars just lets you do things such as:
  63.  
  64. grabchars -q 'end of add menu help...press any key...'
  65. set choice=`grabchars -L -q "'y' to create, anything else exits >> " | cat -v`
  66. set cur_year=`grabchars -b -c'[0-9]' -n 2 -d $cur_year -r`
  67.  
  68. usage: grabchars                gets one keystroke
  69.         -b                      output to stdout and stderr
  70.         -c<valid characters>    only <valid chars> are returned
  71.         -d<char(s)>             default char or string to return
  72.         -e                      output to stderr instead of stdout
  73.         -f                      flush any previous input before reading
  74.         -h                      help screen
  75.         -n<number>              number of characters to read
  76.         -p<prompt>              prompt to help user
  77.         -q<prompt>              prompt to help user (through stderr)
  78.         -r                      RETURN key exits (use with -n)
  79.         -s                      silent, just return status
  80.         -t<seconds>             timeout after <seconds>
  81.         -E                      honor erase/kill characters
  82.         -U/-L                   upper/lower case mapping on input
  83. grabchars -c aeiou              get one of the vowels
  84. grabchars -c i                  get the letter 'i'
  85. grabchars '-penter a letter '   print the prompt "enter a letter "
  86. grabchars -n4                   get four characters
  87. grabchars -t2                   timeout after two seconds
  88.  
  89. print a prompt and grab three characters...
  90. grabchars -p 'enter three characters >> ' -n 3
  91.  
  92.                 Daniel
  93.  
  94.  
  95. -- 
  96.  dansmith@autodesk.com       daniel@world.std.com       dansmith@well.sf.ca.us
  97.         Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
  98.