Add an objfile getter to gdb.Type
[deliverable/binutils-gdb.git] / gdb / ui-file.c
index 77f6b31ce4b48466ee7902c7ae07a2af14e70227..24c914f442a5ee0d01ed452428893c9f31068dde 100644 (file)
@@ -101,6 +101,33 @@ ui_file_isatty (struct ui_file *file)
   return file->isatty ();
 }
 
+/* true if the gdb terminal supports styling, and styling is enabled.  */
+
+static bool
+term_cli_styling ()
+{
+  extern int cli_styling;
+
+  if (!cli_styling)
+    return false;
+
+  const char *term = getenv ("TERM");
+  /* Windows doesn't by default define $TERM, but can support styles
+     regardless.  */
+#ifndef _WIN32
+  if (term == nullptr || !strcmp (term, "dumb"))
+    return false;
+#else
+  /* But if they do define $TERM, let us behave the same as on Posix
+     platforms, for the benefit of programs which invoke GDB as their
+     back-end.  */
+  if (term && !strcmp (term, "dumb"))
+    return false;
+#endif
+  return true;
+}
+
+
 void
 ui_file_write (struct ui_file *file,
                const char *buf,
@@ -140,6 +167,22 @@ string_file::write (const char *buf, long length_buf)
   m_string.append (buf, length_buf);
 }
 
+/* See ui-file.h.  */
+
+bool
+string_file::term_out ()
+{
+  return m_term_out;
+}
+
+/* See ui-file.h.  */
+
+bool
+string_file::can_emit_style_escape ()
+{
+  return m_term_out && term_cli_styling ();
+}
+
 \f
 
 stdio_file::stdio_file (FILE *file, bool close_p)
@@ -255,6 +298,16 @@ stdio_file::isatty ()
   return ::isatty (m_fd);
 }
 
+/* See ui-file.h.  */
+
+bool
+stdio_file::can_emit_style_escape ()
+{
+  return (this == gdb_stdout
+         && this->isatty ()
+         && term_cli_styling ());
+}
+
 \f
 
 /* This is the implementation of ui_file method 'write' for stderr.
@@ -283,20 +336,13 @@ stderr_file::stderr_file (FILE *stream)
 
 \f
 
-tee_file::tee_file (ui_file *one, bool close_one,
-                   ui_file *two, bool close_two)
+tee_file::tee_file (ui_file *one, ui_file_up &&two)
   : m_one (one),
-    m_two (two),
-    m_close_one (close_one),
-    m_close_two (close_two)
+    m_two (std::move (two))
 {}
 
 tee_file::~tee_file ()
 {
-  if (m_close_one)
-    delete m_one;
-  if (m_close_two)
-    delete m_two;
 }
 
 void
@@ -332,3 +378,21 @@ tee_file::isatty ()
 {
   return m_one->isatty ();
 }
+
+/* See ui-file.h.  */
+
+bool
+tee_file::term_out ()
+{
+  return m_one->term_out ();
+}
+
+/* See ui-file.h.  */
+
+bool
+tee_file::can_emit_style_escape ()
+{
+  return (this == gdb_stdout
+         && m_one->term_out ()
+         && term_cli_styling ());
+}
This page took 0.045125 seconds and 4 git commands to generate.