Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ncar!hsdndev!husc6!encore!houligan!epeterso From: epeterso@houligan.encore.com (Eric Peterson) Newsgroups: comp.unix.questions Subject: Re: How to restore terminal after curses program crashes? Message-ID: Date: 15 Feb 91 19:58:50 GMT References: <1991Feb13.133332.22320@ousrvr.oulu.fi> <1991Feb13.191442.16443@cs.UAlberta.CA> Sender: news@Encore.COM Reply-To: epeterson@encore.com (Eric Peterson) Organization: Encore Computer Corporation, Diagnostic Development Lines: 50 Nntp-Posting-Host: houligan.encore.com News-Software: NN 6.4.12 pawel@cs.UAlberta.CA (Pawel Gburzynski) writes: | From article <1991Feb13.133332.22320@ousrvr.oulu.fi>, by clegg@tolsun.oulu.fi (Matthew Tran Clegg/VTT): | > I've been working on a program that uses the curses package and | > cbreak mode. Once in a while, a bug will cause the program to | > crash (for example, with a segmentation fault). This completely | > unhinges the terminal. It won't respond to anything anymore, | > except if I press ^C, then the csh prompt will be printed. | > | > Does anyone know how to restore the terminal to a sane state? | > So far, the only thing that has worked for me is the power switch :-). There are three things that Curses programs typically do -- disable character echoing, allow only a newline (^J) to be used as the end-of-line character, and disable backspace, interrupt, and kill character processing. To return your terminal to sanity, you have to undo these three things, which can be done with the command: % stty echo -nl -cbreak^J The 'echo' argument turns on echoing, '-nl' disables the exclusive use of a newline as a line terminator, and '-cbreak' enables special key processing. And you must terminate the line with a ^J instead of Enter (^M). | How about 'tset ^j' (^j stands for control j). Not everyone has 'tset' though. But it can do the same thing. However, 'tset' is a much more powerful command than that, as it can return your terminal name, termcap entry, and all sorts of other good stuff. Some systems have a command called 'reset' which will do a 'stty echo -nl -cbreak'. But again, not everyone has this. Some implementations of 'stty' also allow you to say 'stty sane' to return the terminal to a standard state. All of the stty parameters are reset, including your erase, kill, and interrupt keys. | Generally, it is a bad habit | for a program using curses to crash without regaining control for resetting | the terminal. Generally, it is a bad habit for any program to crash ever :-) Eric -- Eric Peterson <> epeterson@encore.com <> uunet!encore!epeterson Encore Computer Corp. * Ft. Lauderdale, Florida * (305) 587-2900 x 5208 Why did Constantinople get the works? Gung'f abobql'f ohfvarff ohg gur Ghexf.