xref: /illumos-gate/usr/src/ucblib/libcurses/getch.c (revision f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*LINTLIBRARY*/
18 
19 #ifndef lint
20 static char
21 sccsid[] = "@(#)getch.c 1.9 88/02/08 SMI"; /* from UCB 5.3 86/04/16 */
22 #endif	/* not lint */
23 
24 #include	"curses.ext"
25 
26 /*
27  *	This routine reads in a character from the window.
28  */
29 
30 int
31 wgetch(WINDOW *win)
32 {
33 	bool	weset = FALSE;
34 	char	inp;
35 
36 	if (!win->_scroll && (win->_flags&_FULLWIN) &&
37 	    win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
38 		return (ERR);
39 #ifdef DEBUG
40 	fprintf(outf, "WGETCH: _echoit = %c, _rawmode = %c\n",
41 		_echoit ? 'T' : 'F', _rawmode ? 'T' : 'F');
42 #endif
43 	if (_echoit && !_rawmode) {
44 		cbreak();
45 		weset++;
46 	}
47 	inp = getchar();
48 #ifdef DEBUG
49 	fprintf(outf, "WGETCH got '%s'\n", unctrl(inp));
50 #endif
51 	if (_echoit) {
52 		(void) mvwaddch(curscr, win->_cury + win->_begy,
53 			win->_curx + win->_begx, inp);
54 		(void) waddch(win, inp);
55 	}
56 	if (weset)
57 		nocbreak();
58 	return ((int)inp);
59 }
60