diff -ur vte-0.17.4.orig/src/vte.c vte-0.17.4/src/vte.c
--- vte-0.17.4.orig/src/vte.c	2008-09-08 21:48:31.000000000 +0200
+++ vte-0.17.4/src/vte.c	2010-04-28 13:29:22.704765000 +0200
@@ -249,10 +249,6 @@
 #endif
 
 
-/* Indexes in the "palette" color array for the dim colors.
- * Only the first VTE_LEGACY_COLOR_SET_SIZE colors have dim versions.  */
-static const guchar corresponding_dim_index[] = {16,88,28,100,18,90,30,102};
-
 /* Free a no-longer-used row data array. */
 void
 _vte_free_row_data(VteRowData *row)
@@ -352,9 +348,12 @@
 	screen->defaults.attr.strikethrough = 0;
 	screen->defaults.attr.half = 0;
 	screen->defaults.attr.blink = 0;
+	screen->adjusted_defaults = screen->defaults;
 	screen->basic_defaults = screen->defaults;
 	screen->color_defaults = screen->defaults;
 	screen->fill_defaults = screen->defaults;
+	screen->fg_256 = FALSE;
+	screen->bg_256 = FALSE;
 }
 
 /* Cause certain cells to be repainted. */
@@ -2918,8 +2917,8 @@
 	_vte_debug_print(VTE_DEBUG_PARSE,
 			"Inserting %ld '%c' (%d/%d) (%ld+%d, %ld), delta = %ld; ",
 			(long)c, c < 256 ? c : ' ',
-			screen->defaults.attr.fore,
-			screen->defaults.attr.back,
+			screen->adjusted_defaults.attr.fore,
+			screen->adjusted_defaults.attr.back,
 			col, columns, (long)screen->cursor_current.row,
 			(long)screen->insert_delta);
 
@@ -2935,7 +2934,7 @@
 		}
 	}
 
-	memcpy (&attr, &screen->defaults.attr, sizeof (attr));
+	memcpy (&attr, &screen->adjusted_defaults.attr, sizeof (attr));
 	attr.columns = columns;
 
 	if (G_UNLIKELY (c == '_' && terminal->pvt->flags.ul)) {
@@ -8501,34 +8500,6 @@
 		*fore = cell ? cell->attr.fore : VTE_DEF_FG;
 		*back = cell ? cell->attr.back : VTE_DEF_BG;
 	}
