diff options
Diffstat (limited to 'gdb/ui-file.h')
-rw-r--r-- | gdb/ui-file.h | 174 |
1 files changed, 150 insertions, 24 deletions
diff --git a/gdb/ui-file.h b/gdb/ui-file.h index c097abf0c29..e33ae79e753 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -51,7 +51,7 @@ public: write_async_safe method. */ void putstrn (const char *str, int n, int quoter, bool async_safe = false); - int putc (int c); + void putc (int c); void vprintf (const char *, va_list) ATTRIBUTE_PRINTF (2, 0); @@ -99,14 +99,44 @@ public: virtual int fd () const { return -1; } - /* Return true if this object supports paging, false otherwise. */ - virtual bool can_page () const + /* Indicate that if the next sequence of characters overflows the + line, a newline should be inserted here rather than when it hits + the end. If INDENT is non-zero, it is a number of spaces to be + printed to indent the wrapped part on the next line. + + If the line is already overfull, we immediately print a newline and + the indentation, and disable further wrapping. + + If we don't know the width of lines, but we know the page height, + we must not wrap words, but should still keep track of newlines + that were explicitly printed. + + This routine is guaranteed to force out any output which has been + squirreled away in the wrap_buffer, so wrap_here (0) can be + used to force out output from the wrap_buffer. */ + virtual void wrap_here (int indent) + { + } + + /* Emit an ANSI style escape for STYLE. */ + virtual void emit_style_escape (const ui_file_style &style); + + /* Rest the current output style to the empty style. */ + virtual void reset_style (); + + /* Print STR, bypassing any paging that might be done by this + ui_file. Note that nearly no code should call this -- it's + intended for use by gdb_printf, but nothing else. */ + virtual void puts_unfiltered (const char *str) { - /* Almost no file supports paging, which is why this is the - default. */ - return false; + this->puts (str); } +protected: + + /* The currently applied style. */ + ui_file_style m_applied_style; + private: /* Helper function for putstr and putstrn. Print the character C on @@ -160,17 +190,27 @@ public: /* string_file-specific public API. */ /* Accesses the std::string containing the entire output collected - so far. + so far. */ + const std::string &string () { return m_string; } - Returns a non-const reference so that it's easy to move the - string contents out of the string_file. E.g.: + /* Return an std::string containing the entire output collected so far. + + The internal buffer is cleared, such that it's ready to build a new + string. */ + std::string release () + { + std::string ret = std::move (m_string); + m_string.clear (); + return ret; + } - string_file buf; - buf.printf (....); - buf.printf (....); - return std::move (buf.string ()); - */ - std::string &string () { return m_string; } + /* Set the internal buffer contents to STR. Any existing contents are + discarded. */ + string_file &operator= (std::string &&str) + { + m_string = std::move (str); + return *this; + } /* Provide a few convenience methods with the same API as the underlying std::string. */ @@ -229,11 +269,6 @@ public: int fd () const override { return m_fd; } - virtual bool can_page () const override - { - return m_file == stdout; - } - private: /* Sets the internal stream to FILE, and saves the FILE's file descriptor in M_FD. */ @@ -308,11 +343,22 @@ public: bool can_emit_style_escape () override; void flush () override; - virtual bool can_page () const override + void emit_style_escape (const ui_file_style &style) override + { + m_one->emit_style_escape (style); + m_two->emit_style_escape (style); + } + + void reset_style () override + { + m_one->reset_style (); + m_two->reset_style (); + } + + void puts_unfiltered (const char *str) override { - /* If one of the underlying files can page, then we allow it - here. */ - return m_one->can_page () || m_two->can_page (); + m_one->puts_unfiltered (str); + m_two->puts_unfiltered (str); } private: @@ -335,6 +381,86 @@ public: sequences. */ void write (const char *buf, long length_buf) override; void puts (const char *linebuffer) override; + + void emit_style_escape (const ui_file_style &style) override + { + } + + void reset_style () override + { + } +}; + +/* A base class for ui_file types that wrap another ui_file. */ + +class wrapped_file : public ui_file +{ +public: + + bool isatty () override + { return m_stream->isatty (); } + + bool term_out () override + { return m_stream->term_out (); } + + bool can_emit_style_escape () override + { return m_stream->can_emit_style_escape (); } + + void flush () override + { m_stream->flush (); } + + void wrap_here (int indent) override + { m_stream->wrap_here (indent); } + + void emit_style_escape (const ui_file_style &style) override + { m_stream->emit_style_escape (style); } + + /* Rest the current output style to the empty style. */ + void reset_style () override + { m_stream->reset_style (); } + + int fd () const override + { return m_stream->fd (); } + + void puts_unfiltered (const char *str) override + { m_stream->puts_unfiltered (str); } + + void write_async_safe (const char *buf, long length_buf) override + { return m_stream->write_async_safe (buf, length_buf); } + +protected: + + /* Note that this class does not assume ownership of the stream. + However, a subclass may choose to, by adding a 'delete' to its + destructor. */ + explicit wrapped_file (ui_file *stream) + : m_stream (stream) + { + } + + /* The underlying stream. */ + ui_file *m_stream; +}; + +/* A ui_file that optionally puts a timestamp at the start of each + line of output. */ + +class timestamped_file : public wrapped_file +{ +public: + explicit timestamped_file (ui_file *stream) + : wrapped_file (stream) + { + } + + DISABLE_COPY_AND_ASSIGN (timestamped_file); + + void write (const char *buf, long len) override; + +private: + + /* True if the next output should be timestamped. */ + bool m_needs_timestamp = true; }; #endif |