11namespace CodeContext ;
2-
32public class MyAppsContext
43{
5- private static string _gitRepoRootPath ;
4+ public static string GitRepoRoot { get ; private set ; }
65
76 public static string GetUserInput ( string prompt )
87 {
@@ -12,40 +11,52 @@ public static string GetUserInput(string prompt)
1211
1312 public static string GetProjectStructure ( string path , int indent = 0 )
1413 {
15- if ( _gitRepoRootPath == null )
16- _gitRepoRootPath = FindGitRepoRoot ( path ) ;
14+ if ( GitRepoRoot == null ) GitRepoRoot = FindGitRepoRoot ( path ) ;
15+ if ( indent == 0 ) Console . WriteLine ( "📁 Analyzing directory structure..." ) ;
1716
18- return string . Join ( " \n " , Directory . EnumerateFileSystemEntries ( path )
17+ var entries = Directory . EnumerateFileSystemEntries ( path )
1918 . OrderBy ( e => e )
20- . Where ( e => ! FileChecker . ShouldSkip ( new FileInfo ( e ) , _gitRepoRootPath ) )
21- . Select ( e =>
22- {
23- var info = new FileInfo ( e ) ;
24- var indentation = new string ( ' ' , indent * 2 ) ;
25- var result =
26- $ "{ indentation } { info . Name } { ( info . Attributes . HasFlag ( FileAttributes . Directory ) ? "/" : "" ) } ";
27- return info . Attributes . HasFlag ( FileAttributes . Directory )
28- ? result + "\n " + GetProjectStructure ( e , indent + 1 )
29- : result ;
30- } ) ) ;
19+ . Where ( e => ! FileChecker . ShouldSkip ( new FileInfo ( e ) , GitRepoRoot ) )
20+ . ToList ( ) ;
21+
22+ return string . Join ( "\n " , entries . Select ( ( e , i ) =>
23+ {
24+ if ( indent == 0 ) WriteProgress ( i + 1 , entries . Count ) ;
25+
26+ var info = new FileInfo ( e ) ;
27+ var indentation = new string ( ' ' , indent * 2 ) ;
28+ var result = $ "{ indentation } { info . Name } { ( info . Attributes . HasFlag ( FileAttributes . Directory ) ? "/" : "" ) } ";
29+
30+ return info . Attributes . HasFlag ( FileAttributes . Directory )
31+ ? result + "\n " + GetProjectStructure ( e , indent + 1 )
32+ : result ;
33+ } ) ) ;
3134 }
3235
3336 public static string GetFileContents ( string path )
3437 {
35- if ( _gitRepoRootPath == null )
36- _gitRepoRootPath = FindGitRepoRoot ( path ) ;
38+ if ( GitRepoRoot == null ) GitRepoRoot = FindGitRepoRoot ( path ) ;
39+ Console . WriteLine ( " \n 📄 Processing files..." ) ;
3740
38- return string . Join ( "\n \n " , Directory . EnumerateFiles ( path , "*" , SearchOption . AllDirectories )
39- . Where ( f => ! FileChecker . ShouldSkip ( new FileInfo ( f ) , _gitRepoRootPath ) )
40- . Select ( f => $ "{ f } \n { new string ( '-' , 100 ) } \n { File . ReadAllText ( f ) } ") ) ;
41+ var files = Directory . EnumerateFiles ( path , "*" , SearchOption . AllDirectories )
42+ . Where ( f => ! FileChecker . ShouldSkip ( new FileInfo ( f ) , GitRepoRoot ) )
43+ . ToList ( ) ;
44+
45+ return string . Join ( "\n \n " , files . Select ( ( f , i ) =>
46+ {
47+ WriteProgress ( i + 1 , files . Count ) ;
48+ return $ "{ f } \n { new string ( '-' , 100 ) } \n { File . ReadAllText ( f ) } ";
49+ } ) ) ;
4150 }
4251
43- private static string FindGitRepoRoot ( string path )
44- {
45- return Directory . Exists ( Path . Combine ( path , ".git" ) )
52+ private static string FindGitRepoRoot ( string path ) =>
53+ Directory . Exists ( Path . Combine ( path , ".git" ) )
4654 ? path
47- : string . IsNullOrEmpty ( path )
48- ? null
49- : FindGitRepoRoot ( Path . GetDirectoryName ( path ) ) ;
55+ : string . IsNullOrEmpty ( path ) ? null : FindGitRepoRoot ( Path . GetDirectoryName ( path ) ) ;
56+
57+ private static void WriteProgress ( int current , int total )
58+ {
59+ var percent = ( int ) ( ( current / ( double ) total ) * 100 ) ;
60+ Console . Write ( $ "\r ⏳ Progress: { percent } % ({ current } /{ total } )") ;
5061 }
5162}
0 commit comments