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 all 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
24 changes: 16 additions & 8 deletions src/MSBuild/LiveLogger/LiveLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ internal class LiveLogger : ILogger
private Dictionary<int, ProjectNode> projects = new Dictionary<int, ProjectNode>();

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 LiveLogger()
Expand Down Expand Up @@ -101,6 +98,15 @@ private void Render()
}
}

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

// Build
private void eventSource_BuildStarted(object sender, BuildStartedEventArgs e)
{
Expand All @@ -114,6 +120,7 @@ private void eventSource_BuildFinished(object sender, BuildFinishedEventArgs e)
// Project
private void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e)
{
StartedProjects++;
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
// If id already exists...
Expand All @@ -125,6 +132,8 @@ private void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e
ProjectNode node = new ProjectNode(e);
projects[id] = node;
// Log
// Update footer
UpdateFooter();
node.ShouldRerender = true;
}

Expand All @@ -138,7 +147,8 @@ private void eventSource_ProjectFinished(object sender, ProjectFinishedEventArgs
}
// Update line
node.Finished = true;
// Log
FinishedProjects++;
UpdateFooter();
node.ShouldRerender = true;
}

Expand Down Expand Up @@ -182,14 +192,12 @@ private void eventSource_TaskStarted(object sender, TaskStartedEventArgs e)
}
// Update
node.AddTask(e);
existingTasks++;
// Log
node.ShouldRerender = true;
}

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

// Raised messages, warnings and errors
Expand Down
6 changes: 3 additions & 3 deletions src/MSBuild/LiveLogger/TerminalBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public TerminalBufferLine(string text, bool shouldWrapLines)
internal class TerminalBuffer
{
private static List<TerminalBufferLine> Lines = new();
public static string FooterText = string.Empty;
public static int TopLineIndex = 0;
public static string Footer = string.Empty;
internal static bool IsTerminated = false;
Expand Down Expand Up @@ -102,9 +103,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) + $"\nBuild progress: XX%\tTopLineIndex={TopLineIndex}");
ANSIBuilder.Cursor.Position(Console.BufferHeight - 1, 0) + ANSIBuilder.Eraser.LineCursorToEnd() +
new string('-', Console.BufferWidth) + '\n' + FooterText);

if (Lines.Count == 0)
{
Expand Down