Reset terminal styles
[deliverable/binutils-gdb.git] / gdb / utils.c
index 2fb7476a35ac14ec5a90d217daad94bb1f369371..4bb2f34fc9af29b177a0cddad7abdb17c6d26b86 100644 (file)
@@ -1444,25 +1444,50 @@ emit_style_escape (const ui_file_style &style)
   wrap_buffer.append (style.to_ansi ());
 }
 
-/* Set the current output style.  This will affect future uses of the
-   _filtered output functions.  */
+/* Return true if ANSI escapes can be used on STREAM.  */
 
-static void
-set_output_style (struct ui_file *stream, const ui_file_style &style)
+static bool
+can_emit_style_escape (struct ui_file *stream)
 {
   if (stream != gdb_stdout
       || !cli_styling
-      || style == desired_style
       || !ui_file_isatty (stream))
-    return;
+    return false;
   const char *term = getenv ("TERM");
   if (term == nullptr || !strcmp (term, "dumb"))
+    return false;
+  return true;
+}
+
+/* Set the current output style.  This will affect future uses of the
+   _filtered output functions.  */
+
+static void
+set_output_style (struct ui_file *stream, const ui_file_style &style)
+{
+  if (!can_emit_style_escape (stream)
+      || style == desired_style)
     return;
 
   desired_style = style;
   emit_style_escape (style);
 }
 
+/* See utils.h.  */
+
+void
+reset_terminal_style (struct ui_file *stream)
+{
+  if (can_emit_style_escape (stream))
+    {
+      /* Force the setting, regardless of what we think the setting
+        might already be.  */
+      desired_style = ui_file_style ();
+      applied_style = desired_style;
+      wrap_buffer.append (desired_style.to_ansi ());
+    }
+}
+
 /* Wait, so the user can read what's on the screen.  Prompt the user
    to continue by pressing RETURN.  'q' is also provided because
    telling users what to do in the prompt is more user-friendly than
This page took 0.039643 seconds and 4 git commands to generate.