Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: tools@kernel.org
Cc: Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: [PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes
Date: Fri,  4 Sep 2026 16:59:50 +0200	[thread overview]
Message-ID: <20260904145951.1414701-1-khorenko@virtuozzo.com> (raw)

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


             reply	other threads:[~2026-09-04 14:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 14:59 Konstantin Khorenko [this message]
2026-09-04 14:59 ` [PATCH b4 2/2] review-tui: read native_ansi_color for the trailer overlay header Konstantin Khorenko

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=20260904145951.1414701-1-khorenko@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=tools@kernel.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