xterm-35.patch.txt

XFree86 3.2o - xterm patch #35 - 1997/1/7 - T.Dickey <dickey@clark.net>
 
This patch does the following:
 
        + combines the coding for foreground and background colors into a
          single byte, reducing the memory required to store saved-lines in
          color.  (I'll take back that byte in a following patch to use to
          ensure the character-set, so there's no long-term decrease in memory
          use).
 
        + modifies the PF1-PF4 coding in termcap/terminfo.  Because xterm is
          still by default emulating vt100, the function key codes are
          vt100-compatible (I overlooked this in patch #31).
 
          I also reformatted the whole terminfo file into a single-column,
          for consistency.
 
        + adds an interim xterm-vt220 description to accommodate the old and new
          styles of function-keys (though probably it'd be better to drop the
          old-style altogether).
 
--------------------------------------------------------------------------------
 charproc.c |  180 +++++++++++++++++++-----------------------------
 ptyx.h     |    7 -
 screen.c   |   46 ++++--------
 termcap    |    5 +
 terminfo   |  220 +++++++++++++++++++++++++++++++++++++++++++++--------------
 util.c     |   58 ++++++++++++++-
 xterm.h    |    7 +
 7 files changed, 325 insertions, 198 deletions
--------------------------------------------------------------------------------
Index: charproc.c
--- xterm-34+/charproc.c        Sun Jan  5 17:05:03 1997
+++ xterm-35/charproc.c Tue Jan  7 18:30:56 1997
@@ -131,12 +131,12 @@
 static void VTNonMaskableEvent PROTO_XT_EV_HANDLER_ARGS;
 static void VTallocbuf PROTO((void));
 static void VTparse PROTO((void));
-static void WriteText PROTO(( TScreen *screen, char *str, int len, unsigned flags, unsigned fg, unsigned bg));
+static void WriteText PROTO(( TScreen *screen, char *str, int len));
 static void ansi_modes PROTO((XtermWidget termw, void (*func)(unsigned *p, unsigned mask)));
 static void bitclr PROTO((unsigned *p, unsigned mask));
 static void bitcpy PROTO((unsigned *p, unsigned q, unsigned mask));
 static void bitset PROTO((unsigned *p, unsigned mask));
-static void dotext PROTO((TScreen *screen, unsigned flags, int charset, Char *buf, Char *ptr, unsigned fg, unsigned bg));
+static void dotext PROTO((TScreen *screen, int charset, Char *buf, Char *ptr));
 static void dpmodes PROTO((XtermWidget termw, void (*func)(unsigned *p, unsigned mask)));
 static void report_win_label PROTO((TScreen *screen, int code, XTextProperty *text, Status ok));
 static void restoremodes PROTO((XtermWidget termw));
@@ -157,11 +157,9 @@
 #endif
 
 #if OPT_ISO_COLORS
-static void clrColorBD PROTO((void));
-static void clrColorUL PROTO((void));
-static void setColorBD PROTO((void));
-static void setColorUL PROTO((void));
-static void resetColor PROTO((void));
+static void setExtendedFG PROTO((void));
+static void reset_SGR_Colors PROTO((void));
+static void reset_SGR_Foreground PROTO((void));
 #endif
 
 #define        DEFAULT         -1
@@ -305,8 +303,11 @@
 static ANSI reply;
 static int param[NPARAM];
 
+#ifdef UNUSED
 static unsigned long ctotal;
 static unsigned long ntotal;
+#endif
+
 static jmp_buf vtjmpbuf;
 
 /* event handlers */
@@ -815,63 +816,40 @@
        XSetForeground(screen->display, ReverseBoldGC(screen), bg);
 }
 
+/* Invoked after updating bold/underline flags, computes the extended color
+ * index to use for foreground.
+ */
 static void
-setColorBD()
+setExtendedFG()
 {
-       if (term->screen.colorBDMode) {
-               if (!(term->flags & FG_COLOR)
-                || (term->cur_foreground == COLOR_UL)) {
-                       SGR_Foreground(COLOR_BD);
-               } else if (term->cur_foreground < 8) { /* Set highlight bit */
-                       SGR_Foreground(term->cur_foreground | 8);
-               }
-       }
-}
+       int fg = term->sgr_foreground;
 
