2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 static const char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
39 * The window 'manager', initializes curses and handles the actual
45 #define _XOPEN_SOURCE_EXTENDED
50 void display(xwin_t *, wchar_t *);
56 int curses_initialized = 0;
59 * max HAS to be a function, it is called with
60 * an argument of the form --foo at least once.
66 return (a > b ? a : b);
78 if (setcchar(&cc, wc, A_NORMAL, 0, NULL) != OK)
79 p_error("settchar(3) failure");
85 * Display a symbol on somebody's window, processing some control
86 * characters while we are at it.
89 display(xwin_t *win, wchar_t *wc)
93 * Alas, can't use variables in C switch statement.
94 * Workaround these 3 cases with goto.
98 else if (*wc == win->cerase)
100 else if (*wc == win->werase)
106 wadd_wch(win->x_win, makecchar(L'\n'));
107 getyx(win->x_win, win->x_line, win->x_col);
108 wrefresh(win->x_win);
112 if (win == &my_win) {
113 /* Ctrl-D clears the screen. */
114 werase(my_win.x_win);
115 getyx(my_win.x_win, my_win.x_line, my_win.x_col);
116 wrefresh(my_win.x_win);
117 werase(his_win.x_win);
118 getyx(his_win.x_win, his_win.x_line, his_win.x_col);
119 wrefresh(his_win.x_win);
123 /* Erase character. */
127 wmove(win->x_win, win->x_line, max(--win->x_col, 0));
128 getyx(win->x_win, win->x_line, win->x_col);
129 waddch(win->x_win, ' ');
130 wmove(win->x_win, win->x_line, win->x_col);
131 getyx(win->x_win, win->x_line, win->x_col);
132 wrefresh(win->x_win);
139 * On word erase search backwards until we find
140 * the beginning of a word or the beginning of
148 c = readwin(win->x_win, win->x_line, xcol);
154 c = readwin(win->x_win, win->x_line, xcol);
159 wmove(win->x_win, win->x_line, xcol + 1);
160 for (int i = xcol + 1; i < endcol; i++)
161 waddch(win->x_win, ' ');
162 wmove(win->x_win, win->x_line, xcol + 1);
163 getyx(win->x_win, win->x_line, win->x_col);
164 wrefresh(win->x_win);
170 wmove(win->x_win, win->x_line, 0);
171 wclrtoeol(win->x_win);
172 getyx(win->x_win, win->x_line, win->x_col);
173 wrefresh(win->x_win);
182 write(STDOUT_FILENO, wc, sizeof(*wc));
187 if (iswprint(*wc) || *wc == L'\t')
188 wadd_wch(win->x_win, makecchar(*wc));
192 getyx(win->x_win, win->x_line, win->x_col);
193 wrefresh(win->x_win);
197 * Read the character at the indicated position in win
200 readwin(WINDOW *win, int line, int col)
205 getyx(win, oldline, oldcol);
206 wmove(win, line, col);
208 wmove(win, oldline, oldcol);