by gno
gno [n=user@notbald.gropeep.org]

diff -ur rxvt-unicode.orig/configure.ac rxvt-unicode/configure.ac
--- rxvt-unicode.orig/configure.ac	2007-06-26 14:59:13.000000000 -0700
+++ rxvt-unicode/configure.ac	2007-06-27 17:05:31.000000000 -0700
@@ -104,6 +104,7 @@
 support_mousewheel=yes
 support_mouseslipwheel=yes
 support_text_blink=yes
+support_xterm_colors=88
 support_pointer_blank=yes
 support_scroll_rxvt=yes
 support_scroll_next=yes
@@ -148,6 +149,7 @@
        support_mousewheel=no
        support_mouseslipwheel=no
        support_text_blink=no
+       support_xterm_colors=no
        support_pointer_blank=no
        support_scroll_rxvt=no
        support_scroll_next=no
@@ -179,6 +181,7 @@
        support_mousewheel=yes
        support_mouseslipwheel=yes
        support_text_blink=yes
+       support_xterm_colors=88
        support_pointer_blank=yes
        support_scroll_rxvt=yes
        support_scroll_next=yes
@@ -419,6 +422,12 @@
     support_text_blink=$enableval
   fi])
 
+AC_ARG_ENABLE(xterm-colors,
+  [  --enable-xterm-colors     enable Xterm 88 or 256 color model],
+  [if test x$enableval = x88 -o x$enableval = x256 -o x$enableval = xno; then
+    support_xterm_colors=$enableval
+  fi])
+
 AC_ARG_ENABLE(pointer-blank,
   [  --enable-pointer-blank  enable pointer blank when typing or inactive pointer],
   [if test x$enableval = xyes -o x$enableval = xno; then
@@ -830,6 +839,9 @@
 if test x$support_text_blink = xyes; then
   AC_DEFINE(TEXT_BLINK, 1, Define if you want blinking text support)
 fi
+if test x$support_xterm_colors = x88 -o x$support_xterm_colors = x256; then
+  AC_DEFINE_UNQUOTED(XTERM_COLORS, $support_xterm_colors, Set to 88 or 256 depending on Xterm color cube you want)
+fi
 if test x$support_unicode3 = xyes; then
   AC_DEFINE(UNICODE_3, 1, Define if you want to represent unicode characters outside plane 0)
 fi
@@ -977,6 +989,9 @@
 if test x$terminfo != x; then
   echo "  set TERMINFO to:            $terminfo"
 fi
+if test x$support_xterm_colors != xno; then
+  echo "  Xterm color cube:           $support_xterm_colors"
+fi
 echo "  default resource name:      $RESNAME"
 echo "  resource class:             $RESCLASS"
 if test x$RESFALLBACK != x; then
diff -ur rxvt-unicode.orig/src/feature.h rxvt-unicode/src/feature.h
--- rxvt-unicode.orig/src/feature.h	2007-06-01 21:57:54.000000000 -0700
+++ rxvt-unicode/src/feature.h	2007-06-27 17:05:31.000000000 -0700
@@ -34,6 +34,8 @@
 # define XAPPLOADDIRLOCALE	X11LIBDIR "/%s/app-defaults"
 #endif
 
+#include "../config.h"
+
 /*-------------------------------SECURITY-------------------------------*/
 
 /*
@@ -85,7 +87,9 @@
 /*
  * Make colours match xterm colours instead of `traditional' rxvt colours
  */
-#define XTERM_COLORS
+#ifndef XTERM_COLORS
+#define XTERM_COLORS 256
+#endif
 
 /*
  * Disable separate colours for bold, underline and reverse video
diff -ur rxvt-unicode.orig/src/init.C rxvt-unicode/src/init.C
--- rxvt-unicode.orig/src/init.C	2007-06-25 17:40:18.000000000 -0700
+++ rxvt-unicode/src/init.C	2007-06-27 17:05:31.000000000 -0700
@@ -71,6 +71,7 @@
     "rgb:00/ff/ff",             // 6/14: bright cyan    (Cyan)
     "rgb:ff/ff/ff",             // 7/15: bright white   (White)
 
+#if XTERM_COLORS == 88
     // 88 xterm colours
     "rgb:00/00/00",
     "rgb:00/00/8b",
@@ -144,6 +145,251 @@
     "rgb:b9/b9/b9",
     "rgb:d0/d0/d0",
     "rgb:e7/e7/e7",
+#elif XTERM_COLORS == 256
+    // 256 xterm colours
+    "rgb:00/00/00",
+    "rgb:00/00/5f",
+    "rgb:00/00/87",
+    "rgb:00/00/af",
+    "rgb:00/00/d7",
+    "rgb:00/00/ff",
+    "rgb:00/5f/00",
+    "rgb:00/5f/5f",
+    "rgb:00/5f/87",
+    "rgb:00/5f/af",
+    "rgb:00/5f/d7",
+    "rgb:00/5f/ff",
+    "rgb:00/87/00",
+    "rgb:00/87/5f",
+    "rgb:00/87/87",
+    "rgb:00/87/af",
+    "rgb:00/87/d7",
+    "rgb:00/87/ff",
+    "rgb:00/af/00",
+    "rgb:00/af/5f",
+    "rgb:00/af/87",
+    "rgb:00/af/af",
+    "rgb:00/af/d7",
+    "rgb:00/af/ff",
+    "rgb:00/d7/00",
+    "rgb:00/d7/5f",
+    "rgb:00/d7/87",
+    "rgb:00/d7/af",
+    "rgb:00/d7/d7",
+    "rgb:00/d7/ff",
+    "rgb:00/ff/00",
+    "rgb:00/ff/5f",
+    "rgb:00/ff/87",
+    "rgb:00/ff/af",
+    "rgb:00/ff/d7",
+    "rgb:00/ff/ff",
+    "rgb:5f/00/00",
+    "rgb:5f/00/5f",
+    "rgb:5f/00/87",
+    "rgb:5f/00/af",
+    "rgb:5f/00/d7",
+    "rgb:5f/00/ff",
+    "rgb:5f/5f/00",
+    "rgb:5f/5f/5f",
+    "rgb:5f/5f/87",
+    "rgb:5f/5f/af",
+    "rgb:5f/5f/d7",
+    "rgb:5f/5f/ff",
+    "rgb:5f/87/00",
+    "rgb:5f/87/5f",
+    "rgb:5f/87/87",
+    "rgb:5f/87/af",
+    "rgb:5f/87/d7",
+    "rgb:5f/87/ff",
+    "rgb:5f/af/00",
+    "rgb:5f/af/5f",
+    "rgb:5f/af/87",
+    "rgb:5f/af/af",
+    "rgb:5f/af/d7",
+    "rgb:5f/af/ff",
+    "rgb:5f/d7/00",
+    "rgb:5f/d7/5f",
+    "rgb:5f/d7/87",
+    "rgb:5f/d7/af",
+    "rgb:5f/d7/d7",
+    "rgb:5f/d7/ff",
+    "rgb:5f/ff/00",
+    "rgb:5f/ff/5f",
+    "rgb:5f/ff/87",
+    "rgb:5f/ff/af",
+    "rgb:5f/ff/d7",
+    "rgb:5f/ff/ff",
+    "rgb:87/00/00",
+    "rgb:87/00/5f",
+    "rgb:87/00/87",
+    "rgb:87/00/af",
+    "rgb:87/00/d7",
+    "rgb:87/00/ff",
+    "rgb:87/5f/00",
+    "rgb:87/5f/5f",
+    "rgb:87/5f/87",
+    "rgb:87/5f/af",
+    "rgb:87/5f/d7",
+    "rgb:87/5f/ff",
+    "rgb:87/87/00",
+    "rgb:87/87/5f",
+    "rgb:87/87/87",
+    "rgb:87/87/af",
+    "rgb:87/87/d7",
+    "rgb:87/87/ff",
+    "rgb:87/af/00",
+    "rgb:87/af/5f",
+    "rgb:87/af/87",
+    "rgb:87/af/af",
+    "rgb:87/af/d7",
+    "rgb:87/af/ff",
+    "rgb:87/d7/00",
+    "rgb:87/d7/5f",
+    "rgb:87/d7/87",
+    "rgb:87/d7/af",
+    "rgb:87/d7/d7",
+    "rgb:87/d7/ff",
+    "rgb:87/ff/00",
+    "rgb:87/ff/5f",
+    "rgb:87/ff/87",
+    "rgb:87/ff/af",
+    "rgb:87/ff/d7",
+    "rgb:87/ff/ff",
+    "rgb:af/00/00",
+    "rgb:af/00/5f",
+    "rgb:af/00/87",
+    "rgb:af/00/af",
+    "rgb:af/00/d7",
+    "rgb:af/00/ff",
+    "rgb:af/5f/00",
+    "rgb:af/5f/5f",
+    "rgb:af/5f/87",
+    "rgb:af/5f/af",
+    "rgb:af/5f/d7",
+    "rgb:af/5f/ff",
+    "rgb:af/87/00",
+    "rgb:af/87/5f",
+    "rgb:af/87/87",
+    "rgb:af/87/af",
+    "rgb:af/87/d7",
+    "rgb:af/87/ff",
+    "rgb:af/af/00",
+    "rgb:af/af/5f",
+    "rgb:af/af/87",
+    "rgb:af/af/af",
+    "rgb:af/af/d7",
+    "rgb:af/af/ff",
+    "rgb:af/d7/00",
+    "rgb:af/d7/5f",
+    "rgb:af/d7/87",
+    "rgb:af/d7/af",
+    "rgb:af/d7/d7",
+    "rgb:af/d7/ff",
+    "rgb:af/ff/00",
+    "rgb:af/ff/5f",
+    "rgb:af/ff/87",
+    "rgb:af/ff/af",
+    "rgb:af/ff/d7",
+    "rgb:af/ff/ff",
+    "rgb:d7/00/00",
+    "rgb:d7/00/5f",
+    "rgb:d7/00/87",
+    "rgb:d7/00/af",
+    "rgb:d7/00/d7",
+    "rgb:d7/00/ff",
+    "rgb:d7/5f/00",
+    "rgb:d7/5f/5f",
+    "rgb:d7/5f/87",
+    "rgb:d7/5f/af",
+    "rgb:d7/5f/d7",
+    "rgb:d7/5f/ff",
+    "rgb:d7/87/00",
+    "rgb:d7/87/5f",
+    "rgb:d7/87/87",
+    "rgb:d7/87/af",
+    "rgb:d7/87/d7",
+    "rgb:d7/87/ff",
+    "rgb:d7/af/00",
+    "rgb:d7/af/5f",
+    "rgb:d7/af/87",
+    "rgb:d7/af/af",
+    "rgb:d7/af/d7",
+    "rgb:d7/af/ff",
+    "rgb:d7/d7/00",
+    "rgb:d7/d7/5f",
+    "rgb:d7/d7/87",
+    "rgb:d7/d7/af",
+    "rgb:d7/d7/d7",
+    "rgb:d7/d7/ff",
+    "rgb:d7/ff/00",
+    "rgb:d7/ff/5f",
+    "rgb:d7/ff/87",
+    "rgb:d7/ff/af",
+    "rgb:d7/ff/d7",
+    "rgb:d7/ff/ff",
+    "rgb:ff/00/00",
+    "rgb:ff/00/5f",
+    "rgb:ff/00/87",
+    "rgb:ff/00/af",
+    "rgb:ff/00/d7",
+    "rgb:ff/00/ff",
+    "rgb:ff/5f/00",
+    "rgb:ff/5f/5f",
+    "rgb:ff/5f/87",
+    "rgb:ff/5f/af",
+    "rgb:ff/5f/d7",
+    "rgb:ff/5f/ff",
+    "rgb:ff/87/00",
+    "rgb:ff/87/5f",
+    "rgb:ff/87/87",
+    "rgb:ff/87/af",
+    "rgb:ff/87/d7",
+    "rgb:ff/87/ff",
+    "rgb:ff/af/00",
+    "rgb:ff/af/5f",
+    "rgb:ff/af/87",
+    "rgb:ff/af/af",
+    "rgb:ff/af/d7",
+    "rgb:ff/af/ff",
+    "rgb:ff/d7/00",
+    "rgb:ff/d7/5f",
+    "rgb:ff/d7/87",
+    "rgb:ff/d7/af",
+    "rgb:ff/d7/d7",
+    "rgb:ff/d7/ff",
+    "rgb:ff/ff/00",
+    "rgb:ff/ff/5f",
+    "rgb:ff/ff/87",
+    "rgb:ff/ff/af",
+    "rgb:ff/ff/d7",
+    "rgb:ff/ff/ff",
+    "rgb:08/08/08",
+    "rgb:12/12/12",
+    "rgb:1c/1c/1c",
+    "rgb:26/26/26",
+    "rgb:30/30/30",
+    "rgb:3a/3a/3a",
+    "rgb:44/44/44",
+    "rgb:4e/4e/4e",
+    "rgb:58/58/58",
+    "rgb:62/62/62",
+    "rgb:6c/6c/6c",
+    "rgb:76/76/76",
+    "rgb:80/80/80",
+    "rgb:8a/8a/8a",
+    "rgb:94/94/94",
+    "rgb:9e/9e/9e",
+    "rgb:a8/a8/a8",
+    "rgb:b2/b2/b2",
+    "rgb:bc/bc/bc",
+    "rgb:c6/c6/c6",
+    "rgb:d0/d0/d0",
+    "rgb:da/da/da",
+    "rgb:e4/e4/e4",
+    "rgb:ee/ee/ee",
+#else
+#error XTERM_COLORS needs to be set to 88 or 256
+#endif
 
 #ifndef NO_CURSORCOLOR
     COLOR_CURSOR_BACKGROUND,
diff -ur rxvt-unicode.orig/src/rxvt.h rxvt-unicode/src/rxvt.h
--- rxvt-unicode.orig/src/rxvt.h	2007-06-25 17:40:19.000000000 -0700
+++ rxvt-unicode/src/rxvt.h	2007-06-27 23:04:47.000000000 -0700
@@ -397,32 +397,58 @@
 
 #define RS_None                 0
 
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 #define RS_fgMask               0x0000007fUL    // 128 colors
 #define RS_bgMask               0x00003f80UL    // 128 colors
+#elif XTERM_COLORS == 256
+#define RS_fgMask               0x000001ffUL    // 512 colors
+#define RS_bgMask               0x0003fe00UL    // 512 colors
+#endif
 
 // font styles
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 #define RS_Bold                 0x00004000UL    // value 1
 #define RS_Italic		0x00008000UL    // value 2
+#elif XTERM_COLORS == 256
+#define RS_Bold                 0x00040000UL    // value 1
+#define RS_Italic		0x00080000UL    // value 2
+#endif
 
 // fake styles
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 #define RS_Blink                0x00010000UL    // blink
 #define RS_RVid                 0x00020000UL    // reverse video
 #define RS_Uline                0x00040000UL    // underline
+#elif XTERM_COLORS == 256
+#define RS_Blink                0x00100000UL    // blink	 (disabled)
+#define RS_RVid                 0x00200000UL    // reverse video (disabled)
+#define RS_Uline                0x00400000UL    // underline
+#endif
+
 
 // toggle this to force redraw, must be != RS_Careful
 #define RS_redraw               0x01000000UL
 
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 // 5 custom bits for extensions
 #define RS_customCount          32
 #define RS_customMask           0x00f80000UL
+#elif XTERM_COLORS == 256
+#define RS_customCount          0
+#define RS_customMask           0x00000000UL
+#endif
 #define RS_customShift          19
 
 // other flags
 #define RS_Careful		0x80000000UL	/* be careful when drawing these */
 
 #define RS_styleCount		4
 #define RS_styleMask		(RS_Bold | RS_Italic)
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 #define RS_styleShift		14
+#elif XTERM_COLORS == 256
+#define RS_styleShift		18
+#endif
 
 #define RS_baseattrMask         (RS_Italic | RS_Bold | RS_Blink | RS_RVid | RS_Uline)
 #define RS_attrMask             (RS_baseattrMask | RS_fontMask)
@@ -545,7 +573,13 @@
   Color_White = maxCOLOR,
 #endif
   minTermCOLOR = Color_White + 1,
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
   maxTermCOLOR = Color_White + 72,
+#elif (XTERM_COLORS == 256)
+  maxTermCOLOR = Color_White + 240,
+#else
+#error XTERM_COLORS needs to be set to 88 or 256
+#endif
 #ifndef NO_CURSORCOLOR
   Color_cursor,
   Color_cursor2,
@@ -585,7 +619,11 @@
 #endif
 };
 
+#if !defined(XTERM_COLORS) || XTERM_COLORS == 88
 #define Color_Bits      7 // 0 .. maxTermCOLOR
+#elif XTERM_COLORS == 256
+#define Color_Bits      9 // 0 .. maxTermCOLOR
+#endif
 
 /*
  * Resource list
