--- /tmp/orig-vte/vte-0.11.17/src/vte.c	2006-01-28 12:23:52.000000000 -0800
+++ vte.c	2006-02-14 20:17:35.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			15
 #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
@@ -124,8 +124,8 @@ struct vte_charcell {
 				   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;
-			break;
+		        {
+			  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,7 +6686,8 @@ vte_terminal_set_colors(VteTerminal *ter
 {
 	int i;
 	GdkColor color;
-
+	int r, g, b;
+	
 	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
 	g_return_if_fail(palette_size >= 0);
@@ -6677,8 +6709,10 @@ 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) {
+	for (i = 0, r = g = b = 0; (i < G_N_ELEMENTS(terminal->pvt->palette)); i++) {
+	  if (i < 16)
+	        switch (i) {
+#if 0
 		case VTE_DEF_FG:
 			if (foreground != NULL) {
 				color = *foreground;
@@ -6719,6 +6753,7 @@ vte_terminal_set_colors(VteTerminal *ter
 			color.blue = 0x0000;
 			color.green = 0x0000;
 			break;
+#endif
 		case 0 + 0:
 		case 0 + 1:
 		case 0 + 2:
@@ -6744,30 +6779,40 @@ vte_terminal_set_colors(VteTerminal *ter
 				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;
 		}
-
-		/* Override from the supplied palette if there is one. */
-		if (i < palette_size) {
-			color = palette[i];
-		}
-
-		/* Set up the color entry. */
-		vte_terminal_set_color_internal(terminal, i, &color);
+	  else
+	    if (i < 232) {
+	      int j = i - 16;
+	      int r = j / 36, g = (j / 6) % 6, b = j % 6;
+	      color.red =   (r == 0) ? 0 : r * 40 + 55;
+	      color.green = (g == 0) ? 0 : g * 40 + 55;
+	      color.blue =  (b == 0) ? 0 : b * 40 + 55;
+	      fprintf (stderr, "RGB %x/%x/%x\n", color.red, color.green,
+		       color.blue);
+	      color.red   |= color.red << 8  ;
+	      color.green |= color.green << 8;
+	      color.blue  |= color.blue << 8;
+
+	      b++;
+	      if (b > 5) { g++; b = 0;}
+	      if (g > 5) { r++; g = 0;}
+	      if (r > 5)        r = 0;
+	    } else {
+	      int shade;
+	      shade = 8 + (i - 232) * 10;
+	      fprintf (stderr, "shade %x\n", shade);
+	      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];
+	  }
+	  
+	  /* Set up the color entry. */
+	  vte_terminal_set_color_internal(terminal, i, &color);
 	}
 
 	/* We may just have changed the default background color, so queue
