xref: /original-bsd/usr.bin/talk/init_disp.c (revision 18f6d767)
1 #ifndef lint
2 static char sccsid[] = "@(#)init_disp.c	1.3 (Berkeley) 04/24/85";
3 #endif
4 
5 /*
6  * Initialization code for the display package,
7  * as well as the signal handling routines.
8  */
9 
10 #include "talk.h"
11 #include <signal.h>
12 
13 /*
14  * Set up curses, catch the appropriate signals,
15  * and build the various windows.
16  */
17 init_display()
18 {
19 	void sig_sent();
20 	struct sigvec sigv;
21 
22 	initscr();
23 	(void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
24 	sigv.sv_mask |= sigmask(SIGALRM);
25 	(void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
26 	curses_initialized = 1;
27 	clear();
28 	refresh();
29 	noecho();
30 	crmode();
31 	signal(SIGINT, sig_sent);
32 	signal(SIGPIPE, sig_sent);
33 	/* curses takes care of ^Z */
34 	my_win.x_nlines = LINES / 2;
35 	my_win.x_ncols = COLS;
36 	my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
37 	scrollok(my_win.x_win, FALSE);
38 	wclear(my_win.x_win);
39 
40 	his_win.x_nlines = LINES / 2 - 1;
41 	his_win.x_ncols = COLS;
42 	his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
43 	    my_win.x_nlines+1, 0);
44 	scrollok(his_win.x_win, FALSE);
45 	wclear(his_win.x_win);
46 
47 	line_win = newwin(1, COLS, my_win.x_nlines, 0);
48 	box(line_win, '-', '-');
49 	wrefresh(line_win);
50 	/* let them know we are working on it */
51 	current_state = "No connection yet";
52 }
53 
54 /*
55  * Trade edit characters with the other talk. By agreement
56  * the first three characters each talk transmits after
57  * connection are the three edit characters.
58  */
59 set_edit_chars()
60 {
61 	char buf[3];
62 	int cc;
63 	struct sgttyb tty;
64 	struct ltchars ltc;
65 
66 	ioctl(0, TIOCGETP, &tty);
67 	ioctl(0, TIOCGLTC, (struct sgttyb *)&ltc);
68 	my_win.cerase = tty.sg_erase;
69 	my_win.kill = tty.sg_kill;
70 	if (ltc.t_werasc == (char) -1)
71 		my_win.werase = '\027';	 /* control W */
72 	else
73 		my_win.werase = ltc.t_werasc;
74 	buf[0] = my_win.cerase;
75 	buf[1] = my_win.kill;
76 	buf[2] = my_win.werase;
77 	cc = write(sockt, buf, sizeof(buf));
78 	if (cc != sizeof(buf) )
79 		p_error("Lost the connection");
80 	cc = read(sockt, buf, sizeof(buf));
81 	if (cc != sizeof(buf) )
82 		p_error("Lost the connection");
83 	his_win.cerase = buf[0];
84 	his_win.kill = buf[1];
85 	his_win.werase = buf[2];
86 }
87 
88 void
89 sig_sent()
90 {
91 
92 	message("Connection closing. Exiting");
93 	quit();
94 }
95 
96 /*
97  * All done talking...hang up the phone and reset terminal thingy's
98  */
99 quit()
100 {
101 
102 	if (curses_initialized) {
103 		wmove(his_win.x_win, his_win.x_nlines-1, 0);
104 		wclrtoeol(his_win.x_win);
105 		wrefresh(his_win.x_win);
106 		endwin();
107 	}
108 	if (invitation_waiting)
109 		send_delete();
110 	exit(0);
111 }
112