From 0cae07cba6222fadfbaf1c8ea603530a42319304 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Sat, 24 Jan 2026 11:23:01 +0000 Subject: [PATCH] fix: complete pyte-to-Rich color mapping Audited all color names from both libraries and added complete mappings: pyte standard ANSI: - brown -> yellow (pyte uses 'brown' for ANSI color 33) pyte bright/AIXTERM colors: - brightblack -> bright_black - brightred -> bright_red - brightgreen -> bright_green - brightbrown -> bright_yellow - brightblue -> bright_blue - brightmagenta -> bright_magenta - bfightmagenta -> bright_magenta (typo in pyte's BG_AIXTERM) - brightcyan -> bright_cyan - brightwhite -> bright_white Also handles hex colors from 256-color and truecolor modes by adding '#' prefix (e.g., 'ff8700' -> '#ff8700'). Bumps version to 0.1.15. --- pyproject.toml | 2 +- src/textual_webterm/local_server.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6d08267..b2767ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual-webterm" -version = "0.1.14" +version = "0.1.15" description = "Serve terminal sessions over the web" authors = ["Will McGugan "] license = "MIT" diff --git a/src/textual_webterm/local_server.py b/src/textual_webterm/local_server.py index 4dafd22..7827bad 100644 --- a/src/textual_webterm/local_server.py +++ b/src/textual_webterm/local_server.py @@ -44,21 +44,32 @@ SVG_MONO_FONT_STACK = ( ) # Map pyte color names to Rich-compatible names +# pyte uses different naming conventions than Rich for some colors PYTE_TO_RICH_COLOR = { + # Bright colors (pyte concatenates, Rich uses underscore) "brightblack": "bright_black", "brightred": "bright_red", "brightgreen": "bright_green", + "brightbrown": "bright_yellow", # bright brown = bright yellow "brightyellow": "bright_yellow", "brightblue": "bright_blue", "brightmagenta": "bright_magenta", + "bfightmagenta": "bright_magenta", # typo in pyte's BG_AIXTERM "brightcyan": "bright_cyan", "brightwhite": "bright_white", - "brown": "yellow", # pyte uses 'brown' for ANSI yellow + # Standard colors + "brown": "yellow", # pyte uses 'brown' for ANSI color 33 (yellow) } def _pyte_color_to_rich(color: str) -> str: - """Convert pyte color to Rich-compatible color string.""" + """Convert pyte color to Rich-compatible color string. + + Handles: + - Named color mappings (e.g., 'brown' -> 'yellow') + - Bright color name format (e.g., 'brightred' -> 'bright_red') + - Hex colors from 256-color/truecolor (e.g., 'ff8700' -> '#ff8700') + """ if color == "default": return color # Check mapping first