xref: /titanic_41/usr/src/lib/libcurses/screen/quick_echo.c (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*LINTLIBRARY*/
43 
44 #include	<sys/types.h>
45 #include	"curses_inc.h"
46 
47 extern	int	outchcount;
48 
49 /*
50  *  These routines short-circuit much of the innards of curses in order to get
51  *  a single character output to the screen quickly! It is used by waddch().
52  */
53 
54 int
55 _quick_echo(WINDOW *win, chtype ch)
56 {
57 	short	y = win->_cury;
58 	short	SPy = y + win->_begy + win->_yoffset;
59 	short	SPx = (win->_curx - 1) + win->_begx;
60 	chtype	rawc = _CHAR(ch), rawattrs = _ATTR(ch);
61 
62 	if ((curscr->_flags & _CANT_BE_IMMED) ||
63 	    (win->_flags & _WINCHANGED) ||
64 	    (win->_clear) || (curscr->_clear) ||
65 	    (_virtscr->_flags & _WINCHANGED) ||
66 	    (SPy > ((LINES + SP->Yabove) - 1)) || (SPx > (COLS - 1)) ||
67 	    (SP->slk && (SP->slk->_changed == TRUE))) {
68 		win->_flags |= _WINCHANGED;
69 		return (wrefresh(win));
70 	}
71 
72 	outchcount = 0;
73 	win->_firstch[y] = _INFINITY;
74 	win->_lastch[y] = -1;
75 	/* If the cursor is not in the right place, put it there! */
76 	if ((SPy != curscr->_cury) || (SPx != curscr->_curx)) {
77 		(void) mvcur(curscr->_cury, curscr->_curx, SPy, SPx);
78 		curscr->_cury = SPy;
79 	}
80 	curscr->_curx = SPx + 1;
81 	_CURHASH[SPy] = _NOHASH;
82 	if (ch != ' ') {
83 		if (SPx > _ENDNS[SPy])
84 			_ENDNS[SPy] = SPx;
85 		if (SPx < _BEGNS[SPy])
86 			_BEGNS[SPy] = SPx;
87 	}
88 	_virtscr->_y[SPy][SPx] = curscr->_y[SPy][SPx] = ch;
89 
90 	if (rawattrs != curscr->_attrs)
91 		_VIDS(rawattrs, curscr->_attrs);
92 
93 	if (SP->phys_irm)
94 		_OFFINSERT();
95 
96 	/* Write it out! */
97 	/* LINTED */
98 	(void) _outch((char) rawc);
99 	(void) fflush(SP->term_file);
100 
101 	return (outchcount);
102 }
103