Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
* [PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes
@ 2026-09-04 14:59 Konstantin Khorenko
  2026-09-04 14:59 ` [PATCH b4 2/2] review-tui: read native_ansi_color for the trailer overlay header Konstantin Khorenko
  2026-09-15 20:32 ` [PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes Konstantin Ryabitsev
  0 siblings, 2 replies; 3+ messages in thread
From: Konstantin Khorenko @ 2026-09-04 14:59 UTC (permalink / raw)
  To: tools; +Cc: Konstantin Khorenko

Resolving styles under an ansi theme (TEXTUAL_THEME=ansi-light/dark,
or one picked from the command palette) crashes:

  MissingStyle: 'transparent' is not a valid color

Textual's ansi themes resolve $panel/$surface to the CSS keyword
"transparent" and can suffix a colour with an alpha percentage; Rich
accepts neither. Reduce both to the terminal default colour in
_to_rich_color(), which fixes every consumer of resolve_styles().

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Assisted-by: claude-sonnet-5
---
 src/b4/tui/_common.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/b4/tui/_common.py b/src/b4/tui/_common.py
index 844d980..a378dd3 100644
--- a/src/b4/tui/_common.py
+++ b/src/b4/tui/_common.py
@@ -278,9 +278,20 @@ def matches_limit(
     variable system.  Rich expects ``green``, ``bright_blue``, etc.
     Non-ansi values (hex codes, named CSS colours) pass through unchanged.
     ``ansi_default`` maps to ``default``.
+
+    Textual's ansi themes resolve ``$panel``/``$surface`` to the CSS
+    keyword ``transparent`` and can append an alpha percentage
+    (``default 50%``). Rich understands neither, and feeding one into a
+    style string raises ``MissingStyle``, so both are reduced to the
+    terminal default colour.
     """
+    parts = textual_color.rsplit(' ', 1)
+    if len(parts) == 2 and parts[1].endswith('%'):
+        textual_color = parts[0]  # drop the alpha suffix
     if textual_color.startswith('ansi_'):
         return textual_color[5:]  # strip 'ansi_' prefix
+    if textual_color == 'transparent':
+        return 'default'
     return textual_color
 
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-15 20:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 14:59 [PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes Konstantin Khorenko
2026-09-04 14:59 ` [PATCH b4 2/2] review-tui: read native_ansi_color for the trailer overlay header Konstantin Khorenko
2026-09-15 20:32 ` [PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes Konstantin Ryabitsev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox