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
34 static const char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94";
38 * Initialization code for the display package,
39 * as well as the signal handling routines.
53 * Make sure the callee can write to the screen
61 if ((tty = ttyname(STDERR_FILENO)) == NULL)
63 if (stat(tty, &sb) < 0)
65 if (!(sb.st_mode & S_IWGRP))
66 errx(1, "The callee cannot write to this terminal, use \"mesg y\".");
70 * Set up curses, catch the appropriate signals,
71 * and build the various windows.
78 if (initscr() == NULL)
79 errx(1, "Terminal type unset or lacking necessary features.");
80 (void) sigaction(SIGTSTP, (struct sigaction *)0, &sa);
81 sigaddset(&sa.sa_mask, SIGALRM);
82 (void) sigaction(SIGTSTP, &sa, (struct sigaction *)0);
83 curses_initialized = 1;
88 signal(SIGINT, sig_sent);
89 signal(SIGPIPE, sig_sent);
90 signal(SIGWINCH, sig_winch);
91 /* curses takes care of ^Z */
92 my_win.x_nlines = LINES / 2;
93 my_win.x_ncols = COLS;
94 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
95 idlok(my_win.x_win, TRUE);
96 scrollok(my_win.x_win, TRUE);
99 his_win.x_nlines = LINES / 2 - 1;
100 his_win.x_ncols = COLS;
101 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
102 my_win.x_nlines+1, 0);
103 idlok(my_win.x_win, TRUE);
104 scrollok(his_win.x_win, TRUE);
105 wclear(his_win.x_win);
107 line_win = newwin(1, COLS, my_win.x_nlines, 0);
108 #if defined(hline) || defined(whline) || defined(NCURSES_VERSION)
109 whline(line_win, 0, COLS);
111 box(line_win, '-', '-');
114 /* let them know we are working on it */
115 current_state = "No connection yet";
119 * Trade edit characters with the other talk. By agreement
120 * the first three characters each talk transmits after
121 * connection are the three edit characters.
131 my_win.cerase = tio.c_cc[VERASE];
132 my_win.kill = tio.c_cc[VKILL];
133 my_win.werase = tio.c_cc[VWERASE];
134 if (my_win.cerase == (char)_POSIX_VDISABLE)
135 my_win.kill = CERASE;
136 if (my_win.kill == (char)_POSIX_VDISABLE)
138 if (my_win.werase == (char)_POSIX_VDISABLE)
139 my_win.werase = CWERASE;
140 buf[0] = my_win.cerase;
141 buf[1] = my_win.kill;
142 buf[2] = my_win.werase;
143 cc = write(sockt, buf, sizeof(buf));
144 if (cc != sizeof(buf) )
145 p_error("Lost the connection");
146 cc = read(sockt, buf, sizeof(buf));
147 if (cc != sizeof(buf) )
148 p_error("Lost the connection");
149 his_win.cerase = buf[0];
150 his_win.kill = buf[1];
151 his_win.werase = buf[2];
156 sig_sent(int signo __unused)
159 message("Connection closing. Exiting");
164 sig_winch(int dummy __unused)
171 * All done talking...hang up the phone and reset terminal thingy's
177 if (curses_initialized) {
178 wmove(his_win.x_win, his_win.x_nlines-1, 0);
179 wclrtoeol(his_win.x_win);
180 wrefresh(his_win.x_win);
183 if (invitation_waiting)
189 * If we get SIGWINCH, recompute both window sizes and refresh things.
196 if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) < 0 ||
197 (ws.ws_row == LINES && ws.ws_col == COLS))
200 /* Update curses' internal state with new window size. */
201 resizeterm(ws.ws_row, ws.ws_col);
204 * Resize each window but wait to refresh the screen until
205 * everything has been drawn so the cursor is in the right spot.
207 my_win.x_nlines = LINES / 2;
208 my_win.x_ncols = COLS;
209 wresize(my_win.x_win, my_win.x_nlines, my_win.x_ncols);
210 mvwin(my_win.x_win, 0, 0);
211 clearok(my_win.x_win, TRUE);
213 his_win.x_nlines = LINES / 2 - 1;
214 his_win.x_ncols = COLS;
215 wresize(his_win.x_win, his_win.x_nlines, his_win.x_ncols);
216 mvwin(his_win.x_win, my_win.x_nlines + 1, 0);
217 clearok(his_win.x_win, TRUE);
219 wresize(line_win, 1, COLS);
220 mvwin(line_win, my_win.x_nlines, 0);
221 #if defined(NCURSES_VERSION) || defined(whline)
222 whline(line_win, '-', COLS);
224 wmove(line_win, my_win.x_nlines, 0);
225 box(line_win, '-', '-');
228 /* Now redraw the screen. */
229 wrefresh(his_win.x_win);
231 wrefresh(my_win.x_win);