Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FancyLogger] Footer shows progress bar of completed projects #8314

Merged
merged 9 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/Build/Logging/FancyLogger/FancyLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ namespace Microsoft.Build.Logging.FancyLogger
public class FancyLogger : ILogger
{
private Dictionary<int, FancyLoggerProjectNode> projects = new Dictionary<int, FancyLoggerProjectNode>();

private bool Succeeded;

private float existingTasks = 1;
private float completedTasks = 0;

public string Parameters { get; set; }

public int StartedProjects = 0;
public int FinishedProjects = 0;
public LoggerVerbosity Verbosity { get; set; }

public FancyLogger()
Expand Down Expand Up @@ -48,6 +44,16 @@ public void Initialize(IEventSource eventSource)
FancyLoggerBuffer.Initialize();
}

void UpdateFooter()
{
float percentage = (float) FinishedProjects / StartedProjects;
FancyLoggerBuffer.FooterText = ANSIBuilder.Alignment.SpaceBetween(
$"Build progress (approx.) {ANSIBuilder.Graphics.ProgressBar(percentage)}",
ANSIBuilder.Formatting.Italic(ANSIBuilder.Formatting.Dim("[Up][Down] Scroll")),
Console.BufferWidth
);
}

// Build
void eventSource_BuildStarted(object sender, BuildStartedEventArgs e)
{
Expand All @@ -61,6 +67,7 @@ void eventSource_BuildFinished(object sender, BuildFinishedEventArgs e)
// Project
void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e)
{
StartedProjects++;
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
// If id already exists...
Expand All @@ -70,6 +77,8 @@ void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e)
projects[id] = node;
// Log
node.Log();
// Update footer
UpdateFooter();
}
void eventSource_ProjectFinished(object sender, ProjectFinishedEventArgs e)
{
Expand All @@ -79,6 +88,9 @@ void eventSource_ProjectFinished(object sender, ProjectFinishedEventArgs e)
// Update line
node.Finished = true;
node.Log();
// Update footer
FinishedProjects++;
UpdateFooter();
}
// Target
void eventSource_TargetStarted(object sender, TargetStartedEventArgs e)
Expand Down Expand Up @@ -110,12 +122,10 @@ void eventSource_TaskStarted(object sender, TaskStartedEventArgs e)
// Update
node.AddTask(e);
node.Log();
existingTasks++;
}

void eventSource_TaskFinished(object sender, TaskFinishedEventArgs e)
{
completedTasks++;
}

void eventSource_MessageRaised(object sender, BuildMessageEventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions src/Build/Logging/FancyLogger/FancyLoggerBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FancyLoggerBuffer
private static List<FancyLoggerBufferLine> Lines = new();
private static int TopLineIndex = 0;
private static bool AutoScrollEnabled = true;
public static string FooterText = string.Empty;
public static void Initialize()
{
// Use alternate buffer
Expand Down Expand Up @@ -93,9 +94,8 @@ public static void Render()
ANSIBuilder.Cursor.Home() +
ANSIBuilder.Eraser.LineCursorToEnd() + ANSIBuilder.Formatting.Inverse(ANSIBuilder.Alignment.Center("MSBuild - Build in progress")) +
// Write footer
ANSIBuilder.Eraser.LineCursorToEnd() + ANSIBuilder.Cursor.Position(Console.BufferHeight - 1, 0) +
// TODO: Remove and replace with actual footer
new string('-', Console.BufferWidth) + '\n' + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
ANSIBuilder.Cursor.Position(Console.BufferHeight - 1, 0) + ANSIBuilder.Eraser.LineCursorToEnd() +
new string('-', Console.BufferWidth) + '\n' + FooterText
);
// Write lines
for (int i = 0; i < Console.BufferHeight - 3; i++)
Expand Down