Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
requests>=2.0.0
readchar>=4.0.0
pytest>=7.0.0
webcolors>=24.11.1
10 changes: 8 additions & 2 deletions src/gitfetch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import configparser
from pathlib import Path
from typing import Optional

import webcolors

class ConfigManager:
"""Manages gitfetch configuration."""
Expand Down Expand Up @@ -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:
"""
Expand Down
4 changes: 3 additions & 1 deletion src/gitfetch/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down