[PATCH b4 1/2] tui: fix MissingStyle crash under Textual ansi themes
flat view
COLD27d
From: Konstantin Khorenko <hidden>
Date: 2026-09-04 14:59:53
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted> 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