]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/python: extend gdb.write to support styled output
authorAndrew Burgess <aburgess@redhat.com>
Tue, 17 Jun 2025 17:09:49 +0000 (18:09 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Sun, 5 Oct 2025 12:48:06 +0000 (13:48 +0100)
commit3c724596812882cc0c3b653330551fae132d6475
tree5607b83fa5e5fba0dd3ff4b9b0123bcb990b284b
parentd5214580a5f24cb1ca47f095e6d3554cb48eebbe
gdb/python: extend gdb.write to support styled output

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.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/doc/python.texi
gdb/python/py-style.c
gdb/python/python-internal.h
gdb/python/python.c
gdb/testsuite/gdb.python/py-color-pagination.exp
gdb/testsuite/gdb.python/py-color-pagination.py
gdb/testsuite/gdb.python/py-style.exp