Annotation of src/usr.bin/talk/display.c, Revision 1.12
1.12 ! millert 1: /* $OpenBSD: display.c,v 1.11 2002/06/20 10:18:29 form Exp $ */
1.1 deraadt 2: /* $NetBSD: display.c,v 1.3 1994/12/09 02:14:13 jtc Exp $ */
3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.12 ! millert 41: static char rcsid[] = "$OpenBSD: display.c,v 1.11 2002/06/20 10:18:29 form Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: /*
45: * The window 'manager', initializes curses and handles the actual
46: * displaying of text
47: */
48: #include "talk.h"
1.3 deraadt 49: #include <ctype.h>
1.1 deraadt 50:
51: xwin_t my_win;
52: xwin_t his_win;
53: WINDOW *line_win;
54:
55: int curses_initialized = 0;
1.8 hugh 56: int high_print = 0;
1.12 ! millert 57: bool smooth_scroll = FALSE;
1.1 deraadt 58:
59: /*
60: * max HAS to be a function, it is called with
61: * a argument of the form --foo at least once.
62: */
1.5 pjanzen 63: int
1.1 deraadt 64: max(a,b)
65: int a, b;
66: {
67:
68: return (a > b ? a : b);
69: }
70:
71: /*
72: * Display some text on somebody's window, processing some control
73: * characters while we are at it.
74: */
1.5 pjanzen 75: void
1.1 deraadt 76: display(win, text, size)
1.9 mpech 77: xwin_t *win;
78: char *text;
1.1 deraadt 79: int size;
80: {
1.9 mpech 81: int i;
1.1 deraadt 82: char cch;
83:
84: for (i = 0; i < size; i++) {
1.6 millert 85: /*
86: * Since we do not use curses's input routines we must
87: * convert '\r' -> '\n' ourselves.
88: */
89: if (*text == '\r')
90: *text = '\n';
91: if (*text == '\n') {
1.1 deraadt 92: xscroll(win, 0);
93: text++;
94: continue;
95: }
96: /* erase character */
97: if (*text == win->cerase) {
98: wmove(win->x_win, win->x_line, max(--win->x_col, 0));
99: getyx(win->x_win, win->x_line, win->x_col);
100: waddch(win->x_win, ' ');
101: wmove(win->x_win, win->x_line, win->x_col);
102: getyx(win->x_win, win->x_line, win->x_col);
103: text++;
104: continue;
105: }
106: /*
107: * On word erase search backwards until we find
108: * the beginning of a word or the beginning of
109: * the line.
110: */
111: if (*text == win->werase) {
112: int endcol, xcol, i, c;
113:
114: endcol = win->x_col;
115: xcol = endcol - 1;
116: while (xcol >= 0) {
117: c = readwin(win->x_win, win->x_line, xcol);
118: if (c != ' ')
119: break;
120: xcol--;
121: }
122: while (xcol >= 0) {
123: c = readwin(win->x_win, win->x_line, xcol);
124: if (c == ' ')
125: break;
126: xcol--;
127: }
128: wmove(win->x_win, win->x_line, xcol + 1);
129: for (i = xcol + 1; i < endcol; i++)
130: waddch(win->x_win, ' ');
131: wmove(win->x_win, win->x_line, xcol + 1);
132: getyx(win->x_win, win->x_line, win->x_col);
133: text++;
134: continue;
135: }
136: /* line kill */
137: if (*text == win->kill) {
138: wmove(win->x_win, win->x_line, 0);
139: wclrtoeol(win->x_win);
140: getyx(win->x_win, win->x_line, win->x_col);
141: text++;
142: continue;
143: }
144: if (*text == '\f') {
145: if (win == &my_win)
146: wrefresh(curscr);
147: text++;
148: continue;
149: }
150: if (win->x_col == COLS-1) {
151: /* check for wraparound */
152: xscroll(win, 0);
153: }
1.8 hugh 154: if (*text != '\t' &&
155: ((!high_print && !isprint(*text)) || iscntrl(*text))) {
1.1 deraadt 156: waddch(win->x_win, '^');
157: getyx(win->x_win, win->x_line, win->x_col);
158: if (win->x_col == COLS-1) /* check for wraparound */
159: xscroll(win, 0);
160: cch = (*text & 63) + 64;
161: waddch(win->x_win, cch);
162: } else
1.7 angelos 163: waddch(win->x_win, (unsigned char)(*text));
1.1 deraadt 164: getyx(win->x_win, win->x_line, win->x_col);
165: text++;
166: }
167: wrefresh(win->x_win);
168: }
169:
170: /*
171: * Read the character at the indicated position in win
172: */
1.5 pjanzen 173: int
1.1 deraadt 174: readwin(win, line, col)
175: WINDOW *win;
1.5 pjanzen 176: int line, col;
1.1 deraadt 177: {
178: int oldline, oldcol;
1.9 mpech 179: int c;
1.1 deraadt 180:
181: getyx(win, oldline, oldcol);
182: wmove(win, line, col);
183: c = winch(win);
184: wmove(win, oldline, oldcol);
185: return (c);
186: }
187:
188: /*
189: * Scroll a window, blanking out the line following the current line
190: * so that the current position is obvious
191: */
1.5 pjanzen 192: void
1.1 deraadt 193: xscroll(win, flag)
1.9 mpech 194: xwin_t *win;
1.1 deraadt 195: int flag;
196: {
197:
198: if (flag == -1) {
199: wmove(win->x_win, 0, 0);
200: win->x_line = 0;
201: win->x_col = 0;
202: return;
203: }
204: win->x_col = 0;
1.12 ! millert 205: if (smooth_scroll) {
! 206: if (++win->x_line == win->x_nlines) {
! 207: --win->x_line;
! 208: scroll(win->x_win);
! 209: }
! 210: } else {
! 211: win->x_line = (win->x_line + 1) % win->x_nlines;
! 212: wmove(win->x_win, win->x_line, win->x_col);
! 213: wclrtoeol(win->x_win);
! 214: wmove(win->x_win, (win->x_line + 1) % win->x_nlines,
! 215: win->x_col);
! 216: wclrtoeol(win->x_win);
! 217: }
1.1 deraadt 218: wmove(win->x_win, win->x_line, win->x_col);
219: }