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
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.
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]
23 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * The window 'manager', initializes curses and handles the actual
50 static int readwin(WINDOW
*, int, int);
51 static void xscroll(register xwin_t
*, int);
57 int curses_initialized
= 0;
60 * max HAS to be a function, it is called with
61 * a argument of the form --foo at least once.
76 * Display some text on somebody's window, processing some control
77 * characters while we are at it.
81 display(win
, text
, size
)
87 int mb_cur_max
= MB_CUR_MAX
;
89 for (i
= 0; i
< size
; i
++) {
92 if (*text
== '\n'|| *text
== '\r') {
100 if (*text
== win
->cerase
) {
101 wmove(win
->x_win
, win
->x_line
, max(--win
->x_col
, 0));
102 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
103 waddch(win
->x_win
, ' ');
104 wmove(win
->x_win
, win
->x_line
, win
->x_col
);
105 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
110 * On word erase search backwards until we find
111 * the beginning of a word or the beginning of
114 if (*text
== win
->werase
) {
115 int endcol
, xcol
, i
, c
;
120 c
= readwin(win
->x_win
, win
->x_line
, xcol
);
126 c
= readwin(win
->x_win
, win
->x_line
, xcol
);
131 wmove(win
->x_win
, win
->x_line
, xcol
+ 1);
132 for (i
= xcol
+ 1; i
< endcol
; i
++)
133 waddch(win
->x_win
, ' ');
134 wmove(win
->x_win
, win
->x_line
, xcol
+ 1);
135 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
139 if (*text
== win
->kill
) {
140 wmove(win
->x_win
, win
->x_line
, 0);
141 wclrtoeol(win
->x_win
);
142 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
153 if (*text
== '\004') {
157 /* typing alert character will alert recipient's terminal */
159 if (*text
== '\007') {
164 /* check for wrap around */
165 if (win
->x_col
== COLS
-1) {
170 * Handle the multibyte case
171 * We print '?' for nonprintable widechars.
174 if (mb_cur_max
> 1 && mblen(text
, mb_cur_max
) > 1) {
178 len
= mbtowc(&wc
, text
, mb_cur_max
);
180 if (iswprint(wc
) || iswspace(wc
)) {
181 /* its printable, put out the bytes */
183 if (win
->x_col
== COLS
-1) /* wraparound */
185 waddch(win
->x_win
, *text
++);
186 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
191 * otherwise, punt and print a question mark.
194 waddch(win
->x_win
, '?');
195 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
199 itext
= (unsigned int) *text
;
200 if (isprint(itext
) || *text
== ' ' || *text
== '\t' ||
201 *text
== '\013' || *text
== '\007' /* bell */) {
202 waddch(win
->x_win
, *text
);
205 if (!isascii(*text
)) {
206 /* check for wrap around */
207 if (win
->x_col
== COLS
-3) {
210 waddch(win
->x_win
, 'M');
211 waddch(win
->x_win
, '-');
212 *text
= toascii(*text
);
214 if (iscntrl(*text
)) {
216 /* check for wrap around */
217 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
218 if (win
->x_col
== COLS
-2) {
222 waddch(win
->x_win
, '^');
223 waddch(win
->x_win
, *text
+ 0100);
226 waddch(win
->x_win
, *text
);
229 getyx(win
->x_win
, win
->x_line
, win
->x_col
);
233 wrefresh(win
->x_win
);
238 * Read the character at the indicated position in win
242 readwin(win
, line
, col
)
249 getyx(win
, oldline
, oldcol
);
250 wmove(win
, line
, col
);
252 wmove(win
, oldline
, oldcol
);
257 * Scroll a window, blanking out the line following the current line
258 * so that the current position is obvious
263 register xwin_t
*win
;
267 wmove(win
->x_win
, 0, 0);
272 win
->x_line
= (win
->x_line
+ 1) % win
->x_nlines
;
274 wmove(win
->x_win
, win
->x_line
, win
->x_col
);
275 wclrtoeol(win
->x_win
);
276 wmove(win
->x_win
, (win
->x_line
+ 1) % win
->x_nlines
, win
->x_col
);
277 wclrtoeol(win
->x_win
);
278 wmove(win
->x_win
, win
->x_line
, win
->x_col
);