virtual bool isatty ()
{ return false; }
+ /* true indicates terminal output behaviour such as cli_styling.
+ This default implementation indicates to do terminal output
+ behaviour if the UI_FILE is a tty. A derived class can override
+ TERM_OUT to have cli_styling behaviour without being a tty. */
+ virtual bool term_out ()
+ { return isatty (); }
+
+ /* true if ANSI escapes can be used on STREAM. */
+ virtual bool can_emit_style_escape ()
+ { return false; }
+
virtual void flush ()
{}
};
class string_file : public ui_file
{
public:
- string_file () {}
+ /* Construct a string_file to collect 'raw' output, i.e. without
+ 'terminal' behaviour such as cli_styling. */
+ string_file () : m_term_out (false) {};
+ /* If TERM_OUT, construct a string_file with terminal output behaviour
+ such as cli_styling)
+ else collect 'raw' output like the previous constructor. */
+ explicit string_file (bool term_out) : m_term_out (term_out) {};
~string_file () override;
/* Override ui_file methods. */
long read (char *buf, long length_buf) override
{ gdb_assert_not_reached ("a string_file is not readable"); }
+ bool term_out () override;
+ bool can_emit_style_escape () override;
+
/* string_file-specific public API. */
/* Accesses the std::string containing the entire output collected
private:
/* The internal buffer. */
std::string m_string;
+
+ bool m_term_out;
};
/* A ui_file implementation that maps directly onto <stdio.h>'s FILE.
bool isatty () override;
+ bool can_emit_style_escape () override;
+
private:
/* Sets the internal stream to FILE, and saves the FILE's file
descriptor in M_FD. */
void puts (const char *) override;
bool isatty () override;
+ bool term_out () override;
+ bool can_emit_style_escape () override;
void flush () override;
private: