Skip to content

Commit fa23260

Browse files
committed
display tweaks and languages normalize
1 parent be8681a commit fa23260

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "gitfetch"
7-
version = "1.0.17"
7+
version = "1.0.18"
88
description = "A neofetch-style CLI tool for GitHub statistics"
99
readme = "README.md"
1010
requires-python = ">=3.8"

src/gitfetch/display.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
from datetime import datetime
1111
from .config import ConfigManager
1212

13+
1314
class DisplayFormatter:
1415
"""Formats and displays GitHub stats in a neofetch-style layout."""
1516

16-
def __init__(self,config_manager: ConfigManager):
17+
def __init__(self, config_manager: ConfigManager):
1718
"""Initialize the display formatter."""
1819
self.terminal_width = shutil.get_terminal_size().columns
1920
self.enable_color = sys.stdout.isatty()
2021
self.colors = config_manager.get_colors()
2122

2223
def display(self, username: str, user_data: Dict[str, Any],
23-
stats: Dict[str, Any],spaced=True) -> None:
24+
stats: Dict[str, Any], spaced=True) -> None:
2425
"""
2526
Display GitHub statistics in neofetch style.
2627
@@ -35,13 +36,13 @@ def display(self, username: str, user_data: Dict[str, Any],
3536

3637
if layout == 'minimal':
3738
# Only show contribution graph
38-
self._display_minimal(username, stats,spaced)
39+
self._display_minimal(username, stats, spaced)
3940
elif layout == 'compact':
4041
# Show graph and key info
41-
self._display_compact(username, user_data, stats,spaced)
42+
self._display_compact(username, user_data, stats, spaced)
4243
else:
4344
# Full layout with all sections
44-
self._display_full(username, user_data, stats,spaced)
45+
self._display_full(username, user_data, stats, spaced)
4546

4647
print() # Empty line at the end
4748

@@ -68,11 +69,11 @@ def _display_minimal(self, username: str, stats: Dict[str, Any], spaced=True) ->
6869
print(line)
6970

7071
def _display_compact(self, username: str, user_data: Dict[str, Any],
71-
stats: Dict[str, Any], spaced= True) -> None:
72-
"""Display graph and minimal info side-by-side."""
72+
stats: Dict[str, Any], spaced=True) -> None:
73+
"""Display graph and minimal info side-by-side (no languages)."""
7374
contrib_graph = stats.get('contribution_graph', [])
7475
recent_weeks = self._get_recent_weeks(contrib_graph)
75-
graph_width = max(40, (self.terminal_width - 10) // 2)
76+
graph_width = max(40, (self.terminal_width - 40) // 2)
7677
graph_lines = self._get_contribution_graph_lines(
7778
contrib_graph,
7879
username,
@@ -84,7 +85,6 @@ def _display_compact(self, username: str, user_data: Dict[str, Any],
8485
info_lines = self._format_user_info_compact(user_data, stats)
8586
achievements = self._build_achievements(recent_weeks)
8687

87-
# Combine sections
8888
right_side = list(info_lines)
8989
if achievements:
9090
right_side.append("")
@@ -96,7 +96,6 @@ def _display_compact(self, username: str, user_data: Dict[str, Any],
9696
graph_part = (graph_lines[i] if i < len(graph_lines) else "")
9797
graph_len = self._display_width(graph_part)
9898
padding = " " * max(0, graph_width - graph_len)
99-
10099
info_part = (right_side[i] if i < len(right_side) else "")
101100
print(f"{graph_part}{padding} {info_part}")
102101

@@ -116,11 +115,17 @@ def _display_full(self, username: str, user_data: Dict[str, Any],
116115
pull_request_lines = self._format_pull_requests(stats)
117116
issue_lines = self._format_issues(stats)
118117

119-
section_columns = [
120-
pull_request_lines,
121-
issue_lines,
122-
]
123-
118+
# Only show PR/Issue columns if they fit side by side, otherwise show neither
119+
section_columns = []
120+
if pull_request_lines and issue_lines:
121+
pr_width = max((self._display_width(line)
122+
for line in pull_request_lines), default=0)
123+
issue_width = max((self._display_width(line)
124+
for line in issue_lines), default=0)
125+
total_width = pr_width + issue_width + len(" ") # gap
126+
if total_width <= graph_width:
127+
section_columns = [pull_request_lines, issue_lines]
128+
# Do not show only one column; only show both if they fit
124129
combined_sections = self._combine_section_grid(
125130
section_columns, width_limit=graph_width
126131
)
@@ -132,7 +137,7 @@ def _display_full(self, username: str, user_data: Dict[str, Any],
132137
language_lines = self._format_languages(stats)
133138

134139
right_side = list(info_lines)
135-
if language_lines:
140+
if language_lines and self.terminal_width >= 120:
136141
right_side.append("")
137142
right_side.extend(language_lines)
138143

src/gitfetch/fetcher.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,28 @@ def _calculate_language_stats(self, repos: list) -> Dict[str, float]:
236236
Returns:
237237
Dictionary mapping language names to percentages
238238
"""
239-
language_counts: Dict[str, int] = {}
239+
from collections import defaultdict
240+
241+
# First pass: collect all language occurrences with their casing
242+
language_occurrences: Dict[str, Dict[str, int]] = defaultdict(
243+
lambda: defaultdict(int))
240244

241245
for repo in repos:
242246
language = repo.get('language')
243247
if language:
244-
language_counts[language] = language_counts.get(
245-
language, 0) + 1
248+
# Group by lowercase name, but keep track of different casings
249+
normalized = language.lower()
250+
language_occurrences[normalized][language] += 1
251+
252+
# Second pass: choose canonical casing (most frequent) and sum counts
253+
language_counts: Dict[str, int] = {}
254+
255+
for normalized, casings in language_occurrences.items():
256+
# Find the most common casing
257+
canonical_name = max(casings.items(), key=lambda x: x[1])[0]
258+
# Sum all occurrences for this language
259+
total_count = sum(casings.values())
260+
language_counts[canonical_name] = total_count
246261

247262
# Calculate percentages
248263
total = sum(language_counts.values())

0 commit comments

Comments
 (0)