/* * Display some text on somebody's window, processing some control * characters while we are at it. */ int display (register xwin_t * win, register char *text, int size) { register int i; unsigned char cch; for (i = 0; i < size; i++) { if (*text == '\n') { xscroll (win, 0); text++; continue; } if (*text == '\a') { beep (); wrefresh (curscr); text++; continue; } /* erase character */ if (*text == win->cerase) { wmove (win->x_win, win->x_line, max (--win->x_col, 0)); getyx (win->x_win, win->x_line, win->x_col); waddch (win->x_win, ' '); wmove (win->x_win, win->x_line, win->x_col); getyx (win->x_win, win->x_line, win->x_col); text++; continue; } /* * On word erase search backwards until we find * the beginning of a word or the beginning of * the line. */ if (*text == win->werase) { int endcol, xcol, i, c; endcol = win->x_col; xcol = endcol - 1; while (xcol >= 0) { c = readwin (win->x_win, win->x_line, xcol); if (c != ' ') break; xcol--; } while (xcol >= 0) { c = readwin (win->x_win, win->x_line, xcol); if (c == ' ') break; xcol--; } wmove (win->x_win, win->x_line, xcol + 1); for (i = xcol + 1; i < endcol; i++) waddch (win->x_win, ' '); wmove (win->x_win, win->x_line, xcol + 1); getyx (win->x_win, win->x_line, win->x_col); text++; continue; } /* line kill */ if (*text == win->kill) { wmove (win->x_win, win->x_line, 0); wclrtoeol (win->x_win); getyx (win->x_win, win->x_line, win->x_col); text++; continue; } if (*text == '\f') { if (win == &my_win) wrefresh (curscr); text++; continue; } if (win->x_col == COLS - 1) { /* check for wraparound */ xscroll (win, 0); } if (*text < ' ' && *text != '\t') { waddch (win->x_win, '^'); getyx (win->x_win, win->x_line, win->x_col); if (win->x_col == COLS - 1) /* check for wraparound */ xscroll (win, 0); cch = (*text & 63) + 64; waddch (win->x_win, cch); } else waddch (win->x_win, *text); getyx (win->x_win, win->x_line, win->x_col); text++; } wrefresh (win->x_win); return 0; }
/* * Display a symbol on somebody's window, processing some control * characters while we are at it. */ void display(xwin_t *win, wchar_t *wc) { /* * Alas, can't use variables in C switch statement. * Workaround these 3 cases with goto. */ if (*wc == win->kill) goto kill; else if (*wc == win->cerase) goto cerase; else if (*wc == win->werase) goto werase; switch (*wc) { case L'\n': case L'\r': wadd_wch(win->x_win, makecchar(L'\n')); getyx(win->x_win, win->x_line, win->x_col); wrefresh(win->x_win); return; case 004: if (win == &my_win) { /* Ctrl-D clears the screen. */ werase(my_win.x_win); getyx(my_win.x_win, my_win.x_line, my_win.x_col); wrefresh(my_win.x_win); werase(his_win.x_win); getyx(his_win.x_win, his_win.x_line, his_win.x_col); wrefresh(his_win.x_win); } return; /* Erase character. */ case 010: /* BS */ case 0177: /* DEL */ cerase: wmove(win->x_win, win->x_line, max(--win->x_col, 0)); getyx(win->x_win, win->x_line, win->x_col); waddch(win->x_win, ' '); wmove(win->x_win, win->x_line, win->x_col); getyx(win->x_win, win->x_line, win->x_col); wrefresh(win->x_win); return; case 027: /* ^W */ werase: { /* * On word erase search backwards until we find * the beginning of a word or the beginning of * the line. */ int endcol, xcol, c; endcol = win->x_col; xcol = endcol - 1; while (xcol >= 0) { c = readwin(win->x_win, win->x_line, xcol); if (c != ' ') break; xcol--; } while (xcol >= 0) { c = readwin(win->x_win, win->x_line, xcol); if (c == ' ') break; xcol--; } wmove(win->x_win, win->x_line, xcol + 1); for (int i = xcol + 1; i < endcol; i++) waddch(win->x_win, ' '); wmove(win->x_win, win->x_line, xcol + 1); getyx(win->x_win, win->x_line, win->x_col); wrefresh(win->x_win); return; } case 025: /* ^U */ kill: wmove(win->x_win, win->x_line, 0); wclrtoeol(win->x_win); getyx(win->x_win, win->x_line, win->x_col); wrefresh(win->x_win); return; case L'\f': if (win == &my_win) wrefresh(curscr); return; case L'\7': write(STDOUT_FILENO, wc, sizeof(*wc)); return; } if (iswprint(*wc) || *wc == L'\t') wadd_wch(win->x_win, makecchar(*wc)); else beep(); getyx(win->x_win, win->x_line, win->x_col); wrefresh(win->x_win); }
/* * Display some text on somebody's window, processing some control * characters while we are at it. */ void display(xwin_t *win, char *text, int size) { int i; char cch; for (i = 0; i < size; i++) { if (*text == '\n' || *text == '\r') { waddch(win->x_win, '\n'); getyx(win->x_win, win->x_line, win->x_col); text++; continue; } if (*text == 004 && win == &my_win) { /* control-D clears the screen */ werase(my_win.x_win); getyx(my_win.x_win, my_win.x_line, my_win.x_col); wrefresh(my_win.x_win); werase(his_win.x_win); getyx(his_win.x_win, his_win.x_line, his_win.x_col); wrefresh(his_win.x_win); text++; continue; } /* erase character */ if ( *text == win->cerase || *text == 010 /* BS */ || *text == 0177 /* DEL */ ) { wmove(win->x_win, win->x_line, max(--win->x_col, 0)); getyx(win->x_win, win->x_line, win->x_col); waddch(win->x_win, ' '); wmove(win->x_win, win->x_line, win->x_col); getyx(win->x_win, win->x_line, win->x_col); text++; continue; } /* * On word erase search backwards until we find * the beginning of a word or the beginning of * the line. */ if ( *text == win->werase || *text == 027 /* ^W */ ) { int endcol, xcol, ii, c; endcol = win->x_col; xcol = endcol - 1; while (xcol >= 0) { c = readwin(win->x_win, win->x_line, xcol); if (c != ' ') break; xcol--; } while (xcol >= 0) { c = readwin(win->x_win, win->x_line, xcol); if (c == ' ') break; xcol--; } wmove(win->x_win, win->x_line, xcol + 1); for (ii = xcol + 1; ii < endcol; ii++) waddch(win->x_win, ' '); wmove(win->x_win, win->x_line, xcol + 1); getyx(win->x_win, win->x_line, win->x_col); text++; continue; } /* line kill */ if ( *text == win->kill || *text == 025 /* ^U */ ) { wmove(win->x_win, win->x_line, 0); wclrtoeol(win->x_win); getyx(win->x_win, win->x_line, win->x_col); text++; continue; } if (*text == '\f') { if (win == &my_win) wrefresh(curscr); text++; continue; } if (*text == '\7') { write(STDOUT_FILENO, text, 1); text++; continue; } if (!isprint((unsigned char)*text) && *text != '\t') { waddch(win->x_win, '^'); getyx(win->x_win, win->x_line, win->x_col); cch = (*text & 63) + 64; waddch(win->x_win, cch); } else waddch(win->x_win, (unsigned char)*text); getyx(win->x_win, win->x_line, win->x_col); text++; } wrefresh(win->x_win); }