How to restore terminal after curses program crashes?
Eric Peterson
epeterso at houligan.encore.com
Sat Feb 16 06:58:50 AEST 1991
pawel at cs.UAlberta.CA (Pawel Gburzynski) writes:
| From article <1991Feb13.133332.22320 at ousrvr.oulu.fi>, by clegg at 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 at 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.
More information about the Comp.unix.questions
mailing list