Re: [PATCHv7 4/4] gdb/python: extend gdb.write to support styled output

Eli Zaretskii
2025-08-13T12:37:59Z

> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Wed, 13 Aug 2025 11:30:52 +0100
>
> It is already possible to produce styled output from Python by
> converting the gdb.Style to its escape code sequence, and writing that
> to the output stream.
>
> But this commit adds an alternative option to the mix by extending the
> existing gdb.write() function to accept a 'style' argument. The value
> of this argument can be 'None' to indicate no style change should be
> performed, this is the default, and matches the existing behaviour.
>
> Or the new 'style' argument can be a gdb.Style object, in which case
> the specified style is applied only for the string passed to
> gdb.write, after which the default style is re-applied.
>
> Using gdb.write with a style object more closely matches how GDB
> handles styling internally, and has the benefit that the user doesn't
> need to remember to restore the default style when they are done.
> ---
> gdb/NEWS | 3 ++
> gdb/doc/python.texi | 9 +++-
> gdb/python/py-style.c | 27 ++++++++++
> gdb/python/python-internal.h | 15 ++++++
> gdb/python/python.c | 30 ++++++++++--
> .../gdb.python/py-color-pagination.exp | 49 +++++++++++++++++++
> .../gdb.python/py-color-pagination.py | 16 ++++++
> gdb/testsuite/gdb.python/py-style.exp | 29 +++++++++++
> 8 files changed, 172 insertions(+), 6 deletions(-)

The documentation parts are okay, thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>