-static void
-clrColorBD()
-{
-       if (term->screen.colorBDMode
-        && term->flags & BOLD
-        && !(term->flags & FG_COLOR)) {
-               if (term->cur_foreground == COLOR_BD)
-                       SGR_Foreground(-1);
-               else if ((term->cur_foreground >= 8)
-                  &&    (term->cur_foreground <= 15))
-                       SGR_Foreground(term->cur_foreground & 7);
+       if (fg < 0) {
+               if (term->screen.colorULMode && (term->flags & UNDERLINE))
+                       fg = COLOR_UL;
+
+               if (term->screen.colorBDMode && (term->flags & BOLD))
+                       fg = COLOR_BD;
        }
-}
 
-static void
-setColorUL()
-{
-       if (term->screen.colorULMode
-        && !(term->flags & FG_COLOR))
-               SGR_Foreground(COLOR_UL);
+       if ((fg >= 0) && (fg < 8) && (term->flags & BOLD))
+               fg |= 8;
+
+       SGR_Foreground(fg);
 }
 
 static void
-clrColorUL()
+reset_SGR_Foreground()
 {
-       if (term->screen.colorULMode
-        && term->cur_foreground == COLOR_UL) {
-               if (term->screen.colorBDMode
-                && (term->flags & BOLD))
-                       SGR_Foreground(COLOR_BD);
-               else
-                       SGR_Foreground(-1);
-       }
+       term->sgr_foreground = -1;
+       setExtendedFG();
 }
 
 static void
-resetColor()
+reset_SGR_Colors()
 {
-       clrColorBD(); /* first */
-       clrColorUL(); /* second */
-       if (term->flags & FG_COLOR)
-               SGR_Foreground(-1);
-       if (term->flags & BG_COLOR)
-               SGR_Background(-1);
+       reset_SGR_Foreground();
+       SGR_Background(-1);
 }
 #endif /* OPT_ISO_COLORS */
 
@@ -976,20 +954,16 @@
                        }
                        if(screen->curss) {
                                thischar = *bptr;
-                               dotext(screen, term->flags,
+                               dotext(screen,
                                 screen->gsets[(int)(screen->curss)],
-                                       bptr, bptr + 1,
-                                       term->cur_foreground,
-                                       term->cur_background );
+                                       bptr, bptr + 1);
                                screen->curss = 0;
                        }
                        if(bptr < cp) {
                                thischar = cp[-1];
-                               dotext(screen, term->flags,
+                               dotext(screen,
                                 screen->gsets[(int)(screen->curgl)],
-                                       bptr, cp,
-                                       term->cur_foreground,
-                                       term->cur_background );
+                                       bptr, cp);
                        }
                        bptr = cp;
                        break;
@@ -1412,17 +1386,17 @@
                                 case 0:
                                        term->flags &=
                                                ~(INVERSE|BOLD|UNDERLINE|INVISIBLE);
-                                       if_OPT_ISO_COLORS(screen,{resetColor();})
+                                       if_OPT_ISO_COLORS(screen,{reset_SGR_Colors();})
                                        break;
                                 case 1:        /* Bold                         */
                                        /* FALLTHRU */
                                 case 5:        /* Blink, really.       */
                                        term->flags |= BOLD;
-                                       if_OPT_ISO_COLORS(screen,{setColorBD();})
+                                       if_OPT_ISO_COLORS(screen,{setExtendedFG();})
                                        break;
                                 case 4:        /* Underscore           */
                                        term->flags |= UNDERLINE;
-                                       if_OPT_ISO_COLORS(screen,{setColorUL();})
+                                       if_OPT_ISO_COLORS(screen,{setExtendedFG();})
                                        break;
                                 case 7:
                                        term->flags |= INVERSE;
@@ -1431,14 +1405,14 @@
                                        term->flags |= INVISIBLE;
                                        break;
                                 case 24:
-                                       if_OPT_ISO_COLORS(screen,{clrColorUL();})
                                        term->flags &= ~UNDERLINE;
+                                       if_OPT_ISO_COLORS(screen,{setExtendedFG();})
                                        break;
                                 case 22: /* reset 'bold' */
                                        /* FALLTHRU */
                                 case 25: /* reset 'blink' */
-                                       if_OPT_ISO_COLORS(screen,{clrColorBD();})
                                        term->flags &= ~BOLD;
+                                       if_OPT_ISO_COLORS(screen,{setExtendedFG();})
                                        break;
                                 case 27:
                                        term->flags &= ~INVERSE;
@@ -1455,16 +1429,13 @@
                                 case 36:
                                 case 37:
                                        if_OPT_ISO_COLORS(screen,{
-                                         SGR_Foreground(
-                                               (param[row] - 30)
-                                               /* Set highlight bit if bold */
-                                               | ((term->flags & BOLD)
-                                                 ? 8 : 0));
+                                         term->sgr_foreground = (param[row] - 30);
+                                         setExtendedFG();
                                        })
                                        break;
                                 case 39:
                                        if_OPT_ISO_COLORS(screen,{
-                                         SGR_Foreground(-1);
+                                         reset_SGR_Foreground();
                                        })
                                        break;
                                 case 40:
@@ -1486,10 +1457,8 @@
                                        break;
                                 case 100:
                                        if_OPT_ISO_COLORS(screen,{
-                                         if (term->flags & FG_COLOR)
-                                           SGR_Foreground(-1);
-                                         if (term->flags & BG_COLOR)
-                                           SGR_Background(-1);
+                                         reset_SGR_Foreground();
+                                         SGR_Background(-1);
                                        })
                                        break;
                                }
