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