xref: /illumos-gate/usr/src/ucblib/libcurses/getch.c (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 /*LINTLIBRARY*/
16 
17 #ifndef lint
18 static char
19 sccsid[] = "@(#)getch.c 1.9 88/02/08 SMI"; /* from UCB 5.3 86/04/16 */
20 #endif	/* not lint */
21 
22 #include	"curses.ext"
23 
24 /*
25  *	This routine reads in a character from the window.
26  */
27 
28 int
29 wgetch(WINDOW *win)
30 {
31 	bool	weset = FALSE;
32 	char	inp;
33 
34 	if (!win->_scroll && (win->_flags&_FULLWIN) &&
35 	    win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
36 		return (ERR);
37 #ifdef DEBUG
38 	fprintf(outf, "WGETCH: _echoit = %c, _rawmode = %c\n",
39 		_echoit ? 'T' : 'F', _rawmode ? 'T' : 'F');
40 #endif
41 	if (_echoit && !_rawmode) {
42 		cbreak();
43 		weset++;
44 	}
45 	inp = getchar();
46 #ifdef DEBUG
47 	fprintf(outf, "WGETCH got '%s'\n", unctrl(inp));
48 #endif
49 	if (_echoit) {
50 		(void) mvwaddch(curscr, win->_cury + win->_begy,
51 			win->_curx + win->_begx, inp);
52 		(void) waddch(win, inp);
53 	}
54 	if (weset)
55 		nocbreak();
56 	return ((int)inp);
57 }
58