--- /tmp/orig-vte/vte-0.11.17/src/vte.c	2006-01-28 12:23:52.000000000 -0800
+++ vte.c	2006-02-14 22:43:44.000000000 -0800
@@ -91,12 +91,12 @@ typedef gunichar wint_t;
 #define VTE_COLOR_PLAIN_OFFSET		0
 #define VTE_COLOR_BRIGHT_OFFSET		8
 #define VTE_COLOR_DIM_OFFSET		16
-#define VTE_DEF_FG			24
-#define VTE_DEF_BG			25
+#define VTE_DEF_FG			0
+#define VTE_DEF_BG			7
 #define VTE_BOLD_FG			26
 #define VTE_DIM_FG			27
 #define VTE_DEF_HL			28
-#define VTE_CUR_BG			29
+#define VTE_CUR_BG			255
 #define VTE_SATURATION_MAX		10000
 #define VTE_SCROLLBACK_MIN		100
 #define VTE_DEFAULT_CURSOR		GDK_XTERM
@@ -119,13 +119,13 @@ typedef gunichar wint_t;
  * includes any supported visible attributes. */
 struct vte_charcell {
 	gunichar c;		/* The Unicode character. */
-	guint32 columns: 11;	/* Number of visible columns (as determined
+	guint32 columns: 5;	/* Number of visible columns (as determined
 				   by g_unicode_iswide(c)).  Use as many bits
 				   as possible without making this structure
 				   grow any larger. */
 	guint32 fragment: 1;	/* The nth fragment of a wide character. */
-	guint32 fore: 5;	/* Indices in the color palette for the */
-	guint32 back: 5;	/* foreground and background of the cell. */
+	guint32 fore: 8;	/* Indices in the color palette for the */
+	guint32 back: 8;	/* foreground and background of the cell. */
 	guint32 standout: 1;	/* Single-bit attributes. */
 	guint32 underline: 1;
 	guint32 strikethrough: 1;
@@ -4210,10 +4210,23 @@ vte_sequence_handler_character_attribute
 			terminal->pvt->screen->defaults.fore = param - 30;
 			break;
 		case 38:
-			/* default foreground, underscore */
-			terminal->pvt->screen->defaults.fore = VTE_DEF_FG;
-			terminal->pvt->screen->defaults.underline = 1;
+		        {
+			  GValue *value1;
+			  long param1;
+			  /* The format looks like: ^[[38;5;COLORNUMBERm,
+			     so look for COLORNUMBER here. */
+			  if ((i + 2) < params->n_values){
+			    value1 = g_value_array_get_nth(params, i + 2);
+			    if (!G_VALUE_HOLDS_LONG(value1)) {
+			      break;
+			    }
+			    param1 = g_value_get_long(value1);
+			    terminal->pvt->screen->defaults.fore = param1;
+			    i += 2;
+			  }
+			  
 			break;
+			}
 		case 39:
 			/* default foreground, no underscore */
 			terminal->pvt->screen->defaults.fore = VTE_DEF_FG;
@@ -4231,6 +4244,24 @@ vte_sequence_handler_character_attribute
 		case 47:
 			terminal->pvt->screen->defaults.back = param - 40;
 			break;
+		case 48:
+		        {
+			  GValue *value1;
+			  long param1;
+			  /* The format looks like: ^[[48;5;COLORNUMBERm,
+			     so look for COLORNUMBER here. */
+			  if ((i + 2) < params->n_values){
+			    value1 = g_value_array_get_nth(params, i + 2);
+			    if (!G_VALUE_HOLDS_LONG(value1)) {
+			      break;
+			    }
+			    param1 = g_value_get_long(value1);
+			    terminal->pvt->screen->defaults.back = param1;
+			    i += 2;
+			  }
+			  break;
+			  
+			}
 		case 49:
 			/* default background */
 			terminal->pvt->screen->defaults.back = VTE_DEF_BG;
@@ -6655,6 +6686,7 @@ vte_terminal_set_colors(VteTerminal *ter
 {
 	int i;
 	GdkColor color;
+	int r, g, b;
 
 	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
@@ -6677,64 +6709,16 @@ vte_terminal_set_colors(VteTerminal *ter
 
 	/* Initialize each item in the palette if we got any entries to work
 	 * with. */
-	for (i = 0; (i < G_N_ELEMENTS(terminal->pvt->palette)); i++) {
-		switch (i) {
-		case VTE_DEF_FG:
-			if (foreground != NULL) {
+	for (i=r=g=b=0; (i < G_N_ELEMENTS(terminal->pvt->palette)); i++) {
+	  if (i < 16) {
+	    gboolean already_initialized = FALSE;
+	    if ((i == VTE_DEF_FG) && (foreground != NULL)){
 				color = *foreground;
-			} else {
-				color.red = 0xc000;
-				color.blue = 0xc000;
-				color.green = 0xc000;
-			}
-			break;
-		case VTE_DEF_BG:
-			if (background != NULL) {
+	      already_initialized = TRUE;
+	    } else if ((i == VTE_DEF_BG) && (background != NULL)){
 				color = *background;
-			} else {
-				color.red = 0;
-				color.blue = 0;
-				color.green = 0;
-			}
-			break;
-		case VTE_BOLD_FG:
-			vte_terminal_generate_bold(&terminal->pvt->palette[VTE_DEF_FG],
-						   &terminal->pvt->palette[VTE_DEF_BG],
-						   1.8,
-						   &color);
-			break;
-		case VTE_DIM_FG:
-			vte_terminal_generate_bold(&terminal->pvt->palette[VTE_DEF_FG],
-						   &terminal->pvt->palette[VTE_DEF_BG],
-						   0.5,
-						   &color);
-			break;
-		case VTE_DEF_HL:
-			color.red = 0xc000;
-			color.blue = 0xc000;
-			color.green = 0xc000;
-			break;
-		case VTE_CUR_BG:
-			color.red = 0x0000;
-			color.blue = 0x0000;
-			color.green = 0x0000;
-			break;
-		case 0 + 0:
-		case 0 + 1:
-		case 0 + 2:
-		case 0 + 3:
-		case 0 + 4:
-		case 0 + 5:
-		case 0 + 6:
-		case 0 + 7:
-		case 8 + 0:
-		case 8 + 1:
-		case 8 + 2:
-		case 8 + 3:
-		case 8 + 4:
-		case 8 + 5:
-		case 8 + 6:
-		case 8 + 7:
+	      already_initialized = TRUE;
+	    } else if (!already_initialized){
 			color.blue = (i & 4) ? 0xc000 : 0;
 			color.green = (i & 2) ? 0xc000 : 0;
 			color.red = (i & 1) ? 0xc000 : 0;
@@ -6743,24 +6727,22 @@ vte_terminal_set_colors(VteTerminal *ter
 				color.green += 0x3fff;
 				color.red += 0x3fff;
 			}
-			break;
-		case 16 + 0:
-		case 16 + 1:
-		case 16 + 2:
-		case 16 + 3:
-		case 16 + 4:
-		case 16 + 5:
-		case 16 + 6:
-		case 16 + 7:
-			color.blue = (i & 4) ? 0x8000 : 0;
-			color.green = (i & 2) ? 0x8000 : 0;
-			color.red = (i & 1) ? 0x8000 : 0;
-			break;
-		default:
-			g_assert_not_reached();
-			break;
 		}
-
+	  }
+	  else
+	    if (i < 232) {
+	      int j = i - 16;
+	      int r = j / 36, g = (j / 6) % 6, b = j % 6;
+	      int red =   (r == 0) ? 0 : r * 40 + 55;
+	      int green = (g == 0) ? 0 : g * 40 + 55;
+	      int blue =  (b == 0) ? 0 : b * 40 + 55;
+	      color.red   = red | red << 8  ;
+	      color.green = green | green << 8;
+	      color.blue  = blue | blue << 8;
+	    } else {
+	      int shade = 8 + (i - 232) * 10;
+	      color.red = color.green = color.blue = shade | shade << 8;
+	    }
 		/* Override from the supplied palette if there is one. */
 		if (i < palette_size) {
 			color = palette[i];