@@ -1654,12 +1623,7 @@
                 case CASE_DECRC:
                        /* DECRC */
                        CursorRestore(term, &screen->sc);
-                       if_OPT_ISO_COLORS(screen,{
-                               if (term->flags & BOLD)
-                                       setColorBD();
-                               if (term->flags & UNDERLINE)
-                                       setColorUL();
-                       })
+                       if_OPT_ISO_COLORS(screen,{setExtendedFG();})
                        parsestate = groundtable;
                        break;
 
@@ -1921,11 +1885,9 @@
                            count = (param[0] < 1) ? 1 : param[0];
                            repeated[0] = lastchar;
                            while (count-- > 0) {
-                               dotext(screen, term->flags,
+                               dotext(screen,
                                        screen->gsets[(int)(screen->curgl)],
-                                       repeated, repeated+1,
-                                       term->cur_foreground,
-                                       term->cur_background );
+                                       repeated, repeated+1);
                            }
                        }
                        parsestate = groundtable;
@@ -2312,9 +2274,8 @@
  * by charset.  worry about end of line conditions (wraparound if selected).
  */
 static void
-dotext(screen, flags, charset, buf, ptr, fg, bg )
+dotext(screen, charset, buf, ptr)
     register TScreen   *screen;
-    unsigned   flags, fg, bg;
     char       charset;
     Char       *buf;           /* start of characters to process */
     Char       *ptr;           /* end */
