xref: /csrg-svn/lib/libcurses/PSD.doc/ex1.c (revision 62780)
162779Sbostic .\" Copyright (c) 1992, 1993
262779Sbostic .\"	 The Regents of the University of California.  All rights reserved.
357374Selan .\"
457374Selan .\" %sccs.include.redist.roff%
557374Selan .\"
6*62780Sbostic .\"     @(#)ex1.c	8.1 (Berkeley) 06/08/93
757374Selan .\"
857374Selan #include <sys/types.h>
957374Selan #include <curses.h>
1057374Selan #include <stdio.h>
1157374Selan #include <signal.h>
1257374Selan 
1357374Selan 
1457374Selan #define YSIZE 10
1557374Selan #define XSIZE 20
1657374Selan 
1757374Selan int quit();
1857374Selan 
1957374Selan main()
2057374Selan {
2157374Selan 	int i, j, c;
2257374Selan 	size_t len;
2357374Selan 	char id[100];
2457374Selan 	FILE *fp;
2557374Selan 	char *s;
2657374Selan 
2757374Selan 	initscr();			/* Always call initscr() first */
2857374Selan 	signal(SIGINT, quit);		/* Make sure wou have a 'cleanup' fn */
2957374Selan 	crmode();			/* We want cbreak mode */
3057374Selan 	noecho();			/* We want to have control of chars */
3157374Selan 	delwin(stdscr);			/* Create our own stdscr */
3257374Selan 	stdscr = newwin(YSIZE, XSIZE, 10, 35);
3357374Selan 	flushok(stdscr, TRUE);		/* Enable flushing of stdout */
3457374Selan 	scrollok(stdscr, TRUE);		/* Enable scrolling */
3557374Selan 	erase();			/* Initially, clear the screen */
3657374Selan 
3757374Selan 	standout();
3857374Selan 	move(0,0);
3957374Selan 	while (1) {
4057374Selan 		c = getchar();
4157374Selan 		switch(c) {
4257374Selan 		case 'q':		/* Quit on 'q' */
4357374Selan 			quit();
4457374Selan 			break;
4557374Selan 		case 's':		/* Go into standout mode on 's' */
4657374Selan 			standout();
4757374Selan 			break;
4857374Selan 		case 'e':		/* Exit standout mode on 'e' */
4957374Selan 			standend();
5057374Selan 			break;
5157374Selan 		case 'r':		/* Force a refresh on 'r' */
5257374Selan 			wrefresh(curscr);
5357374Selan 			break;
5457552Selan 		default:		/* By default output the character */
5557374Selan 			addch(c);
5657374Selan 			refresh();
5757374Selan 		}
5857374Selan 	}
5957374Selan }
6057374Selan 
6157374Selan 
6257374Selan int
6357374Selan quit()
6457374Selan {
6557374Selan 	erase();		/* Terminate by erasing the screen */
6657374Selan 	refresh();
6757374Selan 	endwin();		/* Always end with endwin() */
6857374Selan 	delwin(curscr);		/* Return storage */
6957374Selan 	delwin(stdscr);
7057374Selan 	putchar('\n');
7157374Selan 	exit(0);
7257374Selan }
7357374Selan 
7457374Selan 
7557374Selan 
7657374Selan 
77