Skip to content

Commit 349aa53

Browse files
committed
Feature: Add cancellation support and progress display during code generation.
1 parent 553ba29 commit 349aa53

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

CodeIngest.Desktop/MainViewModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
1111

12-
using System;
1312
using System.Linq;
1413
using System.Threading.Tasks;
1514
using CodeIngestLib;
@@ -170,11 +169,13 @@ public async Task RunIngest()
170169
if (IncludeMarkdown)
171170
options.FilePatterns.Add("*.md");
172171

173-
var progress = new ProgressToken();
174-
progress.ProgressUpdated += (_, _) => Console.Write('.');
175-
176-
var ingester = new Ingester(options);
177-
var result = ingester.Run(selectedFolders, outputFile, progress);
172+
var progress = new ProgressToken(true) { IsCancelSupported = true };
173+
(int FileCount, long OutputBytes)? result;
174+
using (m_dialogService.ShowBusy("Generating code...", progress))
175+
{
176+
var ingester = new Ingester(options);
177+
result = await Task.Run(() => ingester.Run(selectedFolders, outputFile, progress));
178+
}
178179
if (!result.HasValue)
179180
{
180181
m_dialogService.ShowMessage("Failed to generate code file.", "Please check your file permissions and try again.", MaterialIconKind.Error);

CodeIngestLib/Ingester.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.IO;
1414
using System.Linq;
1515
using System.Text;
16+
using System.Threading;
1617
using CSharp.Core;
1718

1819
namespace CodeIngestLib;
@@ -79,9 +80,9 @@ public Ingester(IngestOptions options)
7980
{
8081
if (progress.CancelRequested)
8182
break; // Caller requested cancellation.
82-
progress.Progress = (i + 1.0) / sourceFiles.Length;
83+
progress.Progress = (int)(100.0 * (i + 1.0) / sourceFiles.Length);
8384
}
84-
85+
8586
using var reader = new StreamReader(sourceFile.OpenRead(), Encoding.UTF8);
8687

8788
writer.WriteLine($"// File: {(m_options.UseFullPaths ? sourceFile.FullName : sourceFile.Name)}");

DTC.Core

0 commit comments

Comments
 (0)