-
-	/* Handle invisible, bold, and standout text by adjusting colors. */
-	if (cell) {
-		if (cell->attr.invisible) {
-			*fore = *back;
-		}
-		if (cell->attr.bold) {
-			if (*fore == VTE_DEF_FG) {
-				*fore = VTE_BOLD_FG;
-			} else
-			if ((*fore != VTE_DEF_BG) && (*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
-				*fore += VTE_COLOR_BRIGHT_OFFSET;
-			}
-		}
-		if (cell->attr.half) {
-			if (*fore == VTE_DEF_FG) {
-				*fore = VTE_DIM_FG;
-			} else
-			if ((*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
-				*fore = corresponding_dim_index[*fore];;
-			}
-		}
-		if (cell->attr.standout) {
-			if (*back < VTE_LEGACY_COLOR_SET_SIZE) {
-				*back += VTE_COLOR_BRIGHT_OFFSET;
-			}
-		}
-	}
 }
 
 /* Check if a unicode character is actually a graphic character we draw
@@ -10589,8 +10560,8 @@
 					row * height + VTE_PAD_WIDTH,
 					width * columns,
 					height);
-			fore = screen->defaults.attr.fore;
-			back = screen->defaults.attr.back;
+			fore = screen->color_defaults.attr.fore;
+			back = screen->color_defaults.attr.back;
 			vte_terminal_draw_cells_with_attributes(terminal,
 								items, len,
 								terminal->pvt->im_preedit_attrs,
diff -ur vte-0.17.4.orig/src/vte-private.h vte-0.17.4/src/vte-private.h
--- vte-0.17.4.orig/src/vte-private.h	2008-09-08 21:48:31.000000000 +0200
+++ vte-0.17.4/src/vte-private.h	2010-04-28 13:23:32.086631000 +0200
@@ -257,6 +257,7 @@
 		struct vte_charcell defaults;	/* default characteristics
 						   for insertion of any new
 						   characters */
+		struct vte_charcell adjusted_defaults;
 		struct vte_charcell color_defaults;	/* original defaults
 							   plus the current
 							   fore/back */
@@ -265,6 +266,8 @@
 							   fore/back with no
 							   character data */
 		struct vte_charcell basic_defaults;	/* original defaults */
+		gboolean fg_256, bg_256;	/* whether fg/bg were set by
+						   256 color sequences */
 		gboolean alternate_charset;
 		gboolean status_line;
 		GString *status_line_contents;
diff -ur vte-0.17.4.orig/src/vteseq.c vte-0.17.4/src/vteseq.c
--- vte-0.17.4.orig/src/vteseq.c	2008-08-20 15:09:43.000000000 +0200
+++ vte-0.17.4/src/vteseq.c	2010-04-28 13:46:05.903666000 +0200
@@ -43,6 +43,10 @@
 #include "vteseq-list.h"
 #undef VTE_SEQUENCE_HANDLER
 
+/* Indexes in the "palette" color array for the dim colors.
+ * Only the first VTE_LEGACY_COLOR_SET_SIZE colors have dim versions.  */
+static const guchar corresponding_dim_index[] = {16,88,28,100,18,90,30,102};
+
 /* These two handlers are accessed from vte.c */
 gboolean
 _vte_sequence_handler_bl(VteTerminal *terminal, const char *match, GQuark match_quark, GValueArray *params)
@@ -831,6 +835,51 @@
 	return FALSE;
 }
 
+static void
+vte_compute_adjusted_colors(VteTerminal *terminal)
+{
+	/* Handle invisible, bold, half and standout text by adjusting colors. */
+	terminal->pvt->screen->adjusted_defaults = terminal->pvt->screen->defaults;
+	if (terminal->pvt->screen->adjusted_defaults.attr.bold) {
+	        if (terminal->pvt->screen->adjusted_defaults.attr.fore == VTE_DEF_FG) {
+	                terminal->pvt->screen->adjusted_defaults.attr.fore = VTE_BOLD_FG;
+                } else
+                if (!terminal->pvt->screen->fg_256
+        	  && terminal->pvt->screen->adjusted_defaults.attr.fore != VTE_DEF_BG
+        	  && terminal->pvt->screen->adjusted_defaults.attr.fore < VTE_LEGACY_COLOR_SET_SIZE) {
+        		terminal->pvt->screen->adjusted_defaults.attr.fore += VTE_COLOR_BRIGHT_OFFSET;
+                }
+	}
+	if (terminal->pvt->screen->adjusted_defaults.attr.half) {
+	        if (terminal->pvt->screen->adjusted_defaults.attr.fore == VTE_DEF_FG) {
+                        terminal->pvt->screen->adjusted_defaults.attr.fore = VTE_DIM_FG;
+                } else
+        	if (!terminal->pvt->screen->fg_256
+        	  && terminal->pvt->screen->adjusted_defaults.attr.fore != VTE_DEF_FG
+        	  && terminal->pvt->screen->adjusted_defaults.attr.fore < VTE_LEGACY_COLOR_SET_SIZE) {
+        		terminal->pvt->screen->adjusted_defaults.attr.fore = corresponding_dim_index[terminal->pvt->screen->adjusted_defaults.attr.fore];
+                }
+	}
+	if (terminal->pvt->screen->adjusted_defaults.attr.standout) {
+        	if (!terminal->pvt->screen->bg_256
+        	  && terminal->pvt->screen->adjusted_defaults.attr.back < VTE_LEGACY_COLOR_SET_SIZE) {
+        		terminal->pvt->screen->adjusted_defaults.attr.back += VTE_COLOR_BRIGHT_OFFSET;
+                }
+	}
+	if (terminal->pvt->screen->adjusted_defaults.attr.invisible) {
+		terminal->pvt->screen->adjusted_defaults.attr.fore = terminal->pvt->screen->adjusted_defaults.attr.back;
+	}
+	/* Save the new colors. */
+	terminal->pvt->screen->color_defaults.attr.fore =
+		terminal->pvt->screen->adjusted_defaults.attr.fore;
+	terminal->pvt->screen->color_defaults.attr.back =
+		terminal->pvt->screen->adjusted_defaults.attr.back;
+	terminal->pvt->screen->fill_defaults.attr.fore =
+		terminal->pvt->screen->adjusted_defaults.attr.fore;
+	terminal->pvt->screen->fill_defaults.attr.back =
+		terminal->pvt->screen->adjusted_defaults.attr.back;
+}
+
 
 
 
