)]}'
{
  "commit": "49e4d0cdca340fd4b4c6ed16cb76aff69d2c69fc",
  "tree": "60d7ac74141f847fb3a7b3fb70e1a277e8195ffd",
  "parents": [
    "e54066c23716879e44c9f43b52137664156b9d66"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Fri Apr 18 14:24:03 2025 +0100"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Sun Oct 05 13:40:46 2025 +0100"
  },
  "message": "gdb/python: add gdb.Style class\n\nThis commit adds a new gdb.Style class.  This class represents a\ncomplete style within GDB.  A complete style is a collection of\nforeground color, background color, and an intensity.\n\nA gdb.Style comes in two flavours, named, and unnamed.\n\nA named style is one that is based on an existing style within GDB.\nFor example, we have \u0027set style filename ...\u0027, the name of this style\nis \u0027filename\u0027.  We also have \u0027set style disassembler mnemonic ...\u0027,\nthe name of this style is \u0027disassembler mnemonic\u0027.  A named style is\ncreated by passing the name of the style, like this:\n\n  (gdb) python s1 \u003d gdb.Style(\"filename\")\n  (gdb) python s2 \u003d gdb.Style(\"disassembler mnemonic\")\n\nThe other type of style is an unnamed style.  An unnamed style is\ncreated using a foreground and background color, along with an\nintensity.  Colors are specified using gdb.Color objects.  An example\nof creating an unnamed style is:\n\n  (gdb) python s3 \u003d gdb.Style(foreground\u003dgdb.Color(\u0027red\u0027),\n                              background\u003dgdb.Color(\u0027green\u0027),\n\t\t\t      intensity\u003dgdb.INTENSITY_BOLD)\n\nWe can see here an example of the new intensity constants that have\nbeen added in this commit, there is gdb.INTENSITY_NORMAL,\ngdb.INTENSITY_BOLD, and gdb.INTENSITY_DIM.  All of the arguments are\noptional, the default for the colors is gdb.Color(), which will apply\nthe terminal default, and the default intensity is\ngdb.INTENSITY_NORMAL.\n\nHaving created a gdb.Style object there are two ways that it can be\nused to style GDB\u0027s output.  The Style.escape_sequence() method\nreturns the escape sequence needed to apply this style, this can be\nused as in:\n\n  (gdb) python print(s1.escape_sequence() + \"Filename Style\")\n\nThe problem with this approach is that it is the users responsibility\nto restore the style to the default when they are done.  In the above\nexample, all output after the escape sequence is printed, including\nthe next GDB prompt, will be in the s1 (filename) style.  Which is why\nthe Style.apply method exists.  This method takes a string and returns\nthe same string with escape sequences added before and after.  The\nbefore sequence switches to the style, while the after escape sequence\nrestores the terminal default style.  This can be used like:\n\n  (gdb) python print(s1.apply(\"Filename Style\"))\n\nNow only the \u0027Filename Style\u0027 text will be styled.  The next GDB\nprompt will be in the default terminal style.  Personally, I think the\napply method is the more useful, but having \u0027escape_sequence\u0027 matches\nwhat gdb.Color offers, though if/when this patch is merged, I might\npropose a similar \u0027apply\u0027 type method for the gdb.Color class.\n\nThe gdb.Style class has \u0027foreground\u0027, \u0027background\u0027, and \u0027intensity\u0027\nattributes which, when read, return the obvious values.  These\nattributes can also be written too.\n\nWhen writing to an attribute of an unnamed Style object then the Style\nobject itself is updated, as you might expect.\n\nWhen writing to an attribute of a named Style then the style setting\nitself is updated as the following example shows:\n\n  (gdb) python s1 \u003d gdb.Style(\"filename\")\n  (gdb) python print(s1.foreground)\n  green\n  (gdb) show style filename foreground\n  The \"filename\" style foreground color is: green\n  (gdb) python s1.foreground\u003dgdb.Color(\"red\")\n  (gdb) python print(s1.foreground)\n  red\n  (gdb) show style filename foreground\n  The \"filename\" style foreground color is: red\n  (gdb)\n\nWe can see that a gdb.Style object is connected to the underlying\nstyle settings, it doesn\u0027t take a copy of the style settings at\ncreation time.  And the relationship works both ways.  Continuing the\nabove example:\n\n  (gdb) set style filename foreground blue\n  (gdb) python print(s1.foreground)\n  blue\n  (gdb)\n\nHere we see that changing the setting value causes the gdb.Style\nobject to update.  And this is what you would want.  I imagine this\nbeing used in a Python extension to GDB, where a user might create\nglobal objects for some named styles, and then use these globals to\nformat output from some custom commands.  If a user of an extension\nchanges a style setting then the extension wants to adapt to that\nchange.\n\nBoth the Style.escape_sequence and Style.apply methods take the global\nstyle enabled setting into consideration.  If styling is disabled then\nStyle.escape_sequence will return an empty string, and Style.apply\nwill return an unmodified copy of the original string object (actually\nthe input object with Py_INCREF applied).\n\nThere is also support for representing a gdb.Style as a string:\n\n  (gdb) python s1 \u003d gdb.Style(\"filename\")\n  (gdb) python print(s1)\n  \u003cgdb.Style name\u003d\u0027filename\u0027, fg\u003dgreen, bg\u003dnone, intensity\u003dnormal\u003e\n  (gdb)\n\nUnnamed styles are similar, but don\u0027t have a \u0027name\u0027 field.\n\nReviewed-By: Eli Zaretskii \u003celiz@gnu.org\u003e\nApproved-By: Tom Tromey \u003ctom@tromey.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "486d3dbdc5570a68cf2c73e9879a1f4369406bb5",
      "old_mode": 33188,
      "old_path": "gdb/Makefile.in",
      "new_id": "3f645386a1e08505d7f202aebaebcf3ed4a529f8",
      "new_mode": 33188,
      "new_path": "gdb/Makefile.in"
    },
    {
      "type": "modify",
      "old_id": "01d14044aa046264177552557b5b25f062ed0714",
      "old_mode": 33188,
      "old_path": "gdb/NEWS",
      "new_id": "2b76e2fb2b9a31ce4a7137fdd6b3a4fd08f3e92d",
      "new_mode": 33188,
      "new_path": "gdb/NEWS"
    },
    {
      "type": "modify",
      "old_id": "00833cdec9d0709b71629e47ca5162563eb8a567",
      "old_mode": 33188,
      "old_path": "gdb/doc/python.texi",
      "new_id": "6472bd37071f3c01041332b1aa83070204cf372f",
      "new_mode": 33188,
      "new_path": "gdb/doc/python.texi"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "51b35f2fa7e6967dcb6ade236afe195f2205baa8",
      "new_mode": 33188,
      "new_path": "gdb/python/py-style.c"
    },
    {
      "type": "modify",
      "old_id": "e7a9e4fec5fbeec754861218e1c3a074ebe8a5ad",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.python/py-color-pagination.exp",
      "new_id": "1974dbb41868c1d7e4e1ba00a5f2964b21aa8075",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-color-pagination.exp"
    },
    {
      "type": "modify",
      "old_id": "efd501eedf5cddb3ac15f83bf4cb278b590b83ec",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.python/py-color-pagination.py",
      "new_id": "f0252e5bf865893a195f2393b2f276e516932425",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-color-pagination.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "b2efe9a97e36ce79200faf49d802c66064a55cd6",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-style.exp"
    },
    {
      "type": "modify",
      "old_id": "1ea3556869d8e711cdce6bb86c32c320c134607f",
      "old_mode": 33188,
      "old_path": "gdb/ui-style.h",
      "new_id": "64f710b0cc1678e04a6f7ebc55b8c96a0c60e56e",
      "new_mode": 33188,
      "new_path": "gdb/ui-style.h"
    }
  ]
}
