xref: /csrg-svn/lib/libcurses/EXAMPLES/ex1.c (revision 61256)
157566Selan /*
2*61256Sbostic  * Copyright (c) 1992, 1993
3*61256Sbostic  *	The Regents of the University of California.  All rights reserved.
457566Selan  *
557566Selan  *
657566Selan  * %sccs.include.redist.c%
757566Selan  */
857566Selan 
957566Selan #ifndef lint
1057566Selan static char copyright[] =
11*61256Sbostic "@(#) Copyright (c) 1992, 1993\n\
12*61256Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1357566Selan #endif /* not lint */
1457566Selan 
1557566Selan #ifndef lint
16*61256Sbostic static char sccsid[] = "@(#)ex1.c	8.1 (Berkeley) 06/04/93";
1757566Selan #endif /* not lint */
1857566Selan #include <sys/types.h>
1957566Selan #include <curses.h>
2057566Selan #include <stdio.h>
2157566Selan #include <signal.h>
2257566Selan 
2357566Selan 
2457566Selan #define YSIZE 10
2557566Selan #define XSIZE 20
2657566Selan 
2757566Selan int quit();
2857566Selan 
main()2957566Selan main()
3057566Selan {
3157566Selan 	int i, j, c;
3257566Selan 	size_t len;
3357566Selan 	char id[100];
3457566Selan 	FILE *fp;
3557566Selan 	char *s;
3657566Selan 
3757566Selan 	initscr();			/* Always call initscr() first */
3857566Selan 	signal(SIGINT, quit);		/* Make sure wou have a 'cleanup' fn */
3957566Selan 	crmode();			/* We want cbreak mode */
4057566Selan 	noecho();			/* We want to have control of chars */
4157566Selan 	delwin(stdscr);			/* Create our own stdscr */
4257566Selan 	stdscr = newwin(YSIZE, XSIZE, 10, 35);
4357566Selan 	flushok(stdscr, TRUE);		/* Enable flushing of stdout */
4457566Selan 	scrollok(stdscr, TRUE);		/* Enable scrolling */
4557566Selan 	erase();			/* Initially, clear the screen */
4657566Selan 
4757566Selan 	standout();
4857566Selan 	move(0,0);
4957566Selan 	while (1) {
5057566Selan 		c = getchar();
5157566Selan 		switch(c) {
5257566Selan 		case 'q':		/* Quit on 'q' */
5357566Selan 			quit();
5457566Selan 			break;
5557566Selan 		case 's':		/* Go into standout mode on 's' */
5657566Selan 			standout();
5757566Selan 			break;
5857566Selan 		case 'e':		/* Exit standout mode on 'e' */
5957566Selan 			standend();
6057566Selan 			break;
6157566Selan 		case 'r':		/* Force a refresh on 'r' */
6257566Selan 			wrefresh(curscr);
6357566Selan 			break;
6457566Selan 		default:		/* By default output the character */
6557566Selan 			addch(c);
6657566Selan 			refresh();
6757566Selan 		}
6857566Selan 	}
6957566Selan }
7057566Selan 
7157566Selan 
7257566Selan int
quit()7357566Selan quit()
7457566Selan {
7557566Selan 	erase();		/* Terminate by erasing the screen */
7657566Selan 	refresh();
7757566Selan 	endwin();		/* Always end with endwin() */
7857566Selan 	delwin(curscr);		/* Return storage */
7957566Selan 	delwin(stdscr);
8057566Selan 	putchar('\n');
8157566Selan 	exit(0);
8257566Selan }
8357566Selan 
8457566Selan 
8557566Selan 
8657566Selan 
87