Skip to content

Commit 05df5f2

Browse files
committed
Add non updating progress target
1 parent 2f5f123 commit 05df5f2

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

src/Installer/dnup/Commands/Sdk/Install/SdkInstallCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public override int Execute()
209209

210210
// TODO: Implement transaction / rollback?
211211

212-
SpectreAnsiConsole.MarkupInterpolated($"Installing .NET SDK [blue]{resolvedVersion}[/] to [blue]{resolvedInstallPath}[/]...");
212+
SpectreAnsiConsole.MarkupLineInterpolated($"Installing .NET SDK [blue]{resolvedVersion}[/] to [blue]{resolvedInstallPath}[/]...");
213213

214214
DotnetInstall? mainInstall;
215215

src/Installer/dnup/InstallerOrchestratorSingleton.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ private InstallerOrchestratorSingleton()
5151
}
5252
}
5353

54-
// TODO: Change noProgress logic so that output should still be printed, just not updates
55-
IProgressTarget progressTarget = noProgress ? new NullProgressTarget() : new SpectreProgressTarget();
54+
IProgressTarget progressTarget = noProgress ? new NonUpdatingProgressTarget() : new SpectreProgressTarget();
5655

5756
using ArchiveDotnetExtractor installer = new(installRequest, versionToInstall, progressTarget);
5857
installer.Prepare();
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Reflection.Metadata.Ecma335;
7+
using System.Text;
8+
9+
namespace Microsoft.DotNet.Tools.Bootstrapper;
10+
11+
public class NonUpdatingProgressTarget : IProgressTarget
12+
{
13+
public IProgressReporter CreateProgressReporter() => new Reporter();
14+
15+
class Reporter : IProgressReporter
16+
{
17+
List<ProgressTaskImpl> _tasks = new();
18+
19+
public IProgressTask AddTask(string description, double maxValue)
20+
{
21+
var task = new ProgressTaskImpl(description)
22+
{
23+
MaxValue = maxValue
24+
};
25+
_tasks.Add(task);
26+
Spectre.Console.AnsiConsole.WriteLine(description + "...");
27+
return task;
28+
}
29+
public void Dispose()
30+
{
31+
foreach (var task in _tasks)
32+
{
33+
task.Complete();
34+
}
35+
}
36+
}
37+
38+
class ProgressTaskImpl : IProgressTask
39+
{
40+
bool _completed = false;
41+
double _value;
42+
43+
public ProgressTaskImpl(string description)
44+
{
45+
Description = description;
46+
}
47+
48+
public double Value
49+
{
50+
get => _value;
51+
set
52+
{
53+
_value = value;
54+
if (_value >= MaxValue)
55+
{
56+
Complete();
57+
}
58+
}
59+
}
60+
public string Description { get; set; }
61+
public double MaxValue { get; set; }
62+
63+
public void Complete()
64+
{
65+
if (!_completed)
66+
{
67+
Spectre.Console.AnsiConsole.MarkupLine($"[green]Completed:[/] {Description}");
68+
_completed = true;
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)