Skip to content

Commit dfded09

Browse files
authored
Merge pull request #60 from Zeviraty/main
Added webcolors dependency & fixed named colors
2 parents 51c33e7 + 084c871 commit dfded09

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
requests>=2.0.0
44
readchar>=4.0.0
55
pytest>=7.0.0
6+
webcolors>=24.11.1

src/gitfetch/config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import configparser
66
from pathlib import Path
77
from typing import Optional
8-
8+
import webcolors
99

1010
class ConfigManager:
1111
"""Manages gitfetch configuration."""
@@ -100,7 +100,13 @@ def get_colors(self) -> dict:
100100
Returns:
101101
dict: color name to hex code
102102
"""
103-
return dict(self.config._sections["COLORS"])
103+
parsed = {}
104+
for k,v in self.config._sections["COLORS"].items():
105+
if not v.startswith("#") and v in webcolors.names():
106+
parsed[k] = webcolors.name_to_hex(v)
107+
else:
108+
parsed[k] = v
109+
return parsed
104110

105111
def get_ansi_colors(self) -> dict:
106112
"""

src/gitfetch/display.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .config import ConfigManager
1212
from .text_patterns import CHAR_PATTERNS
1313
import subprocess
14-
14+
import webcolors
1515

1616
def hex_to_ansi(hex_color: str, background: bool = False) -> str:
1717
"""Convert hex color to ANSI escape code."""
@@ -1294,6 +1294,8 @@ def _colorize(self, text: str, color: str) -> str:
12941294

12951295
color_code = colors.get(color.lower())
12961296
reset = colors['reset']
1297+
if not color_code and color_code in webcolors.names():
1298+
color_code = hex_to_ansi(webcolors.name_to_hex(color_code))
12971299

12981300
if not self.enable_color or not color_code:
12991301
return text

0 commit comments

Comments
 (0)