@@ -2351,7 +2312,7 @@
        while (len > 0) {
                n = screen->max_col - screen->cur_col +1;
                if (n <= 1) {
-                       if (screen->do_wrap && (flags&WRAPAROUND)) {
+                       if (screen->do_wrap && (term->flags & WRAPAROUND)) {
                            /* mark that we had to wrap this line */
                            ScrnSetAttributes(screen, screen->cur_row, 0,
                                              LINEWRAPPED, LINEWRAPPED, 1);
@@ -2365,7 +2326,9 @@
                if (len < n)
                        n = len;
                next_col = screen->cur_col + n;
-               WriteText(screen, (char *)ptr, n, flags, fg, bg );
+
+               WriteText(screen, (char *)ptr, n);
+
                /*
                 * the call to WriteText updates screen->cur_col.
                 * If screen->cur_col != next_col, we must have
@@ -2382,20 +2345,21 @@
  * the current cursor position.  update cursor position.
  */
 static void
-WriteText(screen, str, len, flags, fg, bg )
+WriteText(screen, str, len)
     register TScreen   *screen;
     register char      *str;
     register int       len;
-    unsigned           flags, fg, bg;
 {
-       register unsigned fgs = flags;
+       unsigned flags  = term->flags;
+       unsigned fg     = term->cur_foreground;
+       unsigned bg     = term->cur_background;
        GC      currentGC;
  
        if(screen->cur_row - screen->topline <= screen->max_row) {
                if(screen->cursor_state)
                        HideCursor();
 
-               if (fgs & INSERT)
+               if (flags & INSERT)
                        InsertChar(screen, len);
                if (!(AddToRefresh(screen))) {
                        /* make sure that the correct GC is current */
@@ -2404,24 +2368,26 @@
                        if(screen->scroll_amt)
                                FlushScroll(screen);
 
-                       if (fgs & INVISIBLE)
+                       if (flags & INVISIBLE)
                                memset(str, ' ', len);
 
-                       drawXtermText(screen, fgs, currentGC,
+                       drawXtermText(screen, flags, currentGC,
                                CursorX(screen, screen->cur_col),
-                               CursorY(screen, screen->cur_row)
-                                       + screen->fnt_norm->ascent,
+                               CursorY(screen, screen->cur_row),
                                str, len);
 
+                       resetXtermGC(screen, flags, False);
+
                        /*
                         * The following statements compile data to compute the
                         * average number of characters written on each call to
                         * XText.  The data may be examined via the use of a
                         * "hidden" escape sequence.
                         */
+#ifdef UNUSED
                        ctotal += len;
                        ++ntotal;
-                       resetXtermGC(screen, flags, False);
+#endif
                }
        }
        ScreenWrite(screen, str, flags,  fg, bg, len);
@@ -3446,7 +3412,8 @@
    if (!color_ok)
        new->screen.colorMode = False;
 
-   new->num_ptrs = new->screen.colorMode ? 4 : 2;
+   new->num_ptrs = new->screen.colorMode ? 3 : 2;
+   new->sgr_foreground = -1;
 #endif /* OPT_ISO_COLORS */
    new->screen.underline = request->screen.underline;
 
@@ -4012,13 +3979,12 @@
 
        drawXtermText(screen, flags, currentGC,
                x = CursorX(screen, screen->cur_col),
-               y = CursorY(screen, screen->cur_row) + 
-                       screen->fnt_norm->ascent,
+               y = CursorY(screen, screen->cur_row),
                (char *) &c, 1);
 
        if (!screen->select && !screen->always_highlight) {
                screen->box->x = x;
-               screen->box->y = y - screen->fnt_norm->ascent;
+               screen->box->y = y;
                XDrawLines (screen->display, TextWindow(screen), 
                            screen->cursoroutlineGC ? screen->cursoroutlineGC 
                                                    : currentGC,
@@ -4046,8 +4012,9 @@
        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];
+           unsigned fb = SCRN_BUF_COLOR(screen, screen->cursor_row)[screen->cursor_col];
+           fg = extract_fg(fb, flags);
+           bg = extract_bg(fb);
        })
 
 #ifndef NO_ACTIVE_ICON
@@ -4075,8 +4042,7 @@
 
        drawXtermText(screen, flags, currentGC,
                CursorX(screen, screen->cursor_col),
-               CursorY(screen, screen->cursor_row)
-                       + screen->fnt_norm->ascent,
+               CursorY(screen, screen->cursor_row),
                &c, 1);
 
        screen->cursor_state = OFF;
@@ -4163,7 +4129,7 @@
 
        bitclr(&term->flags, ORIGIN);
 
-       if_OPT_ISO_COLORS(screen,{ resetColor(); })
+       if_OPT_ISO_COLORS(screen,{reset_SGR_Colors();})
 
        /* Reset character-sets to initial state */
        resetCharsets(screen);
@@ -4219,7 +4185,7 @@
                term->keyboard.flags &= ~(MODE_DECCKM);
                bitcpy(&term->flags, term->initflags, WRAPAROUND|REVERSEWRAP);
                bitclr(&term->flags, INSERT|INVERSE|BOLD|UNDERLINE|INVISIBLE);
-               if_OPT_ISO_COLORS(screen,{resetColor();})
+               if_OPT_ISO_COLORS(screen,{reset_SGR_Colors();})
                update_appcursor();
                update_autowrap();
                update_reversewrap();
Index: ptyx.h
--- xterm-34+/ptyx.h    Sun Jan  5 16:06:15 1997
+++ xterm-35/ptyx.h     Tue Jan  7 18:25:49 1997
@@ -336,8 +336,7 @@
 #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])
+#define BUF_COLOR(buf, row) (buf[MAX_PTRS * (row) + 2])
 #endif
 
        /* TScreen-level macros */
@@ -345,8 +344,7 @@
 #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)
+#define SCRN_BUF_COLOR(screen, row) BUF_COLOR(screen->buf, row)
 #endif
 
 typedef struct {
@@ -636,6 +634,7 @@
     unsigned    cur_foreground;        /* current foreground color     */
     unsigned    cur_background;        /* current background color     */
 #if OPT_ISO_COLORS
+    unsigned    sgr_foreground;        /* current SGR foreground color */
     int         num_ptrs;      /* number of pointers per row in 'ScrnBuf' */
 #endif
     unsigned   initflags;      /* initial mode flags           */
Index: screen.c
--- xterm-34+/screen.c  Fri Dec 27 03:01:57 1996
+++ xterm-35/screen.c   Tue Jan  7 18:26:47 1997
@@ -207,7 +207,7 @@
 register int length;           /* length of string */
 {
 #if OPT_ISO_COLORS
-       register Char *fgs = 0, *bgs = 0;
+       register Char *fb = 0;
 #endif
        register Char *attrs;
        register int avail  = screen->max_col - screen->cur_col + 1;
@@ -223,8 +223,7 @@
        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;
+               fb = SCRN_BUF_COLOR(screen, screen->cur_row) + screen->cur_col;
        })
 
        wrappedbit = *attrs & LINEWRAPPED;
@@ -241,8 +240,7 @@
        memset( attrs, flags,  length);
 
        if_OPT_ISO_COLORS(screen,{
-               memset( fgs,   cur_fg, length);
-               memset( bgs,   cur_bg, length);
+               memset( fb,   makeColorPair(cur_fg, cur_bg), length);
        })
 
        if (wrappedbit)
@@ -272,8 +270,7 @@
                for (i = 0; i < last; i += MAX_PTRS) {
                        bzero(save[i+0], size);
                        memset(save[i+1], flags, size);
-                       memset(save[i+2], term->cur_foreground, size);
-                       memset(save[i+3], term->cur_background, size);
+                       memset(save[i+2], xtermColorPair(), size);
                }
        } else {
                for (i = MAX_PTRS * n - 1 ; i >= 0 ; i--)
@@ -374,10 +371,7 @@
        for (i=col; i<col+n; i++)
            attrs[i] = flags;
        if_OPT_ISO_COLORS(screen,{
-           if (flags & FG_COLOR)
-               memset(BUF_FORES(sb, row) + col, term->cur_foreground, n);
-           if (flags & BG_COLOR)
-               memset(BUF_BACKS(sb, row) + col, term->cur_background, n);
+           memset(BUF_COLOR(sb, row) + col, xtermColorPair(), n);
        })
 
        if (wrappedbit)
@@ -407,10 +401,7 @@
        memset (attrs + size - n, TERM_COLOR_FLAGS, n);
 
        if_OPT_ISO_COLORS(screen,{
-           if (term->flags & FG_COLOR)
-               memset(BUF_FORES(sb, row) + size - n, term->cur_foreground, n);
-           if (term->flags & BG_COLOR)
-               memset(BUF_BACKS(sb, row) + size - n, term->cur_background, n);
+           memset(BUF_COLOR(sb, row) + size - n, xtermColorPair(), n);
        })
        if (wrappedbit)
            attrs[0] |= LINEWRAPPED;
@@ -428,8 +419,7 @@
 int toprow, leftcol, nrows, ncols;
 Boolean force;                 /* ... leading/trailing spaces */
 {
-       int y = toprow * FontHeight(screen) + screen->border +
-               FontAscent(screen);
+       int y = toprow * FontHeight(screen) + screen->border;
        register int row;
        register int topline = screen->topline;
        int maxrow = toprow + nrows - 1;
@@ -443,7 +433,7 @@
                screen->cursor_state = OFF;
        for (row = toprow; row <= maxrow; y += FontHeight(screen), row++) {
 #if OPT_ISO_COLORS
-          register Char *fgs = 0, *bgs = 0;
+          register Char *fb = 0;
 #endif
           register Char *chars;
           register Char *attrs;
@@ -468,8 +458,7 @@
           attrs = SCRN_BUF_ATTRS(screen, lastind + topline);
 
           if_OPT_ISO_COLORS(screen,{
-                  fgs = SCRN_BUF_FORES(screen, lastind + topline);
-                  bgs = SCRN_BUF_BACKS(screen, lastind + topline);
+                  fb = SCRN_BUF_COLOR(screen, lastind + topline);
           })
 
           if (row < screen->startHRow || row > screen->endHRow ||
@@ -530,8 +519,8 @@
 
           flags = attrs[col];
           if_OPT_ISO_COLORS(screen,{
-               fg = fgs[col];
-               bg = bgs[col];
+               fg = extract_fg(fb[col], flags);
+               bg = extract_bg(fb[col]);
           })
           gc = updatedXtermGC(screen, flags, fg, bg, hilite);
           gc_changes |= (flags & (FG_COLOR|BG_COLOR));
@@ -542,8 +531,8 @@
           for (; col <= maxcol; col++) {
                if ((attrs[col] != flags)
 #if OPT_ISO_COLORS
-                || ((flags & FG_COLOR) && (fgs[col] != fg))
-                || ((flags & BG_COLOR) && (bgs[col] != bg))
+                || ((flags & FG_COLOR) && (extract_fg(fb[col],attrs[col]) != fg))
+                || ((flags & BG_COLOR) && (extract_bg(fb[col]) != bg))
 #endif
                 ) {
                   drawXtermText(screen, flags, gc, x, y,
@@ -555,8 +544,8 @@
 
                   flags = attrs[col];
                   if_OPT_ISO_COLORS(screen,{
-                       fg = fgs[col];
-                       bg = bgs[col];
+                       fg = extract_fg(fb[col], flags);
+                       bg = extract_bg(fb[col]);
                   })
                   gc = updatedXtermGC(screen, flags, fg, bg, hilite);
                   gc_changes |= (flags & (FG_COLOR|BG_COLOR));
@@ -601,10 +590,7 @@
            bzero (BUF_CHARS(buf, row), len);
            memset(BUF_ATTRS(buf, row), flags, len);
            if_OPT_ISO_COLORS(screen,{
-               memset(BUF_FORES(buf, row), 
-                       (flags & FG_COLOR) ? term->cur_foreground : 0, len);
-               memset(BUF_BACKS(buf, row), 
-                       (flags & BG_COLOR) ? term->cur_background : 0, len);
+               memset(BUF_COLOR(buf, row), xtermColorPair(), len);
            })
        }
 }
Index: termcap
--- xterm-34+/termcap   Sat Dec 28 11:36:20 1996
+++ xterm-35/termcap    Tue Jan  7 18:27:15 1997
@@ -21,7 +21,7 @@
        :ho=\E[H:\
        :im=\E[4h:ei=\E[4l:mi:\
        :ks=\E[?1h\E=:ke=\E[?1l\E>:\
-       :k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:\
+       :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\
        :k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:\
        :k;=\E[21~:F1=\E[23~:F2=\E[24~:\
        :kn#12:\
@@ -51,6 +51,9 @@
        :F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:\
        :kn#20:\
        :st@:ut@:Co@:NC@:op@:AB@:AF@:pa@:Sf@:Sb@:tc=xterm:
+xterm-vt220|xterm emulating vt220:\
+       :k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:\
+       :tc=xterm:
 #
 # vi may work better with this entry, because vi
 # doesn't use insert mode much
Index: terminfo
--- xterm-34+/terminfo  Sun Nov 24 11:02:48 1996
+++ xterm-35/terminfo   Tue Jan  7 18:25:49 1997
@@ -11,7 +11,7 @@
        xenl,
        colors#8,
        cols#80,
-       it#8, 
+       it#8,
        lines#24,
        pairs#64,
        acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
@@ -66,7 +66,7 @@
        kdch1=\177,
        kend=\EOF,
        kent=\EOM,
-       kf1=\E[11~,
+       kf1=\EOP,
        kf10=\E[21~,
        kf11=\E[23~,
        kf12=\E[24~,
@@ -77,10 +77,10 @@
        kf17=\E[31~,
        kf18=\E[32~,
        kf19=\E[33~,
-       kf2=\E[12~,
+       kf2=\EOQ,
        kf20=\E[34~,
-       kf3=\E[13~,
-       kf4=\E[14~,
+       kf3=\EOR,
+       kf4=\EOS,
        kf5=\E[15~,
        kf6=\E[17~,
        kf7=\E[18~,
@@ -157,64 +157,180 @@
        smir@,
        use=xterm,
 #
+xterm-vt220|xterm emulating vt220,
+       kf1=\E[11~,
+       kf2=\E[12~,
+       kf3=\E[13~,
+       kf4=\E[14~,
+       use=xterm,
+#
 xterm-rep|xterm with repeat-character control,
        rep=%p1%c\E[%p2%{1}%-%db,
        use=xterm,
 #
 # Compatible with the R6 xterm
 xterm-r6|xterm-old|xterm X11R6 version,
-       is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
-       rs2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
-       am, bel=^G,
-       cols#80, lines#24,
-       clear=\E[H\E[2J, cup=\E[%i%p1%d;%p2%dH,
-       csr=\E[%i%p1%d;%p2%dr,
-       cud=\E[%p1%dB, cud1=\n, cuu=\E[%p1%dA, cuu1=\E[A,
-       cub=\E[%p1%dD, cub1=\b, cuf=\E[%p1%dC, cuf1=\E[C,
-       el=\E[K, ed=\E[J,
-       home=\E[H, ht=^I, ind=^J, cr=^M,
+       am,
        km,
-       smir=\E[4h, rmir=\E[4l, mir,
-       smso=\E[7m, rmso=\E[m, smul=\E[4m, rmul=\E[m,
-       bold=\E[1m, rev=\E[7m, blink@, sgr0=\E[m, msgr,
-       enacs=\E)0, smacs=^N, rmacs=^O,
-       smkx=\E[?1h\E=, rmkx=\E[?1l\E>,
-       kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS,
-       kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
+       mir,
+       msgr,
+       xenl,
+       cols#80,
+       lines#24,
+       bel=^G,
+       blink@,
+       bold=\E[1m,
+       clear=\E[H\E[2J,
+       cr=^M,
+       csr=\E[%i%p1%d;%p2%dr,
+       cub=\E[%p1%dD,
+       cub1=^H,
+       cud=\E[%p1%dB,
+       cud1=^J,
+       cuf=\E[%p1%dC,
+       cuf1=\E[C,
+       cup=\E[%i%p1%d;%p2%dH,
+       cuu=\E[%p1%dA,
+       cuu1=\E[A,
+       dch=\E[%p1%dP,
+       dch1=\E[P,
+       dl=\E[%p1%dM,
+       dl1=\E[M,
+       ed=\E[J,
+       el=\E[K,
+       enacs=\E)0,
+       home=\E[H,
+       ht=^I,
+       il=\E[%p1%dL,
+       il1=\E[L,
+       ind=^J,
+       is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
+       kbs=^H,
+       kcub1=\EOD,
+       kcud1=\EOB,
+       kcuf1=\EOC,
+       kcuu1=\EOA,
+       kdch1=\E[3~,
+       kf1=\EOP,
        kf10=\E[21~,
-       kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
-       kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~, kf20=\E[34~,
-       kfnd=\E[1~, kich1=\E[2~, kdch1=\E[3~,
-       kslt=\E[4~, kpp=\E[5~, knp=\E[6~,
-       kbs=\b, kcuu1=\EOA, kcud1=\EOB, kcuf1=\EOC, kcub1=\EOD,
-       meml=\El, memu=\Em,
-       smcup=\E7\E[?47h, rmcup=\E[2J\E[?47l\E8,
-       sc=\E7, rc=\E8,
-       il=\E[%p1%dL, dl=\E[%p1%dM, il1=\E[L, dl1=\E[M,
+       kf11=\E[23~,
+       kf12=\E[24~,
+       kf13=\E[25~,
+       kf14=\E[26~,
+       kf15=\E[28~,
+       kf16=\E[29~,
+       kf17=\E[31~,
+       kf18=\E[32~,
+       kf19=\E[33~,
+       kf2=\EOQ,
+       kf20=\E[34~,
+       kf3=\EOR,
+       kf4=\EOS,
+       kf5=\E[15~,
+       kf6=\E[17~,
+       kf7=\E[18~,
+       kf8=\E[19~,
+       kf9=\E[20~,
+       kfnd=\E[1~,
+       kich1=\E[2~,
+       knp=\E[6~,
+       kpp=\E[5~,
+       kslt=\E[4~,
+       meml=\El,
+       memu=\Em,
+       rc=\E8,
+       rev=\E[7m,
        ri=\EM,
-       dch=\E[%p1%dP, dch1=\E[P,
+       rmacs=^O,
+       rmcup=\E[2J\E[?47l\E8,
+       rmir=\E[4l,
+       rmkx=\E[?1l\E>,
+       rmso=\E[m,
+       rmul=\E[m,
+       rs2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
+       sc=\E7,
+       sgr0=\E[m,
+       smacs=^N,
+       smcup=\E7\E[?47h,
+       smir=\E[4h,
+       smkx=\E[?1h\E=,
+       smso=\E[7m,
+       smul=\E[4m,
        tbc=\E[3g,
-       xenl,
 #
 # Compatible with the R5 xterm
 xterm-r5|xterm R5 version,
-       am, xenl, km, msgr,
-       cols#80, it#8, lines#24,
-       bel=^G, cr=\r, csr=\E[%i%p1%d;%p2%dr, tbc=\E[3g,
-       clear=\E[H\E[2J, el=\E[K, ed=\E[J, cup=\E[%i%p1%d;%p2%dH,
-       cud1=\n, home=\E[H, cub1=\b, cuf1=\E[C,
-       cuu1=\E[A, dch1=\E[P, dl1=\E[M, blink=@,
-       bold=\E[1m, rev=\E[7m, smso=\E[7m, sgr0=\E[m,
-       rmso=\E[m, ich1=\E[@, il1=\E[L, kbs=\b,
-       kdch1=\E[3~, kdl1=\E[31~, kel=\E[8~, kcud1=\EOB, kf0=\EOq,
-       kf1=\E[11~, kf10=\E[21~, kf2=\E[12~, kf3=\E[13~,
-       kf4=\E[14~, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~,
-       kf8=\E[19~, kf9=\E[20~, khome=\E[7~, kich1=\E[2~,
-       kil1=\E[30~, kcub1=\EOD, knp=\E[6~, kpp=\E[5~,
-       kcuf1=\EOC, kcuu1=\EOA, rmkx=\E[?1l\E>, smkx=\E[?1h\E=,
-       dch=\E[%p1%dP, dl=\E[%p1%dM, cud=\E[%p1%dB, ich=\E[%p1%d@,
-       il=\E[%p1%dL, cub=\E[%p1%dD, cuf=\E[%p1%dC, cuu=\E[%p1%dA,
-       rs1=\E>\E[1;3;4;5;6l\E[?7h\E[m\E[r\E[2J\E[H, rc=\E8, sc=\E7,
-       ind=\n, ri=\EM,
+       am,
+       km,
+       msgr,
+       xenl,
+       cols#80,
+       it#8,
+       lines#24,
+       bel=^G,
+       blink=@,
+       bold=\E[1m,
+       clear=\E[H\E[2J,
+       cr=^M,
+       csr=\E[%i%p1%d;%p2%dr,
+       cub=\E[%p1%dD,
+       cub1=^H,
+       cud=\E[%p1%dB,
+       cud1=^J,
+       cuf=\E[%p1%dC,
+       cuf1=\E[C,
+       cup=\E[%i%p1%d;%p2%dH,
+       cuu=\E[%p1%dA,
+       cuu1=\E[A,
+       dch=\E[%p1%dP,
+       dch1=\E[P,
+       dl=\E[%p1%dM,
+       dl1=\E[M,
+       ed=\E[J,
+       el=\E[K,
+       home=\E[H,
+       ht=^I,
+       hts=\EH,
+       ich=\E[%p1%d@,
+       ich1=\E[@,
+       il=\E[%p1%dL,
+       il1=\E[L,
+       ind=^J,
+       kbs=^H,
+       kcub1=\EOD,
+       kcud1=\EOB,
+       kcuf1=\EOC,
+       kcuu1=\EOA,
+       kdch1=\E[3~,
+       kdl1=\E[31~,
+       kel=\E[8~,
+       kf0=\EOq,
+       kf1=\EOP,
+       kf10=\E[21~,
+       kf11=\E[23~,
+       kf12=\E[24~,
+       kf2=\EOQ,
+       kf3=\EOR,
+       kf4=\EOS,
+       kf5=\E[15~,
+       kf6=\E[17~,
+       kf7=\E[18~,
+       kf8=\E[19~,
+       kf9=\E[20~,
+       khome=\E[7~,
+       kich1=\E[2~,
+       kil1=\E[30~,
+       knp=\E[6~,
+       kpp=\E[5~,
+       rc=\E8,
+       rev=\E[7m,
+       ri=\EM,
+       rmkx=\E[?1l\E>,
+       rmso=\E[m,
+       rs1=\E>\E[1;3;4;5;6l\E[?7h\E[m\E[r\E[2J\E[H,
+       sc=\E7,
        sgr=\E[%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;m,
-       hts=\EH, ht=\t, kf11=\E[23~, kf12=\E[24~,
+       sgr0=\E[m,
+       smkx=\E[?1h\E=,
+       smso=\E[7m,
+       tbc=\E[3g,
Index: util.c
--- xterm-34+/util.c    Fri Dec 27 03:01:57 1996
+++ xterm-35/util.c     Tue Jan  7 19:14:55 1997
@@ -697,10 +697,7 @@
        memset(SCRN_BUF_ATTRS(screen, row) + col, flags, len);
 
        if_OPT_ISO_COLORS(screen,{
-               memset(SCRN_BUF_FORES(screen, row) + col,
-                       flags & FG_COLOR ? term->cur_foreground : 0, len);
-               memset(SCRN_BUF_BACKS(screen, row) + col,
-                       flags & BG_COLOR ? term->cur_background : 0, len);
+               memset(SCRN_BUF_COLOR(screen, row) + col, xtermColorPair(), len);
        })
 
        return rc;
@@ -1294,6 +1291,7 @@
        char *text;
        int len;
 {
+       y += FontAscent(screen);
        XDrawImageString(screen->display, TextWindow(screen), gc, 
                x, y,  text, len);
        if ((flags & BOLD) && screen->enbolden)
@@ -1380,6 +1378,58 @@
 }
 
 #if OPT_ISO_COLORS
+/*
+ * Extract the foreground-color index from a one-byte color pair.  If we've got
+ * BOLD or UNDERLINE color-mode active, those will be used unless we've got
+ * an SGR foreground color active.
+ */
+unsigned
+extract_fg (color, flags)
+       unsigned color;
+       unsigned flags;
+{
+       unsigned fg = (color >> 4) & 0xf;
+       if (fg == extract_bg(color))
+       {
+               if (term->screen.colorULMode && (flags & UNDERLINE))
+                       fg = COLOR_UL;
+               if (term->screen.colorBDMode && (flags & BOLD))
+                       fg = COLOR_BD;
+       }
+       return fg;
+}
+
+unsigned
+extract_bg (color)
+       unsigned color;
+{
+       return color & 0xf;
+}
+
+/*
+ * Combine the current foreground and background into a single 8-bit number.
+ * Note that we're storing the SGR foreground, since cur_foreground may be set
+ * to COLOR_UL or COLOR_BD, which would make the code larger than 8 bits.
+ *
+ * FIXME: I'm using the coincidence of fg/bg values to unmask COLOR_UL/COLOR_BD,
+ * which will require more work...
+ */
+unsigned
+makeColorPair (fg, bg)
+       int fg;
+       int bg;
+{
+       unsigned my_bg = (bg >= 0) && (bg < 16) ? bg : 0;
+       unsigned my_fg = (fg >= 0) && (fg < 16) ? fg : my_bg;
+       return (my_fg << 4) | my_bg;
+}
+
+unsigned
+xtermColorPair ()
+{
+       return makeColorPair(term->sgr_foreground, term->cur_background);
+}
+
 Pixel
 getXtermForeground(flags, color)
        int flags;
Index: xterm.h
--- xterm-34+/xterm.h   Fri Dec 27 03:01:57 1996
+++ xterm-35/xterm.h    Tue Jan  7 18:25:49 1997
@@ -204,6 +204,10 @@
 
 extern Pixel getXtermBackground PROTO((int flags, int color));
 extern Pixel getXtermForeground PROTO((int flags, int color));
+extern unsigned extract_bg PROTO((unsigned color));
+extern unsigned extract_fg PROTO((unsigned color, unsigned flags));
+extern unsigned makeColorPair PROTO((int fg, int bg));
+extern unsigned xtermColorPair PROTO((void));
 extern void ClearCurBackground PROTO((TScreen *screen, int top, int left, unsigned height, unsigned width));
 extern void useCurBackground PROTO((Bool flag));
 
@@ -212,6 +216,9 @@
 #define ClearCurBackground(screen, top, left, height, width) \
        XClearArea (screen->display, TextWindow(screen), \
                left, top, width, height, FALSE)
+
+#define extract_fg(color, flags) term->cur_foreground
+#define extract_bg(color) term->cur_background
 
                /* FIXME: Reverse-Video? */
 #define getXtermBackground(flags, color) term->core.background_pixel