Newsgroups: can.usrgroup
Path: utzoo!telly!tmsoft!uucp
From: telly!moore!telly!cain!darcy
Message-ID: <1989Aug9.191534.19268@tmsoft.uucp>
To: telly!moore!unix-unanimous
Sender: uucp@tmsoft.uucp (Now THATs a Daemon)
Original-To: can-usrgroup@tmsoft.UUCP (Mailing list injector)
Reply-To: telly!moore!telly!cain!darcy
Organization: /usr/group/cdn
Distribution: ont
Date: Wed, 9 Aug 89 19:15:34 GMT


/*

Are there any curses gurus out there who can help me with this
problem?  

The following code is designed to do the following:

	accept input in a box at the bottom of the screen implementing
	word wrap.  Each line (terminated by a CR or by reaching the
	maximum number of characters) is displayed above the box.

	If nothing is typed for 5 seconds, a timeout message is displayed.

This program is designed to test the halfdelay() routine and the scroll()
routine neither of which I seem to be able to work.

*/

#include	
#include	
#include	
#include	
#include	
#include	
#include	

WINDOW	*disp, *input;

void	cleanup()
{
	mvwprintw(input, 1, 1, "%77s", "");
	wrefresh(input);
	delwin(disp);
	delwin(input);
	endwin();
	exit(0);
}

main()
{
	int		c;
	char	entry[80], *ptr, *ptr1;

	initscr();
	halfdelay(50);
	nonl();
	noecho();

	signal(SIGABRT, cleanup);
	signal(SIGKILL, cleanup);
	signal(SIGTERM, cleanup);

	disp = newwin(19, 80, 0, 0);
	input = newwin(3, 80, 20, 0);
	box(input, 0, 0);

	mvwprintw(input, 1, 1, "-> ");
	ptr = entry;

	for (;;)
	{
		if ((c = wgetch(input)) == ERR)
		{
			scroll(disp);
			mvwprintw(disp, 18, 0, "timeout *****************");
			wrefresh(disp);
		}
		else
		{
			if (c == 4)
				cleanup();
			if ((c == 4) || (c == '\r'))
			{
				*ptr = 0;
				scroll(disp);
				mvwprintw(disp, 18, 0, "%s", entry);
				wrefresh(disp);
				ptr = entry;
				mvwprintw(input, 1, 1, "%77s", "");
				mvwprintw(input, 1, 1, "-> ");

				if (c == 4)
					cleanup();
			}
			else if (c == '\b')
			{
				if (ptr == entry)
					continue;

				wprintw(input, "\b \b");
				ptr--;
			}
			else if (c == '\t')
			{
				ptr1 = ptr + 8 - ((ptr - entry) % 8);
				while (ptr != ptr1)
				{
					*(ptr++) = ' ';
					waddch(input, ' ');
				}
			}
			else if ((c >= ' ') && (c < 0x7f))
			{
				if ((ptr - entry) > 62)
				{
					*ptr = 0;
					while (!isspace(*ptr))
						ptr--;
					*(ptr++) = 0;
					scroll(disp);
					mvwprintw(disp, 18, 0, "%s", entry);
					wrefresh(disp);
					strcpy(entry, ptr);
					ptr = entry + strlen(entry);
					mvwprintw(input, 1, 1, "%77s", "");
					mvwprintw(input, 1, 1, "-> %s", entry);
				}
				else
					waddch(input, (*(ptr++) = c));
			}
		}
	}
}