XFree86 3.1.2Ec - xterm patch #21 - T.Dickey This patch does the following: + fixes some minor typography in the control-sequences documentation (it didn't occur to me til I'd sent the last patch that I could use ghostview for previewing the troff output ;-) + adjusts the shell's background color in ReverseVideo so that flicker in resizing is reduced + adds an ifdef OPT_ISO_COLORS to allow configuring xterm without the ISO color support (saves a lot of memory) + used that ifdef to isolate/modify logic so that if the user doesn't have the colorMode enabled, then ISO color support is disabled (saving memory). (If anyone needs numbers, I had savedLines set to 2000, and found a reduction from ~700k to ~400k of allocated memory, according to Purify). To do: + I think I've got a double-negative in the color sense (if the xterm is started in reverse video, and the application clears it, I get a "white" background when my modified vttest says it should be black -- I'll investigate). + time-permitting, implement ech/ech1 terminal capabilities, and protected characters. -------------------------------------------------------------------------------- doc/specs/xterm/ctlseqs.ms | 14 !!!! programs/xterm/charproc.c | 80 ++-!!!!!!!!!!!!!!!!!!!!!!! programs/xterm/ptyx.h | 31 +++++!!!!! programs/xterm/screen.c | 139 +++-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! programs/xterm/util.c | 49 ++-!!!!!!!!!!!!! programs/xterm/xterm.h | 34 ++++++++-! 6 files changed, 72 insertions, 10 deletions, 265 modifications -------------------------------------------------------------------------------- Index: ctlseqs.ms *** /build/x11r6/XFree86-960721/xc/doc/specs/xterm/ctlseqs.ms Wed Jul 24 21:03:44 1996 --- /build/x11r6/XFree86-current/xc/doc/specs/xterm/ctlseqs.ms Thu Jul 25 06:29:05 1996 *************** *** 415,432 **** \*(Ps = \*7 \(-> Refresh the xterm window. \*(Ps = \*8 ; \fIheight ; width\fP \(-> Resize the text area to [height;width] in characters. \*(Ps = \*1\*1 \(-> Report xterm window state. ! If the xterm window is open (non-iconified), it returns ``\*(Es [ 1 t''. ! If the xterm window is iconified, it returns ``\*(Es [ 2 t''. \*(Ps = \*1\*3 \(-> Report xterm window position as ! \*(Es [ 3 ; x ; y t \*(Ps = \*1\*4 \(-> Report xterm window in pixels as ! \*(Es\*s\*([[\*s\*4\*s\*;\*sheight\*s\*;\*swidth\*s\*t \*(Ps = \*1\*8 \(-> Report the size of the text area in characters as ! \*(Es\*s\*([[\*s\*8\*s\*;\*sheight\*s\*;\*swidth t \*(Ps = \*2\*0 \(-> Report xterm window's icon label as ! \*(Es\*s\*]\*s\*L\*slabel\*s\*(Es\*s\*(bS \*(Ps = \*2\*1 \(-> Report xterm window's title as ! \*(Es\*s\*]\*s\*l\*stitle\*s\*(Es\*s\*(bS .IP \\*(Es\\*([[\\*(Ps\\*s\\*x Request Terminal Parameters (DECREQTPARM) .IP \\*(Es\\*([[\\*?\\*(Pm\\*s\\*h --- 415,432 ---- \*(Ps = \*7 \(-> Refresh the xterm window. \*(Ps = \*8 ; \fIheight ; width\fP \(-> Resize the text area to [height;width] in characters. \*(Ps = \*1\*1 \(-> Report xterm window state. ! If the xterm window is open (non-iconified), it returns \*(Es\*([[\*1\*t. ! If the xterm window is iconified, it returns \*(Es\*([[\*2\*t. \*(Ps = \*1\*3 \(-> Report xterm window position as ! \*(Es\*([[\*3\*;\*(Ix\*;\*(Iy\*t \*(Ps = \*1\*4 \(-> Report xterm window in pixels as ! \*(Es\*s\*([[\*s\*4\*s\*;\*s\fIheight\fP\*s\*;\*s\fIwidth\fP\*s\*t \*(Ps = \*1\*8 \(-> Report the size of the text area in characters as ! \*(Es\*s\*([[\*s\*8\*s\*;\*s\fIheight\fP\*s\*;\*s\fIwidth\fP\*t \*(Ps = \*2\*0 \(-> Report xterm window's icon label as ! \*(Es\*s\*]\*s\*L\*s\fIlabel\fP\*s\*(Es\*s\*(bS \*(Ps = \*2\*1 \(-> Report xterm window's title as ! \*(Es\*s\*]\*s\*l\*s\fItitle\fP\*s\*(Es\*s\*(bS .IP \\*(Es\\*([[\\*(Ps\\*s\\*x Request Terminal Parameters (DECREQTPARM) .IP \\*(Es\\*([[\\*?\\*(Pm\\*s\\*h Index: charproc.c *** /build/x11r6/XFree86-960721/xc/programs/xterm/charproc.c Sun Jul 21 19:11:02 1996 --- /build/x11r6/XFree86-current/xc/programs/xterm/charproc.c Wed Jul 24 20:09:29 1996 *************** *** 586,591 **** --- 586,592 ---- XtOffsetOf(XtermWidgetRec, misc.open_im), XtRImmediate, (XtPointer)TRUE}, #endif + #if OPT_ISO_COLORS {XtNcolor0, XtCForeground, XtRPixel, sizeof(Pixel), XtOffsetOf(XtermWidgetRec, screen.Acolors[COLOR_0]), XtRString, "XtDefaultForeground"}, *************** *** 649,654 **** --- 650,656 ---- {XtNcolorBDMode, XtCColorMode, XtRBoolean, sizeof(Boolean), XtOffsetOf(XtermWidgetRec, screen.colorBDMode), XtRBoolean, (XtPointer) &defaultFALSE}, + #endif /* OPT_ISO_COLORS */ {XtNdynamicColors, XtCDynamicColors, XtRBoolean, sizeof(Boolean), XtOffsetOf(XtermWidgetRec, misc.dynamicColors), XtRBoolean, (XtPointer) &defaultTRUE}, *************** *** 709,714 **** --- 711,717 ---- WidgetClass xtermWidgetClass = (WidgetClass)&xtermClassRec; + #if OPT_ISO_COLORS /* * The terminal's foreground and background colors are set via two mechanisms: * text (cur_foreground, cur_background values that are passed down to *************** *** 754,759 **** --- 757,763 ---- XSetBackground(screen->display, screen->normalboldGC, bg); XSetForeground(screen->display, screen->reverseboldGC, bg); } + #endif /* OPT_ISO_COLORS */ static void VTparse() { *************** *** 1105,1139 **** switch (param[row]) { case DEFAULT: case 0: ! if (term->flags & FG_COLOR) SGR_Foreground(-1); ! if (term->flags & BG_COLOR) SGR_Background(-1); term->flags &= ~(INVERSE|BOLD|UNDERLINE); break; case 1: case 5: /* Blink, really. */ term->flags |= BOLD; ! if( screen->colorMode && ! screen->colorBDMode) { ! if (!(term->flags & FG_COLOR) || ! (term->cur_foreground==COLOR_UL)){ ! SGR_Foreground(COLOR_BD); } ! else /* Set highlight bit */ ! if (term->cur_foreground < 8) ! term->cur_foreground |= 8; ! } break; case 4: /* Underscore */ term->flags |= UNDERLINE; ! if( screen->colorMode && ! screen->colorULMode) { ! if (!(term->flags & FG_COLOR)) { ! SGR_Foreground(COLOR_UL); } ! } break; case 7: term->flags |= INVERSE; --- 1109,1147 ---- switch (param[row]) { case DEFAULT: case 0: ! if_OPT_ISO_COLORS(screen,{ ! if (term->flags & FG_COLOR) SGR_Foreground(-1); ! if (term->flags & BG_COLOR) SGR_Background(-1); + }) term->flags &= ~(INVERSE|BOLD|UNDERLINE); break; case 1: case 5: /* Blink, really. */ term->flags |= BOLD; ! if_OPT_ISO_COLORS(screen,{ ! if (screen->colorBDMode) { ! if (!(term->flags & FG_COLOR) || ! (term->cur_foreground==COLOR_UL)){ ! SGR_Foreground(COLOR_BD); ! } ! else /* Set highlight bit */ ! if (term->cur_foreground < 8) ! term->cur_foreground |= 8; } ! }) break; case 4: /* Underscore */ term->flags |= UNDERLINE; ! if_OPT_ISO_COLORS(screen,{ ! if (screen->colorULMode) { ! if (!(term->flags & FG_COLOR)) { ! SGR_Foreground(COLOR_UL); ! } } ! }) break; case 7: term->flags |= INVERSE; *************** *** 1159,1176 **** case 35: case 36: case 37: ! if( screen->colorMode ) { SGR_Foreground( (param[row] - 30) ! /* Set highlight bit if bold */ ! | ((term->flags & BOLD) ? 8 : 0)); ! } break; case 39: ! if( screen->colorMode ) { SGR_Foreground(-1); ! } break; case 40: case 41: --- 1167,1184 ---- case 35: case 36: case 37: ! if_OPT_ISO_COLORS(screen,{ SGR_Foreground( (param[row] - 30) ! /* Set highlight bit if bold */ ! | ((term->flags & BOLD) ? 8 : 0)); ! }) break; case 39: ! if_OPT_ISO_COLORS(screen,{ SGR_Foreground(-1); ! }) break; case 40: case 41: *************** *** 1180,1201 **** case 45: case 46: case 47: ! if( screen->colorMode ) { SGR_Background(param[row] - 40); ! } break; case 49: ! if( screen->colorMode ) { SGR_Background(-1); ! } break; case 100: ! if( screen->colorMode ) { if (term->flags & FG_COLOR) SGR_Foreground(-1); if (term->flags & BG_COLOR) SGR_Background(-1); ! } break; } } --- 1188,1209 ---- case 45: case 46: case 47: ! if_OPT_ISO_COLORS(screen,{ SGR_Background(param[row] - 40); ! }) break; case 49: ! if_OPT_ISO_COLORS(screen,{ SGR_Background(-1); ! }) break; case 100: ! if_OPT_ISO_COLORS(screen,{ if (term->flags & FG_COLOR) SGR_Foreground(-1); if (term->flags & BG_COLOR) SGR_Background(-1); ! }) break; } } *************** *** 2576,2582 **** register TScreen *screen; { register int rows = screen->max_row + 1; ! char *save [MAX_PTRS * MAX_ROWS]; Size_t len = MAX_PTRS * sizeof(char *) * rows; memcpy ( (char *)save, (char *)screen->buf, len); --- 2584,2590 ---- register TScreen *screen; { register int rows = screen->max_row + 1; ! char *save [4 /* MAX_PTRS */ * MAX_ROWS]; Size_t len = MAX_PTRS * sizeof(char *) * rows; memcpy ( (char *)save, (char *)screen->buf, len); *************** *** 2849,2858 **** new->screen.menu_font_names[fontMenu_fontsel] = NULL; new->screen.menu_font_number = fontMenu_fontdefault; new->screen.colorMode = request->screen.colorMode; new->screen.colorULMode = request->screen.colorULMode; new->screen.colorBDMode = request->screen.colorBDMode; - new->screen.underline = request->screen.underline; for (i = 0; i < MAXCOLORS; i++) { new->screen.Acolors[i] = request->screen.Acolors[i]; } --- 2857,2867 ---- new->screen.menu_font_names[fontMenu_fontsel] = NULL; new->screen.menu_font_number = fontMenu_fontdefault; + #if OPT_ISO_COLORS + new->num_ptrs = request->screen.colorMode ? 4 : 2; new->screen.colorMode = request->screen.colorMode; new->screen.colorULMode = request->screen.colorULMode; new->screen.colorBDMode = request->screen.colorBDMode; for (i = 0; i < MAXCOLORS; i++) { new->screen.Acolors[i] = request->screen.Acolors[i]; } *************** *** 2863,2868 **** --- 2872,2879 ---- new->screen.original_fg = request->screen.foreground; new->screen.original_bg = request->core.background_pixel; } + #endif /* OPT_ISO_COLORS */ + new->screen.underline = request->screen.underline; new->cur_foreground = 0; new->cur_background = 0; *************** *** 3378,3384 **** { register TScreen *screen = &term->screen; GC currentGC; ! register int x, y, flags, fg, bg; char c; Boolean in_selection; --- 3389,3395 ---- { register TScreen *screen = &term->screen; GC currentGC; ! register int x, y, flags, fg = 0, bg = 0; char c; Boolean in_selection; *************** *** 3387,3394 **** c = SCRN_BUF_CHARS(screen, screen->cursor_row)[screen->cursor_col]; flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[screen->cursor_col]; ! fg = SCRN_BUF_FORES(screen, screen->cursor_row)[screen->cursor_col]; ! bg = SCRN_BUF_BACKS(screen, screen->cursor_row)[screen->cursor_col]; if (screen->cursor_row > screen->endHRow || (screen->cursor_row == screen->endHRow && --- 3398,3408 ---- c = SCRN_BUF_CHARS(screen, screen->cursor_row)[screen->cursor_col]; flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[screen->cursor_col]; ! ! if_OPT_ISO_COLORS(screen,{ ! fg = SCRN_BUF_FORES(screen, screen->cursor_row)[screen->cursor_col]; ! bg = SCRN_BUF_BACKS(screen, screen->cursor_row)[screen->cursor_col]; ! }) if (screen->cursor_row > screen->endHRow || (screen->cursor_row == screen->endHRow && Index: ptyx.h *** /build/x11r6/XFree86-960721/xc/programs/xterm/ptyx.h Thu Jul 18 22:00:40 1996 --- /build/x11r6/XFree86-current/xc/programs/xterm/ptyx.h Wed Jul 24 20:09:29 1996 *************** *** 275,280 **** --- 275,287 ---- /***====================================================================***/ + #define OPT_ISO_COLORS 1 /* true if xterm is configured with ISO colors */ + + /***====================================================================***/ + + #if OPT_ISO_COLORS + #define if_OPT_ISO_COLORS(screen, code) if(screen->colorMode) code + #define TERM_COLOR_FLAGS (term->flags & (FG_COLOR|BG_COLOR)) #define MAXCOLORS 18 #define COLOR_0 0 #define COLOR_1 1 *************** *** 294,313 **** #define COLOR_15 15 #define COLOR_BD 16 #define COLOR_UL 17 ! ! #define MAX_PTRS 4 /* the number of pointers per row in 'ScrnBuf' */ /* ScrnBuf-level macros */ #define BUF_CHARS(buf, row) (buf[MAX_PTRS * (row) + 0]) #define BUF_ATTRS(buf, row) (buf[MAX_PTRS * (row) + 1]) #define BUF_FORES(buf, row) (buf[MAX_PTRS * (row) + 2]) #define BUF_BACKS(buf, row) (buf[MAX_PTRS * (row) + 3]) /* TScreen-level macros */ #define SCRN_BUF_CHARS(screen, row) BUF_CHARS(screen->buf, row) #define SCRN_BUF_ATTRS(screen, row) BUF_ATTRS(screen->buf, row) #define SCRN_BUF_FORES(screen, row) BUF_FORES(screen->buf, row) #define SCRN_BUF_BACKS(screen, row) BUF_BACKS(screen->buf, row) typedef struct { /* These parameters apply to both windows */ --- 301,335 ---- #define COLOR_15 15 #define COLOR_BD 16 #define COLOR_UL 17 ! #else ! #define if_OPT_ISO_COLORS(screen, code) /* nothing */ ! #define TERM_COLOR_FLAGS 0 ! #endif /* OPT_ISO_COLORS */ ! ! /* the number of pointers per row in 'ScrnBuf' */ ! #if OPT_ISO_COLORS ! #define MAX_PTRS term->num_ptrs ! #else ! #define MAX_PTRS 2 ! #endif /* ScrnBuf-level macros */ #define BUF_CHARS(buf, row) (buf[MAX_PTRS * (row) + 0]) #define BUF_ATTRS(buf, row) (buf[MAX_PTRS * (row) + 1]) + + #if OPT_ISO_COLORS #define BUF_FORES(buf, row) (buf[MAX_PTRS * (row) + 2]) #define BUF_BACKS(buf, row) (buf[MAX_PTRS * (row) + 3]) + #endif /* TScreen-level macros */ #define SCRN_BUF_CHARS(screen, row) BUF_CHARS(screen->buf, row) #define SCRN_BUF_ATTRS(screen, row) BUF_ATTRS(screen->buf, row) + + #if OPT_ISO_COLORS #define SCRN_BUF_FORES(screen, row) BUF_FORES(screen->buf, row) #define SCRN_BUF_BACKS(screen, row) BUF_BACKS(screen->buf, row) + #endif typedef struct { /* These parameters apply to both windows */ *************** *** 333,344 **** --- 355,368 ---- Pixel cursorcolor; /* Cursor color */ Pixel mousecolor; /* Mouse color */ Pixel mousecolorback; /* Mouse color background */ + #if OPT_ISO_COLORS Pixel Acolors[MAXCOLORS]; /* ANSI color emulation */ Pixel original_fg; /* reference for SGR reset fg */ Pixel original_bg; /* reference for SGR reset bg */ Boolean colorMode; /* are we using color mode? */ Boolean colorULMode; /* use color for underline? */ Boolean colorBDMode; /* use color for bold? */ + #endif int border; /* inner border */ Cursor arrow; /* arrow cursor */ unsigned short send_mouse_pos; /* user wants mouse transition */ *************** *** 570,575 **** --- 594,602 ---- unsigned flags; /* mode flags */ unsigned cur_foreground; /* current foreground color */ unsigned cur_background; /* current background color */ + #if OPT_ISO_COLORS + int num_ptrs; /* number of pointers per row in 'ScrnBuf' */ + #endif unsigned initflags; /* initial mode flags */ Tabs tabs; /* tabstops of the terminal */ Misc misc; /* miscellaneous parameters */ Index: screen.c *** /build/x11r6/XFree86-960721/xc/programs/xterm/screen.c Sun Jul 21 19:11:02 1996 --- /build/x11r6/XFree86-current/xc/programs/xterm/screen.c Wed Jul 24 20:09:29 1996 *************** *** 129,135 **** register Size_t mincols; Char *oldbuf; int move_down = 0, move_up = 0; ! if (sbuf == NULL || *sbuf == NULL) return 0; --- 129,135 ---- register Size_t mincols; Char *oldbuf; int move_down = 0, move_up = 0; ! if (sbuf == NULL || *sbuf == NULL) return 0; *************** *** 206,212 **** register unsigned cur_fg, cur_bg; register int length; /* length of string */ { ! register Char *attrs, *attrs0, *fgs, *bgs; register int avail = screen->max_col - screen->cur_col + 1; register Char *col; register int wrappedbit; --- 206,215 ---- register unsigned cur_fg, cur_bg; register int length; /* length of string */ { ! #if OPT_ISO_COLORS ! register Char *fgs = 0, *bgs = 0; ! #endif ! register Char *attrs; register int avail = screen->max_col - screen->cur_col + 1; register Char *col; register int wrappedbit; *************** *** 218,236 **** col = SCRN_BUF_CHARS(screen, screen->cur_row) + screen->cur_col; attrs = SCRN_BUF_ATTRS(screen, screen->cur_row) + screen->cur_col; - fgs = SCRN_BUF_FORES(screen, screen->cur_row) + screen->cur_col; - bgs = SCRN_BUF_BACKS(screen, screen->cur_row) + screen->cur_col; ! attrs0 = attrs; ! wrappedbit = *attrs0&LINEWRAPPED; flags &= ATTRIBUTES; flags |= CHARDRAWN; memcpy( col, str, length); memset( attrs, flags, length); ! memset( fgs, cur_fg, length); ! memset( bgs, cur_bg, length); if (wrappedbit) ! *attrs0 |= LINEWRAPPED; } static void --- 221,245 ---- col = SCRN_BUF_CHARS(screen, screen->cur_row) + screen->cur_col; attrs = SCRN_BUF_ATTRS(screen, screen->cur_row) + screen->cur_col; ! if_OPT_ISO_COLORS(screen,{ ! fgs = SCRN_BUF_FORES(screen, screen->cur_row) + screen->cur_col; ! bgs = SCRN_BUF_BACKS(screen, screen->cur_row) + screen->cur_col; ! }) ! ! wrappedbit = *attrs & LINEWRAPPED; flags &= ATTRIBUTES; flags |= CHARDRAWN; memcpy( col, str, length); memset( attrs, flags, length); ! ! if_OPT_ISO_COLORS(screen,{ ! memset( fgs, cur_fg, length); ! memset( bgs, cur_bg, length); ! }) ! if (wrappedbit) ! *attrs |= LINEWRAPPED; } static void *************** *** 250,258 **** MAX_PTRS * sizeof(char *) * n); /* clear contents of old rows */ ! if (term->flags & (FG_COLOR|BG_COLOR)) { int last = (n * MAX_PTRS); ! int flags = (term->flags & (FG_COLOR|BG_COLOR)); for (i = 0; i < last; i += MAX_PTRS) { bzero(save[i+0], size); memset(save[i+1], flags, size); --- 259,267 ---- MAX_PTRS * sizeof(char *) * n); /* clear contents of old rows */ ! if (TERM_COLOR_FLAGS) { int last = (n * MAX_PTRS); ! int flags = TERM_COLOR_FLAGS; for (i = 0; i < last; i += MAX_PTRS) { bzero(save[i+0], size); memset(save[i+1], flags, size); *************** *** 277,283 **** int last; register int where, n, size; { ! char *save [MAX_PTRS * MAX_ROWS]; /* save n lines at bottom */ ScrnClearLines(save, sb, (last -= n - 1), n, size); --- 286,292 ---- int last; register int where, n, size; { ! char *save [4 /* MAX_PTRS */ * MAX_ROWS]; /* save n lines at bottom */ ScrnClearLines(save, sb, (last -= n - 1), n, size); *************** *** 313,319 **** register int n, last, size; int where; { ! char *save [MAX_PTRS * MAX_ROWS]; ScrnClearLines(save, sb, where, n, size); --- 322,328 ---- register int n, last, size; int where; { ! char *save [4 /* MAX_PTRS */ * MAX_ROWS]; ScrnClearLines(save, sb, where, n, size); *************** *** 329,347 **** } void ! ScrnInsertChar (sb, row, col, n, size) /* ! Inserts n blanks in sb at row, col. Size is the size of each row. ! */ ! ScrnBuf sb; ! int row, size; ! register int col, n; { register int i, j; register Char *ptr = BUF_CHARS(sb, row); register Char *attrs = BUF_ATTRS(sb, row); int wrappedbit = attrs[0]&LINEWRAPPED; ! int flags = CHARDRAWN | (term->flags & (FG_COLOR|BG_COLOR)); attrs[0] &= ~LINEWRAPPED; /* make sure the bit isn't moved */ for (i = size - 1; i >= col + n; i--) { --- 338,360 ---- } void ! ScrnInsertChar (screen, n, size) /* ! * Inserts n blanks in screen at current row, col. Size is the size of each ! * row. ! */ ! register TScreen *screen; ! register int n; ! int size; { + ScrnBuf sb = screen->buf; + int row = screen->cur_row; + int col = screen->cur_col; register int i, j; register Char *ptr = BUF_CHARS(sb, row); register Char *attrs = BUF_ATTRS(sb, row); int wrappedbit = attrs[0]&LINEWRAPPED; ! int flags = CHARDRAWN | TERM_COLOR_FLAGS; attrs[0] &= ~LINEWRAPPED; /* make sure the bit isn't moved */ for (i = size - 1; i >= col + n; i--) { *************** *** 353,376 **** ptr[i] = ' '; for (i=col; i