Fix hex color handling in SVG exporter

pyte provides 256-color/truecolor values without # prefix (e.g., 'ff8700').
Added check to prepend # for 6-digit hex strings.
This commit is contained in:
GitHub Copilot
2026-01-24 18:34:13 +00:00
parent d5a060d6aa
commit e161d94bcc
2 changed files with 13 additions and 1 deletions
+6 -1
View File
@@ -68,10 +68,15 @@ def _color_to_hex(color: str, is_foreground: bool = True) -> str:
if color == "default":
return DEFAULT_FG if is_foreground else DEFAULT_BG
# Already a hex color
# Already a hex color with #
if color.startswith("#"):
return color
# Hex color without # prefix (pyte's 256-color/truecolor format)
# Check if it looks like a hex color (6 hex digits)
if len(color) == 6 and all(c in "0123456789abcdefABCDEF" for c in color):
return f"#{color}"
# Named color lookup (case-insensitive)
lower = color.lower()
if lower in ANSI_COLORS: