2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 static const char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
41 * The window 'manager', initializes curses and handles the actual
47 #define _XOPEN_SOURCE_EXTENDED
52 void display(xwin_t *, wchar_t *);
58 int curses_initialized = 0;
61 * max HAS to be a function, it is called with
62 * an argument of the form --foo at least once.
68 return (a > b ? a : b);
80 if (setcchar(&cc, wc, A_NORMAL, 0, NULL) != OK)
81 p_error("settchar(3) failure");
87 * Display a symbol on somebody's window, processing some control
88 * characters while we are at it.
91 display(xwin_t *win, wchar_t *wc)
95 * Alas, can't use variables in C switch statement.
96 * Workaround these 3 cases with goto.
100 else if (*wc == win->cerase)
102 else if (*wc == win->werase)
108 wadd_wch(win->x_win, makecchar(L'\n'));
109 getyx(win->x_win, win->x_line, win->x_col);
110 wrefresh(win->x_win);
114 if (win == &my_win) {
115 /* Ctrl-D clears the screen. */
116 werase(my_win.x_win);
117 getyx(my_win.x_win, my_win.x_line, my_win.x_col);
118 wrefresh(my_win.x_win);
119 werase(his_win.x_win);
120 getyx(his_win.x_win, his_win.x_line, his_win.x_col);
121 wrefresh(his_win.x_win);
125 /* Erase character. */
129 wmove(win->x_win, win->x_line, max(--win->x_col, 0));
130 getyx(win->x_win, win->x_line, win->x_col);
131 waddch(win->x_win, ' ');
132 wmove(win->x_win, win->x_line, win->x_col);
133 getyx(win->x_win, win->x_line, win->x_col);
134 wrefresh(win->x_win);
141 * On word erase search backwards until we find
142 * the beginning of a word or the beginning of
150 c = readwin(win->x_win, win->x_line, xcol);
156 c = readwin(win->x_win, win->x_line, xcol);
161 wmove(win->x_win, win->x_line, xcol + 1);
162 for (int i = xcol + 1; i < endcol; i++)
163 waddch(win->x_win, ' ');
164 wmove(win->x_win, win->x_line, xcol + 1);
165 getyx(win->x_win, win->x_line, win->x_col);
166 wrefresh(win->x_win);
172 wmove(win->x_win, win->x_line, 0);
173 wclrtoeol(win->x_win);
174 getyx(win->x_win, win->x_line, win->x_col);
175 wrefresh(win->x_win);
184 write(STDOUT_FILENO, wc, sizeof(*wc));
189 if (iswprint(*wc) || *wc == L'\t')
190 wadd_wch(win->x_win, makecchar(*wc));
194 getyx(win->x_win, win->x_line, win->x_col);
195 wrefresh(win->x_win);
199 * Read the character at the indicated position in win
202 readwin(WINDOW *win, int line, int col)
207 getyx(win, oldline, oldcol);
208 wmove(win, line, col);
210 wmove(win, oldline, oldcol);