]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/python: new class gdb.StyleParameterSet
authorAndrew Burgess <aburgess@redhat.com>
Wed, 23 Apr 2025 13:51:17 +0000 (14:51 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Sun, 5 Oct 2025 12:47:18 +0000 (13:47 +0100)
commitd5214580a5f24cb1ca47f095e6d3554cb48eebbe
tree18cb6c808a8ffc96a6538cf3d6178a9a2895be53
parent49e4d0cdca340fd4b4c6ed16cb76aff69d2c69fc
gdb/python: new class gdb.StyleParameterSet

Add a new helper class gdb.StyleParameterSet.  This new class can be
used to simplify creation of new style parameter sets.  A style
parameter set is the 'foreground', 'background', and (optionally), the
'intensity' settings, all grouped under a single prefix command.

And example usage is:

  (gdb) python s = gdb.StyleParameterSet("my-style")
  (gdb) show style my-style
  style my-style background:  The "my-style" style background color is: none
  style my-style foreground:  The "my-style" style foreground color is: none
  style my-style intensity:  The "my-style" style display intensity is: normal
  (gdb)

Having created a gdb.StyleParameterSet, the object itself can be used
to access a named style corresponding to the setting group, like this:

  (gdb) python print(s.style)
  <gdb.Style name='my-style', fg=none, bg=none, intensity=normal>
  (gdb)

Of course, having access to the gdb.Style makes it easy to change the
settings, or the settings can be adjusted via the normal CLI 'set'
commands.

As gdb.StyleParameterSet manages a set of parameters, and the
gdb.Parameter class uses Parameter.value as the attribute to read the
parameter's value, there is also StyleParameterSet.value, but this is
just an alias for StyleParameterSet.style, that is, it allows the
gdb.Style object to be read and written too.

It is worth noting that this class only creates a single level of
prefix command.  As an example GDB has style 'disassembler mnemonic',
where the 'disassembler' part is a group of related styles.  If a user
wanted to create:

  style
    my-style-group
      style-1
      style-2
      style-3

Where each of 'style-1', 'style-2', and 'style-3' will have the full
set of 'foreground', 'background', and 'intensity', then the
gdb.StyleParameterSet can be used to create the 'style-N' part, but
the user will have to create the 'my-style-group' prefix themselves,
possibly using gdb.ParameterPrefix, e.g.:

  gdb.ParameterPrefix("style my-style-group", gdb.COMMAND_NONE)
  gdb.StyleParameterSet("my-style-group style-1")
  gdb.StyleParameterSet("my-style-group style-2")
  gdb.StyleParameterSet("my-style-group style-3")

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/doc/python.texi
gdb/python/lib/gdb/__init__.py
gdb/testsuite/gdb.python/py-style-parameter-set.exp [new file with mode: 0644]