@@ -48,11 +48,18 @@ def _load_config(self) -> None:
4848 }
4949 if self .CONFIG_FILE .exists ():
5050 self .config .read (self .CONFIG_FILE )
51- if "COLORS" in self .config :
51+ if "COLORS" in self .config ._sections :
52+ # Filter out non-color keys that might have been corrupted
53+ colors_data = self .config ._sections ['COLORS' ]
54+ valid_color_keys = set (default_colors .keys ())
55+ filtered_colors = {k : v for k , v in colors_data .items ()
56+ if k in valid_color_keys }
5257 self .config ._sections ['COLORS' ] = {
53- ** default_colors , ** self . config . _sections [ 'COLORS' ] }
58+ ** default_colors , ** filtered_colors }
5459 else :
55- self .config ._sections ['COLORS' ] = default_colors
60+ self .config .add_section ('COLORS' )
61+ for key , value in default_colors .items ():
62+ self .config .set ('COLORS' , key , value )
5663 else :
5764 # Create default config
5865 self .config ['DEFAULT' ] = {
@@ -208,6 +215,49 @@ def set_provider_url(self, url: str) -> None:
208215 self .config ['DEFAULT' ] = {}
209216 self .config ['DEFAULT' ]['provider_url' ] = url
210217
218+ def get_custom_box (self ) -> Optional [str ]:
219+ """
220+ Get the custom box character from config.
221+
222+ Returns:
223+ Custom box character or None if not set
224+ """
225+ box = self .config .get ('DEFAULT' , 'custom_box' , fallback = '' )
226+ return box if box else None
227+
228+ def set_custom_box (self , box : str ) -> None :
229+ """
230+ Set the custom box character in config.
231+
232+ Args:
233+ box: Custom box character to use
234+ """
235+ if 'DEFAULT' not in self .config :
236+ self .config ['DEFAULT' ] = {}
237+ self .config ['DEFAULT' ]['custom_box' ] = box
238+
239+ def get_show_date (self ) -> bool :
240+ """
241+ Get whether to show date labels on the contribution graph.
242+
243+ Returns:
244+ True if date labels should be shown, False otherwise
245+ """
246+ show_date_str = self .config .get ('DEFAULT' , 'show_date' ,
247+ fallback = 'true' )
248+ return show_date_str .lower () in ('true' , '1' , 'yes' , 'on' )
249+
250+ def set_show_date (self , show_date : bool ) -> None :
251+ """
252+ Set whether to show date labels on the contribution graph.
253+
254+ Args:
255+ show_date: Whether to show date labels
256+ """
257+ if 'DEFAULT' not in self .config :
258+ self .config ['DEFAULT' ] = {}
259+ self .config ['DEFAULT' ]['show_date' ] = str (show_date ).lower ()
260+
211261 def save (self ) -> None :
212262 """Save configuration to file."""
213263 import os
@@ -222,26 +272,37 @@ def save(self) -> None:
222272
223273 f .write ("[DEFAULT]\n " )
224274 username = self .config .get ('DEFAULT' , 'username' , fallback = '' )
225- f .write (f"username = { username } \n \n " )
275+ f .write (f"username = { username } \n " )
226276
227277 cache_hours = self .config .get ('DEFAULT' , 'cache_expiry_hours' ,
228278 fallback = '24' )
229- f .write (f"cache_expiry_hours = { cache_hours } \n \n " )
279+ f .write (f"cache_expiry_hours = { cache_hours } \n " )
230280
231281 provider = self .config .get ('DEFAULT' , 'provider' , fallback = '' )
232- f .write (f"provider = { provider } \n \n " )
282+ f .write (f"provider = { provider } \n " )
233283
234284 provider_url = self .config .get ('DEFAULT' , 'provider_url' ,
235285 fallback = '' )
236- f .write (f"provider_url = { provider_url } \n \n " )
286+ f .write (f"provider_url = { provider_url } \n " )
287+
288+ custom_box = self .config .get ('DEFAULT' , 'custom_box' , fallback = '' )
289+ if custom_box :
290+ f .write (f"custom_box = { custom_box } \n " )
291+
292+ show_date = self .config .get ('DEFAULT' , 'show_date' ,
293+ fallback = 'true' )
294+ if show_date != 'true' : # Only write if it's not the default
295+ f .write (f"show_date = { show_date } \n " )
237296
238- if 'COLORS' in self .config :
297+ f .write ("\n " )
298+
299+ if 'COLORS' in self .config ._sections :
239300 f .write ("[COLORS]\n " )
240301 # Find the longest key for alignment
241- if self .config ['COLORS' ]:
242- keys = list (self .config ['COLORS' ].keys ())
302+ colors_section = self .config ._sections ['COLORS' ]
303+ if colors_section :
304+ keys = list (colors_section .keys ())
243305 max_key_length = max (len (key ) for key in keys )
244- for key , value in self . config [ 'COLORS' ] .items ():
306+ for key , value in colors_section .items ():
245307 f .write (f"{ key :<{max_key_length }} = { value } \n " )
246308 f .write ("\n " )
247- f .write ("\n " )
0 commit comments