How can I detect waiting characters in a curses application ?

Sam Christie samc at ntpdvp1.UUCP
Thu Dec 6 10:54:23 AEST 1990


Would some kind sole tell me the name of the curses function
which checks for input without blocking ? If none exists, then please
read on and help me create one.

I am using Interactive's 386/IX 2.0.2 on a Dell 386.  My application
uses curses for a terminal based user interface.  Using the application,
the user may request that the program perform an operation which takes
considerable time.  Users, being prone to errors as they are, may wish
to abort the operation by pressing the "stop-doing-that,I-didnt-mean-that"
key.  The code is in a loop and could easily test for such a user request.

Something like :

while( !done) {
	/* do a bunch of stuff */

	if ( istypeahead( stdscr)) {   /* <==== what should this say */
		if ( KEY_F(8) == getch( )) break;
	}
}

I wrote an istypeahead function as:

istypeahead()
{
	int i, j, c;

	i =  fcntl( 0, F_GETFL );
	fcntl( 0, F_SETFL, i | O_NDELAY );
	c = getchar();                         /* didn't use getch() here because */
											  I don't know how to ungetch() */
	fcntl( 0, F_SETFL, i & ( ~O_NDELAY ));
	if( EOF == c) return( 0);
	ungetc( c, stdin);
	return( 1);
}

This seems to detect typeahead ok, but curses seems to be lost regarding 
the keys.  I suspect it has something to do with curses' internal buffering.
(I doubt curses uses getchar() or the buffers associated with fopen() )

Any hints ?

-- 
Sam Christie                            Standard Disclaimer Applies
Northern Telecom - DMS-10
Research Triangle Park, NC
EMAIL ...!uunet!mcnc!rti!ntpdvp1!samc                  919/992-3917



More information about the Comp.unix.programmer mailing list