- /*
- * If we got this far, we have open connection(s) to the terminal(s).
- * Set up the screens.
- */
- for (j = 0; j < argc; j++) {
- active_tty++;
- data[j].screen = newterm(
- (char *)0, /* assume $TERM is the same */
- data[j].output,
- data[j].input);
- if (data[j].screen == 0)
- failed("newterm");
- cbreak();
- noecho();
- scrollok(stdscr, TRUE);
+ box(outer, 0, 0);
+ mvwaddstr(outer, 0, 2, target->titles[k]);
+ wnoutrefresh(outer);
+
+ scrollok(inner, TRUE);
+ keypad(inner, TRUE);
+#ifndef USE_PTHREADS
+ nodelay(inner, TRUE);
+#endif
+
+ target->windows[k] = inner;
+ }
+ doupdate();
+}
+
+static void
+open_screen(DITTO * target, char **source, int length, int which1)
+{
+ if (which1 != 0) {
+ target->input =
+ target->output = open_tty(source[which1]);
+ } else {
+ target->input = stdin;
+ target->output = stdout;
+ }
+
+ target->which1 = which1;
+ target->titles = source;
+ target->length = length;
+ target->fifo.head = -1;
+ target->screen = newterm((char *) 0, /* assume $TERM is the same */
+ target->output,
+ target->input);
+
+ if (target->screen == 0)
+ failed("newterm");
+
+ (void) USING_SCREEN(target->screen, init_screen, target);
+}
+
+static int
+close_screen(
+#if HAVE_USE_WINDOW
+ SCREEN *sp GCC_UNUSED,
+#endif
+ void *arg GCC_UNUSED)
+{
+#if HAVE_USE_WINDOW
+ (void) sp;
+#endif
+ (void) arg;
+ return endwin();
+}
+
+/*
+ * Read data from the 'source' screen.
+ */
+static int
+read_screen(
+#if HAVE_USE_WINDOW
+ SCREEN *sp GCC_UNUSED,
+#endif
+ void *arg)
+{
+ DDATA *data = (DDATA *) arg;
+ DITTO *ditto = &(data->ditto[data->source]);
+ WINDOW *win = ditto->windows[data->source];
+ int ch = wgetch(win);
+
+ if (ch > 0 && ch < 256)
+ put_fifo(&(ditto->fifo), ch);
+ else
+ ch = ERR;
+
+ return ch;
+}
+
+/*
+ * Write all of the data that's in fifos for the 'target' screen.
+ */
+static int
+write_screen(
+#if HAVE_USE_WINDOW
+ SCREEN *sp GCC_UNUSED,
+#endif
+ void *arg GCC_UNUSED)
+{
+ DDATA *data = (DDATA *) arg;
+ DITTO *ditto = &(data->ditto[data->target]);
+ bool changed = FALSE;
+ int which;
+
+ for (which = 0; which < ditto->length; ++which) {
+ WINDOW *win = ditto->windows[which];
+ FIFO *fifo = &(data->ditto[which].fifo);
+ PEEK *peek = &(ditto->peeks[which]);
+ int ch;
+
+ while ((ch = peek_fifo(fifo, peek)) > 0) {
+ changed = TRUE;
+
+ waddch(win, (chtype) ch);
+ wnoutrefresh(win);