@@ -2329,6 +2378,8 @@
 		terminal->pvt->screen->defaults.attr.standout = 1;
 	}
 
+	vte_compute_adjusted_colors(terminal);
+
 	g_free(blink);
 	g_free(bold);
 	g_free(half);
@@ -2792,6 +2843,7 @@
 		case 35:
 		case 36:
 		case 37:
+			terminal->pvt->screen->fg_256 = FALSE;
 			terminal->pvt->screen->defaults.attr.fore = param - 30;
 			break;
 		case 38:
@@ -2806,6 +2858,7 @@
 					break;
 				}
 				param1 = g_value_get_long(value1);
+				terminal->pvt->screen->fg_256 = TRUE;
 				terminal->pvt->screen->defaults.attr.fore = param1;
 				i += 2;
 			}
@@ -2826,6 +2879,7 @@
 		case 45:
 		case 46:
 		case 47:
+			terminal->pvt->screen->bg_256 = FALSE;
 			terminal->pvt->screen->defaults.attr.back = param - 40;
 			break;
 		case 48:
@@ -2840,6 +2894,7 @@
 					break;
 				}
 				param1 = g_value_get_long(value1);
+				terminal->pvt->screen->bg_256 = TRUE;
 				terminal->pvt->screen->defaults.attr.back = param1;
 				i += 2;
 			}
@@ -2847,6 +2902,7 @@
 		}
 		case 49:
 			/* default background */
+			terminal->pvt->screen->bg_256 = FALSE;
 			terminal->pvt->screen->defaults.attr.back = VTE_DEF_BG;
 			break;
 		case 90:
@@ -2857,6 +2913,7 @@
 		case 95:
 		case 96:
 		case 97:
+			terminal->pvt->screen->fg_256 = FALSE;
 			terminal->pvt->screen->defaults.attr.fore = param - 90 + VTE_COLOR_BRIGHT_OFFSET;
 			break;
 		case 100:
@@ -2867,6 +2924,7 @@
 		case 105:
 		case 106:
 		case 107:
+			terminal->pvt->screen->bg_256 = FALSE;
 			terminal->pvt->screen->defaults.attr.back = param - 100 + VTE_COLOR_BRIGHT_OFFSET;
 			break;
 		}
@@ -2875,15 +2933,8 @@
 	if (i == 0) {
 		_vte_terminal_set_default_attributes(terminal);
 	}
-	/* Save the new colors. */
-	terminal->pvt->screen->color_defaults.attr.fore =
-		terminal->pvt->screen->defaults.attr.fore;
-	terminal->pvt->screen->color_defaults.attr.back =
-		terminal->pvt->screen->defaults.attr.back;
-	terminal->pvt->screen->fill_defaults.attr.fore =
-		terminal->pvt->screen->defaults.attr.fore;
-	terminal->pvt->screen->fill_defaults.attr.back =
-		terminal->pvt->screen->defaults.attr.back;
+
+	vte_compute_adjusted_colors(terminal);
 	return FALSE;
 }
 
