77import shutil
88from typing import List , Dict
99import re
10+ from rich .console import Console
11+ from rich .markdown import Markdown
1012
1113
1214class DisplayManager :
@@ -48,6 +50,7 @@ class DisplayManager:
4850
4951 def __init__ (self ):
5052 self .terminal_width = self ._get_terminal_width ()
53+ self .console = Console (width = min (self .terminal_width - 4 , 120 ))
5154
5255 def _get_terminal_width (self ) -> int :
5356 """Get the current terminal width."""
@@ -151,7 +154,7 @@ def show_repository_header(self, repo: Dict[str, str]):
151154 print (f"📝 Description: { description } " )
152155
153156 def show_readme (self , readme_content : str ):
154- """Display README content with proper formatting ."""
157+ """Display README content with beautiful Rich markdown rendering ."""
155158 print ("\n " + "-" * 80 )
156159 print ("📖 README" )
157160 print ("-" * 80 )
@@ -160,8 +163,61 @@ def show_readme(self, readme_content: str):
160163 print ("No README content available." )
161164 return
162165
166+ self ._render_with_rich (readme_content )
167+
168+ def _render_with_rich (self , content : str ):
169+ """Render markdown content using Rich with beautiful formatting and pagination."""
170+ try :
171+ # Create Rich Markdown object
172+ markdown = Markdown (content )
173+
174+ # Render to string to get the formatted content
175+ with self .console .capture () as capture :
176+ self .console .print (markdown )
177+
178+ # Get the rendered content and split into lines
179+ rendered_content = capture .get ()
180+ lines = rendered_content .split ('\n ' )
181+
182+ # Paginate the beautifully rendered content
183+ self ._paginate_rich_content (lines )
184+
185+ except Exception as e :
186+ print (f"⚠️ Error rendering with Rich: { e } " )
187+ self ._render_fallback (content )
188+
189+ def _paginate_rich_content (self , lines : list ):
190+ """Display Rich-rendered content with pagination."""
191+ lines_per_page = 30
192+ current_line = 0
193+
194+ while current_line < len (lines ):
195+ # Display current page
196+ end_line = min (current_line + lines_per_page , len (lines ))
197+
198+ for i in range (current_line , end_line ):
199+ print (lines [i ])
200+
201+ current_line = end_line
202+
203+ # Check if there are more lines
204+ if current_line < len (lines ):
205+ remaining_lines = len (lines ) - current_line
206+ print (f"\n --- More content available ({ remaining_lines } lines remaining) ---" )
207+
208+ try :
209+ user_input = input ("📖 Press Enter to continue, 'q' to stop reading: " ).strip ().lower ()
210+ if user_input == 'q' :
211+ print ("📖 README reading stopped." )
212+ break
213+ except KeyboardInterrupt :
214+ print ("\n 📖 README reading interrupted." )
215+ break
216+
217+ def _render_fallback (self , content : str ):
218+ """Fallback rendering for plain text display."""
163219 # Split content into lines for better display
164- lines = readme_content .split ('\n ' )
220+ lines = content .split ('\n ' )
165221
166222 # Display with pagination for very long READMEs
167223 if len (lines ) > 50 :
0 commit comments