88import re
99import unicodedata
1010from datetime import datetime
11-
11+ from . config import ConfigManager
1212
1313class DisplayFormatter :
1414 """Formats and displays GitHub stats in a neofetch-style layout."""
1515
16- def __init__ (self ):
16+ def __init__ (self , config_manager : ConfigManager ):
1717 """Initialize the display formatter."""
1818 self .terminal_width = shutil .get_terminal_size ().columns
1919 self .enable_color = sys .stdout .isatty ()
20+ self .colors = config_manager .get_colors ()
2021
2122 def display (self , username : str , user_data : Dict [str , Any ],
22- stats : Dict [str , Any ]) -> None :
23+ stats : Dict [str , Any ], spaced = True ) -> None :
2324 """
2425 Display GitHub statistics in neofetch style.
2526
2627 Args:
2728 username: GitHub username
2829 user_data: User profile data
2930 stats: User statistics data
31+ spaced: Spaced layout
3032 """
3133 # Determine layout based on terminal width
3234 layout = self ._determine_layout ()
3335
3436 if layout == 'minimal' :
3537 # Only show contribution graph
36- self ._display_minimal (username , stats )
38+ self ._display_minimal (username , stats , spaced )
3739 elif layout == 'compact' :
3840 # Show graph and key info
39- self ._display_compact (username , user_data , stats )
41+ self ._display_compact (username , user_data , stats , spaced )
4042 else :
4143 # Full layout with all sections
42- self ._display_full (username , user_data , stats )
44+ self ._display_full (username , user_data , stats , spaced )
4345
4446 print () # Empty line at the end
4547
@@ -52,20 +54,21 @@ def _determine_layout(self) -> str:
5254 else :
5355 return 'full'
5456
55- def _display_minimal (self , username : str , stats : Dict [str , Any ]) -> None :
57+ def _display_minimal (self , username : str , stats : Dict [str , Any ], spaced = True ) -> None :
5658 """Display only contribution graph for narrow terminals."""
5759 contrib_graph = stats .get ('contribution_graph' , [])
5860 graph_lines = self ._get_contribution_graph_lines (
5961 contrib_graph ,
6062 username ,
6163 width_constraint = self .terminal_width - 4 ,
62- include_sections = False
64+ include_sections = False ,
65+ spaced = spaced ,
6366 )
6467 for line in graph_lines :
6568 print (line )
6669
6770 def _display_compact (self , username : str , user_data : Dict [str , Any ],
68- stats : Dict [str , Any ]) -> None :
71+ stats : Dict [str , Any ], spaced = True ) -> None :
6972 """Display graph and minimal info side-by-side."""
7073 contrib_graph = stats .get ('contribution_graph' , [])
7174 recent_weeks = self ._get_recent_weeks (contrib_graph )
@@ -74,7 +77,8 @@ def _display_compact(self, username: str, user_data: Dict[str, Any],
7477 contrib_graph ,
7578 username ,
7679 width_constraint = graph_width ,
77- include_sections = False
80+ include_sections = False ,
81+ spaced = spaced ,
7882 )
7983
8084 info_lines = self ._format_user_info_compact (user_data , stats )
@@ -97,15 +101,16 @@ def _display_compact(self, username: str, user_data: Dict[str, Any],
97101 print (f"{ graph_part } { padding } { info_part } " )
98102
99103 def _display_full (self , username : str , user_data : Dict [str , Any ],
100- stats : Dict [str , Any ]) -> None :
104+ stats : Dict [str , Any ], spaced = True ) -> None :
101105 """Display full layout with graph and all info sections."""
102106 contrib_graph = stats .get ('contribution_graph' , [])
103107 graph_width = max (50 , (self .terminal_width - 10 ) // 2 )
104108 left_side = self ._get_contribution_graph_lines (
105109 contrib_graph ,
106110 username ,
107111 width_constraint = graph_width ,
108- include_sections = False
112+ include_sections = False ,
113+ spaced = spaced ,
109114 )
110115
111116 pull_request_lines = self ._format_pull_requests (stats )
@@ -152,7 +157,8 @@ def _display_full(self, username: str, user_data: Dict[str, Any],
152157 def _get_contribution_graph_lines (self , weeks_data : list ,
153158 username : str ,
154159 width_constraint : int = None ,
155- include_sections : bool = True ) -> list :
160+ include_sections : bool = True ,
161+ spaced : bool = True ) -> list :
156162 """
157163 Get contribution graph as lines for display.
158164
@@ -187,7 +193,10 @@ def _get_contribution_graph_lines(self, weeks_data: list,
187193 for idx in range (7 ):
188194 day = days [idx ] if idx < len (days ) else {}
189195 count = day .get ('contributionCount' , 0 )
190- block = self ._get_contribution_block_spaced (count )
196+ if spaced :
197+ block = self ._get_contribution_block_spaced (count )
198+ else :
199+ block = self ._get_contribution_block (count )
191200 day_rows [idx ].append (block )
192201
193202 lines = [* header_lines ]
@@ -825,22 +834,7 @@ def _colorize(self, text: str, color: str) -> str:
825834 if not text :
826835 return text
827836
828- colors = {
829- 'reset' : '\033 [0m' ,
830- 'bold' : '\033 [1m' ,
831- 'dim' : '\033 [2m' ,
832- 'red' : '\033 [91m' ,
833- 'green' : '\033 [92m' ,
834- 'yellow' : '\033 [93m' ,
835- 'blue' : '\033 [94m' ,
836- 'magenta' : '\033 [95m' ,
837- 'cyan' : '\033 [96m' ,
838- 'white' : '\033 [97m' ,
839- 'orange' : '\033 [38;2;255;165;0m' ,
840- 'accent' : '\033 [1m' ,
841- 'header' : '\033 [38;2;118;215;161m' ,
842- 'muted' : '\033 [2m'
843- }
837+ colors = self .colors
844838
845839 color_code = colors .get (color .lower ())
846840 reset = colors ['reset' ]
@@ -882,15 +876,15 @@ def _get_contribution_block(self, count: int) -> str:
882876
883877 reset = '\033 [0m'
884878 if count == 0 :
885- color = ' \033 [48;5;238m'
879+ color = self . colors [ '0' ]
886880 elif count < 3 :
887- color = ' \033 [48;5;28m'
881+ color = self . colors [ '1' ]
888882 elif count < 7 :
889- color = ' \033 [48;5;34m'
883+ color = self . colors [ '2' ]
890884 elif count < 13 :
891- color = ' \033 [48;5;40m'
885+ color = self . colors [ '3' ]
892886 else :
893- color = ' \033 [48;5;82m'
887+ color = self . colors [ '4' ]
894888
895889 return f"{ color } { reset } "
896890
0 commit comments