From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 7C2673858C50; Tue, 29 Mar 2022 19:42:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C2673858C50 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Add style-escape methods to ui_file X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 9b7167182d1f6fef32c264587bbc00c7f9bd21f2 X-Git-Newrev: c8d74a7b4b341f7498a3827555451924cabdd0f1 Message-Id: <20220329194225.7C2673858C50@sourceware.org> Date: Tue, 29 Mar 2022 19:42:25 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 19:42:25 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc8d74a7b4b34= 1f7498a3827555451924cabdd0f1 commit c8d74a7b4b341f7498a3827555451924cabdd0f1 Author: Tom Tromey Date: Sat Jan 1 01:34:48 2022 -0700 Add style-escape methods to ui_file =20 This adds emit_style_escape and reset_style methods to ui_file. These aren't used yet, but they will be once the pager is converted to be a ui_file subclass. Diff: --- gdb/ui-file.c | 24 ++++++++++++++++++++++++ gdb/ui-file.h | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/gdb/ui-file.c b/gdb/ui-file.c index 354a7c3e3b6..2072fd81954 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -73,6 +73,30 @@ ui_file::vprintf (const char *format, va_list args) =20 /* See ui-file.h. */ =20 +void +ui_file::emit_style_escape (const ui_file_style &style) +{ + if (can_emit_style_escape () && style !=3D m_applied_style) + { + m_applied_style =3D style; + this->puts (style.to_ansi ().c_str ()); + } +} + +/* See ui-file.h. */ + +void +ui_file::reset_style () +{ + if (can_emit_style_escape ()) + { + m_applied_style =3D ui_file_style (); + this->puts (m_applied_style.to_ansi ().c_str ()); + } +} + +/* See ui-file.h. */ + void ui_file::printchar (int c, int quoter, bool async_safe) { diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 7ae3937e41a..1d946bf97ad 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -124,6 +124,12 @@ public: used to force out output from the wrap_buffer. */ void wrap_here (int indent); =20 + /* 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 printf_filtered, but nothing else. */ @@ -132,6 +138,11 @@ public: this->puts (str); } =20 +protected: + + /* The currently applied style. */ + ui_file_style m_applied_style; + private: =20 /* Helper function for putstr and putstrn. Print the character C on @@ -376,6 +387,14 @@ 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 + { + } }; =20 /* A ui_file that optionally puts a timestamp at the start of each