Need help w/unbuff'd input.

Charles Hannum hannum at chopin.psu.edu
Sat Jun 9 10:32:17 AEST 1990


What you need to do is set 'cbreak' mode on your tty.  This tells the tty
driver not to do line editing.  Here's what to do:

  When you want to start character-by-character input:

    #include <sys/ioctl.h>
    #include <sgtty.h>

    struct sgttyb otty, ntty;

    /* emacs-insert-whatever-code-here */

    ioctl(stdin, TIOCGETP, &otty);
    ntty=otty;
    ntty.sg_flags |= CBREAK;
    /* Use the following line if you *don't* want it to echo: */
    /* ntty.sg_flags &= ~ECHO; */
    ioctl(stdin, TIOCSETP, &ntty);

    /* emacs-insert-more-code-here */

  Then, to set the terminal back to its previous mode:

    ioctl(stdin, TIOCSETP, &otty);

  MAKE SURE YOU DO THIS!  If you don't set the tty back to the correct mode,
  you will have no line editing (and if you turned off echo, no echo either),
  which makes life very miserable.  (tcsh sets the mode back automatically,
  BTW, but csh does not.)

NOTE:  This only works on ttys, not sockets or other types of files.
--
 
Virtually,
Charles Martin Hannum		 "Those who say a thing cannot be done should
Please send mail to:		  under no circumstances stand in the way of
hannum at schubert.psu.edu		  he who is doing it." - a misquote



More information about the Comp.lang.c mailing list