FreeBSD/usr.bin/talk/display.c
/*
 * Display a symbol on somebody's window, processing some control
 * characters while we are at it.
 */
Display a symbol on somebody's window, processing some control
characters while we are at it.
Display a symbol on somebody ' s window processing some control characters while we are at it .
void
display(xwin_t *win, wchar_t *wc)
{
	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) {
			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;
	case 010:	
	case 0177:	
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:	
werase:
	    {
		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:	
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);
}
void display ( xwin_t * win , wchar_t * wc ) { 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 ) { 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 ; case 010 : case 0177 : 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 : werase : { 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 : 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 a symbol on somebody's window, processing some control
 characters while we are at it.
Display a symbol on somebody ' s window processing some control characters while we are at it .
/*
	 * Alas, can't use variables in C switch statement.
	 * Workaround these 3 cases with goto.
	 */ /* Ctrl-D clears the screen. */ /* Erase character. */ /* BS */ /* DEL */ /* ^W */ /*
		 * On word erase search backwards until we find
		 * the beginning of a word or the beginning of
		 * the line.
		 */ /* ^U */