From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/5] Add ui_file_style::merge
Date: Fri, 12 Jun 2026 08:25:24 -0600 [thread overview]
Message-ID: <20260612-submit-zebra-style-v1-4-cfd00b5c984c@tromey.com> (raw)
In-Reply-To: <20260612-submit-zebra-style-v1-0-cfd00b5c984c@tromey.com>
This adds ui_file_style::merge, a new method allowing two styles to be
merged together.
---
gdb/ui-style.h | 15 +++++++++++++++
gdb/unittests/style-selftests.c | 8 ++++++++
2 files changed, 23 insertions(+)
diff --git a/gdb/ui-style.h b/gdb/ui-style.h
index 52f5a5a104d..53df949bd85 100644
--- a/gdb/ui-style.h
+++ b/gdb/ui-style.h
@@ -419,6 +419,21 @@ struct ui_file_style
return this;
}
+ /* Combine STYLE with this style, returning a new merged style. Any
+ non-"empty" attributes of STYLE override the corresponding
+ attributes of this style. */
+ ui_file_style merge (const ui_file_style &style) const
+ {
+ ui_file_style result = *this;
+ if (!style.m_foreground.is_none ())
+ result.m_foreground = style.m_foreground;
+ if (!style.m_background.is_none ())
+ result.m_background = style.m_background;
+ result.m_intensity = style.m_intensity;
+ result.m_reverse = style.m_reverse;
+ return result;
+ }
+
/* nullptr-terminated list of names corresponding to enum basic_color. */
static const std::vector<const char *> basic_color_enums;
diff --git a/gdb/unittests/style-selftests.c b/gdb/unittests/style-selftests.c
index 9035050bd6c..0fa8074f719 100644
--- a/gdb/unittests/style-selftests.c
+++ b/gdb/unittests/style-selftests.c
@@ -119,6 +119,14 @@ run_tests ()
SELF_CHECK (!style.is_underline ());
SELF_CHECK (style.is_reverse ());
SELF_CHECK (style.to_ansi () == "\033[38;2;83;84;85;48;2;0;1;254;2;23;24;7m");
+
+ const ui_file_style redblack_style (ui_file_style::RED, ui_file_style::BLACK);
+ const ui_file_style rednone_style (ui_file_style::RED, ui_file_style::NONE);
+ const ui_file_style noneblack_style (ui_file_style::NONE, ui_file_style::BLACK);
+ SELF_CHECK (ui_file_style ().merge (redblack_style) == redblack_style);
+ SELF_CHECK (redblack_style.merge ({}) == redblack_style);
+ SELF_CHECK (rednone_style.merge (noneblack_style) == redblack_style);
+ SELF_CHECK (noneblack_style.merge (rednone_style) == redblack_style);
}
} /* namespace style */
--
2.49.0
next prev parent reply other threads:[~2026-06-12 14:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 14:25 [PATCH 0/5] Add zebra-striping to CLI tables Tom Tromey
2026-06-12 14:25 ` [PATCH 1/5] Ensure tgetent is called before tgetnum Tom Tromey
2026-06-12 14:25 ` [PATCH 2/5] Make two ui_out methods 'private' Tom Tromey
2026-06-12 14:25 ` [PATCH 3/5] Allow "phony" ui-out tables Tom Tromey
2026-06-12 14:25 ` Tom Tromey [this message]
2026-06-12 14:25 ` [PATCH 5/5] Add zebra-striping to CLI table display Tom Tromey
2026-06-12 15:14 ` Eli Zaretskii
2026-06-13 14:28 ` Matt Rice
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260612-submit-zebra-style-v1-4-cfd00b5c984c@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox