xref: /csrg-svn/lib/libcurses/PSD.doc/ex1.c (revision 57374)
1*57374Selan .\" Copyright (c) 1992 The Regents of the University of California.
2*57374Selan .\" All rights reserved.
3*57374Selan .\"
4*57374Selan .\" %sccs.include.redist.roff%
5*57374Selan .\"
6*57374Selan .\"     @(#)ex1.c	1.1 (Berkeley) 12/30/92
7*57374Selan .\"
8*57374Selan #include <sys/types.h>
9*57374Selan #include <curses.h>
10*57374Selan #include <stdio.h>
11*57374Selan #include <signal.h>
12*57374Selan 
13*57374Selan 
14*57374Selan #define YSIZE 10
15*57374Selan #define XSIZE 20
16*57374Selan 
17*57374Selan int quit();
18*57374Selan 
19*57374Selan main()
20*57374Selan {
21*57374Selan 	int i, j, c;
22*57374Selan 	size_t len;
23*57374Selan 	char id[100];
24*57374Selan 	FILE *fp;
25*57374Selan 	char *s;
26*57374Selan 
27*57374Selan 	initscr();			/* Always call initscr() first */
28*57374Selan 	signal(SIGINT, quit);		/* Make sure wou have a 'cleanup' fn */
29*57374Selan 	crmode();			/* We want cbreak mode */
30*57374Selan 	noecho();			/* We want to have control of chars */
31*57374Selan 	delwin(stdscr);			/* Create our own stdscr */
32*57374Selan 	stdscr = newwin(YSIZE, XSIZE, 10, 35);
33*57374Selan 	flushok(stdscr, TRUE);		/* Enable flushing of stdout */
34*57374Selan 	scrollok(stdscr, TRUE);		/* Enable scrolling */
35*57374Selan 	erase();			/* Initially, clear the screen */
36*57374Selan 
37*57374Selan 	standout();
38*57374Selan 	move(0,0);
39*57374Selan 	while (1) {
40*57374Selan 		c = getchar();
41*57374Selan 		switch(c) {
42*57374Selan 		case 'q':		/* Quit on 'q' */
43*57374Selan 			quit();
44*57374Selan 			break;
45*57374Selan 		case 's':		/* Go into standout mode on 's' */
46*57374Selan 			standout();
47*57374Selan 			break;
48*57374Selan 		case 'e':		/* Exit standout mode on 'e' */
49*57374Selan 			standend();
50*57374Selan 			break;
51*57374Selan 		case 'r':		/* Force a refresh on 'r' */
52*57374Selan 			wrefresh(curscr);
53*57374Selan 			break;
54*57374Selan 		default:		/* By defualt output the character */
55*57374Selan 			addch(c);
56*57374Selan 			refresh();
57*57374Selan 		}
58*57374Selan 	}
59*57374Selan }
60*57374Selan 
61*57374Selan 
62*57374Selan int
63*57374Selan quit()
64*57374Selan {
65*57374Selan 	erase();		/* Terminate by erasing the screen */
66*57374Selan 	refresh();
67*57374Selan 	endwin();		/* Always end with endwin() */
68*57374Selan 	delwin(curscr);		/* Return storage */
69*57374Selan 	delwin(stdscr);
70*57374Selan 	putchar('\n');
71*57374Selan 	exit(0);
72*57374Selan }
73*57374Selan 
74*57374Selan 
75*57374Selan 
76*57374Selan 
77