diff options
author | Andrew Burgess <aburgess@redhat.com> | 2025-04-29 17:57:06 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2025-05-06 11:24:28 +0100 |
commit | 41b0ab843fb8f1639c34776512f0886af96a36a9 (patch) | |
tree | 55a6a3281d6d41bb1aa510552361959d2fb92d75 /gdb/doc | |
parent | 4dd03f30caa7cae1d41ff070e7519b09d5d95648 (diff) | |
download | binutils-41b0ab843fb8f1639c34776512f0886af96a36a9.zip binutils-41b0ab843fb8f1639c34776512f0886af96a36a9.tar.gz binutils-41b0ab843fb8f1639c34776512f0886af96a36a9.tar.bz2 |
gdb/python/guile: check if styling is disabled in Color.escape_sequence
I noticed that the gdb.Color.escape_sequence() method would produce an
escape sequence even when styling is disabled.
I think this is the wrong choice. Ideally, when styling is
disabled (e.g. with 'set style enabled off'), GDB should not be
producing styled output.
If a GDB extension is using gdb.Color to apply styling to the output,
then currently, the extension should be checking 'show style enabled'
any time Color.escape_sequence() is used. This means lots of code
duplication, and the possibility that some locations will be missed,
which means disabling styling no longer does what it says.
I propose that Color.escape_sequence() should return the empty string
if styling is disabled. A Python extension can then do:
python
c_none = gdb.Color('none')
c_red = gdb.Color('red')
print(c_red.escape_sequence(True)
+ "Text in red."
+ c_none.escape_sequence(True))
end
If styling is enable this will print some red text. And if styling is
disabled, then it will print text in the terminal's default color.
I have applied the same fix to the guile API.
I have extended the tests to cover this case.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/guile.texi | 3 | ||||
-rw-r--r-- | gdb/doc/python.texi | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi index c6808ef..c6d889f 100644 --- a/gdb/doc/guile.texi +++ b/gdb/doc/guile.texi @@ -3899,6 +3899,9 @@ Return string to change terminal's color to this. If @var{is_foreground} is @code{#t}, then the returned sequence will change foreground color. Otherwise, the returned sequence will change background color. + +If styling is currently disabled (@pxref{Output Styling,,@kbd{set style +enabled}}), then this procedure will return an empty string. @end deffn When color is initialized, its color space must be specified. The diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index afbd62f..7bb6503 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -7101,6 +7101,9 @@ Returns string to change terminal's color to this. If @var{is_foreground} is @code{True}, then the returned sequence will change foreground color. Otherwise, the returned sequence will change background color. + +If styling is currently disabled (@pxref{Output Styling,,@kbd{set style +enabled}}), then this method will return an empty string. @end defun When color is initialized, its color space must be specified. The |