From 084c8718e837e122ea1d6bdfddb5fff93625c14a Mon Sep 17 00:00:00 2001 From: zeviraty Date: Wed, 29 Oct 2025 11:16:38 +0100 Subject: [PATCH] Added webcolors dependency & fixed named colors --- requirements.txt | 1 + src/gitfetch/config.py | 10 ++++++++-- src/gitfetch/display.py | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 17364d1..eae9653 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ requests>=2.0.0 readchar>=4.0.0 pytest>=7.0.0 +webcolors>=24.11.1 diff --git a/src/gitfetch/config.py b/src/gitfetch/config.py index 01c1cd8..6c67b4f 100644 --- a/src/gitfetch/config.py +++ b/src/gitfetch/config.py @@ -5,7 +5,7 @@ import configparser from pathlib import Path from typing import Optional - +import webcolors class ConfigManager: """Manages gitfetch configuration.""" @@ -100,7 +100,13 @@ def get_colors(self) -> dict: Returns: dict: color name to hex code """ - return dict(self.config._sections["COLORS"]) + parsed = {} + for k,v in self.config._sections["COLORS"].items(): + if not v.startswith("#") and v in webcolors.names(): + parsed[k] = webcolors.name_to_hex(v) + else: + parsed[k] = v + return parsed def get_ansi_colors(self) -> dict: """ diff --git a/src/gitfetch/display.py b/src/gitfetch/display.py index 4eb48a6..b55d6cd 100644 --- a/src/gitfetch/display.py +++ b/src/gitfetch/display.py @@ -11,7 +11,7 @@ from .config import ConfigManager from .text_patterns import CHAR_PATTERNS import subprocess - +import webcolors def hex_to_ansi(hex_color: str, background: bool = False) -> str: """Convert hex color to ANSI escape code.""" @@ -1294,6 +1294,8 @@ def _colorize(self, text: str, color: str) -> str: color_code = colors.get(color.lower()) reset = colors['reset'] + if not color_code and color_code in webcolors.names(): + color_code = hex_to_ansi(webcolors.name_to_hex(color_code)) if not self.enable_color or not color_code: return text