Skip to content

Commit fdaea52

Browse files
committed
add progress indicators
1 parent e003206 commit fdaea52

2 files changed

Lines changed: 41 additions & 28 deletions

File tree

MyAppsContext.cs

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
namespace CodeContext;
2-
32
public 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
}

Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
var stats = CalculateStats(path, content, sw.Elapsed);
1818

1919
WriteOutput(output, content, config.OutputFormat);
20-
Console.WriteLine($"✅ Output written to {output}");
20+
Console.WriteLine($"\n✅ Output written to {output}");
2121
Console.WriteLine(stats);
2222
}
2323
catch (Exception ex)
@@ -74,6 +74,7 @@ static string BuildContent(string path, Config config)
7474

7575
static string CalculateStats(string path, string content, TimeSpan timeTaken) =>
7676
$"""
77+
7778
📊 Stats:
7879
📁 Files processed: {Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length}
7980
📝 Total lines: {content.Count(c => c == '\n')}
@@ -83,6 +84,7 @@ static string CalculateStats(string path, string content, TimeSpan timeTaken) =>
8384

8485
static void WriteOutput(string output, string content, string format)
8586
{
87+
Console.WriteLine("\n💾 Writing output...");
8688
try
8789
{
8890
var outputPath = Directory.Exists(output) ? Path.Combine(output, "context.txt") : output;

0 commit comments

Comments
 (0)