diff options
Diffstat (limited to 'gdb/ui-file.h')
-rw-r--r-- | gdb/ui-file.h | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 5379bb3..1219bde 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -1,5 +1,5 @@ /* UI_FILE - a generic STDIO like output stream. - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 1999-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -123,9 +123,6 @@ public: /* 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. */ @@ -353,12 +350,6 @@ public: 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 { m_one->puts_unfiltered (str); @@ -371,28 +362,58 @@ private: ui_file *m_two; }; +/* A ui_file implementation that buffers terminal escape sequences. + Note that this does not buffer in general -- it only buffers when + an incomplete but potentially recognizable escape sequence is + started. */ + +class escape_buffering_file : public stdio_file +{ +public: + using stdio_file::stdio_file; + + /* Like the stdio_file methods but these forward to do_write and + do_puts, respectively. */ + void write (const char *buf, long length_buf) override final; + void puts (const char *linebuffer) override final; + + /* This class does not override 'flush'. While it does have an + internal buffer, it does not really make sense to flush the + buffer until an escape sequence has been fully processed. */ + +protected: + + /* Called to output some text. If the text contains a recognizable + terminal escape sequence, then it is guaranteed to be complete. + "Recognizable" here means that examine_ansi_escape did not return + INCOMPLETE. */ + virtual void do_puts (const char *buf) = 0; + virtual void do_write (const char *buf, long len) = 0; + +private: + + /* Buffer used only for incomplete escape sequences. */ + std::string m_buffer; +}; + /* A ui_file implementation that filters out terminal escape sequences. */ -class no_terminal_escape_file : public stdio_file +class no_terminal_escape_file : public escape_buffering_file { public: no_terminal_escape_file () { } - /* Like the stdio_file methods, but these filter out terminal escape - 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 - { - } +protected: + + void do_puts (const char *linebuffer) override; + void do_write (const char *buf, long len) override; }; /* A base class for ui_file types that wrap another ui_file. */ @@ -419,10 +440,6 @@ public: 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 (); } |