[comp.unix.questions] cbreak mode

sho@tybalt.caltech.edu (Sho Kuwamoto) (01/13/87)

	I tried using cbreak mode for the first time today,
and just like all other things, I failed miserably on my
first attempt.  Since I was already using curses in my program,
I first used the curses functions cbreak() and nocbreak().
After debugging, I found that the program

#include <stdio.h>
#include <curses.h>

main()
{
   cbreak();
   nocbreak();
}

would leave the machine in cbreak mode.  Furthermore, I
wrote my own routines to set and unset cbreak mode using
ioctl() and had the same result.  Am I just being a twit,
or and I lodged firmly in the Twilight Zone(TM)?  By the
way, our system runs 4.3bsd.

				Thanx

				-Sho

					

abs@nbc1.UUCP (Andrew Siegel) (01/15/87)

> ... I found that the program
> 
> #include <stdio.h>
> #include <curses.h>
> 
> main()
> {
>    cbreak();
>    nocbreak();
> }
> 
> would leave the machine in cbreak mode.  Furthermore, I
> wrote my own routines to set and unset cbreak mode using
> ioctl() and had the same result.

If you're using curses, you must begin your program with a call to
initscr(), and terminate it with endwin().  The endwin() call returns
the tty parameters to their original setting.

Good luck.
-- 
Andrew Siegel, N2CN		NBC Computer Imaging, New York, NY
philabs!nbc1!abs		(212)664-5776

neil@sunybcs.UUCP (01/26/87)

In article <194@nbc1.UUCP> abs@nbc1.UUCP (Andrew Siegel) writes:
>> ... I found that the program
>> 
>> #include <stdio.h>
>> #include <curses.h>
>> 
>> main()
>> {
>>    cbreak();
>>    nocbreak();
>> }
>> 
>> would leave the machine in cbreak mode.  
>If you're using curses, you must begin your program with a call to
>initscr(), and terminate it with endwin().  The endwin() call returns
>the tty parameters to their original setting.

The function initscr() needs to be called before screen and window
functions only.  cbreak() and nocbreak() are not screen or window
functions so it shouldn't have to be called.  Calling endwin() does
call resetty() which does restore the terminal settings but nocbreak()
should take the terminal out of cbreak mode.  As far as why this
doesn't work...  I dunno;  I have found problems like this before with
curses and terminal modes and have managed to avoid them but never fix
them.

				Neil



Neil Smithline				CSnet:  neil@buffalo
ARPA:	neil.buffalo@rand-relay		Bitnet: NEIL@SUNYBCS
uucp:   {decvax!watmath}
        {pur-ee!rocks34!rocksvax}
        {{allegra, seismo}!rochester!rocksvax} !sunybcs!neil