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] Show link to project outputs #8324

Merged
merged 23 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
9 changes: 4 additions & 5 deletions src/Build/Logging/FancyLogger/ANSIBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class ANSIBuilder
{
public static string ANSIRemove(string text)
{
return Regex.Replace(text, "\\x1b(?:[@-Z\\-_]|\\[[0-?]*[ -\\/]*[@-~])", "");
return Regex.Replace(text, @"\x1b(?:[@-Z\-_]|\[[0-?]*[ -\/]*[@-~]|(?:\]8;;.*?\x1b\\))", "");
}

public static class Alignment
Expand Down Expand Up @@ -157,11 +157,10 @@ public static string Overlined(string text)
return String.Format("\x1b[53m{0}\x1b[55m", text);
}

// TODO: Right now only replaces \ with /. Needs review to make sure it works on all or most terminal emulators.
public static string Hyperlink(string text, string url)
public static string Hyperlink(string text, string rawUrl)
{
// return String.Format("\x1b[]8;;{0}\x1b\\{1}\x1b[]8;\x1b\\", text, url);
return url.Replace("\\", "/");
string url = rawUrl.Length > 0 ? new System.Uri(rawUrl).AbsoluteUri : rawUrl;
return $"\x1b]8;;{url}\x1b\\{text}\x1b]8;;\x1b\\";
}

public static string DECLineDrawing(string text)
Expand Down
20 changes: 16 additions & 4 deletions src/Build/Logging/FancyLogger/FancyLoggerProjectNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;

namespace Microsoft.Build.Logging.FancyLogger
Expand All @@ -26,6 +27,7 @@ private static string GetUnambiguousPath(string path)
public string ProjectPath;
public string TargetFramework;
public bool Finished;
public string ProjectOutputExecutable;
edvilme marked this conversation as resolved.
Show resolved Hide resolved
// Line to display project info
public FancyLoggerBufferLine? Line;
// Targets
Expand All @@ -44,6 +46,7 @@ public FancyLoggerProjectNode(ProjectStartedEventArgs args)
ProjectPath = args.ProjectFile!;
Finished = false;
FinishedTargets = 0;
ProjectOutputExecutable = string.Empty;
if (args.GlobalProperties != null && args.GlobalProperties.ContainsKey("TargetFramework"))
{
TargetFramework = args.GlobalProperties["TargetFramework"];
Expand All @@ -60,11 +63,14 @@ public void Log()
string lineContents = ANSIBuilder.Alignment.SpaceBetween(
// Show indicator
(Finished ? ANSIBuilder.Formatting.Color("✓", ANSIBuilder.Formatting.ForegroundColor.Green) : ANSIBuilder.Formatting.Blinking(ANSIBuilder.Graphics.Spinner())) +
// Project
ANSIBuilder.Formatting.Dim("Project: ") +
// Project file path with color
$"{ANSIBuilder.Formatting.Color(ANSIBuilder.Formatting.Bold(GetUnambiguousPath(ProjectPath)), Finished ? ANSIBuilder.Formatting.ForegroundColor.Green : ANSIBuilder.Formatting.ForegroundColor.Default )} [{TargetFramework ?? "*"}]",
$"({MessageCount} Messages, {WarningCount} Warnings, {ErrorCount} Errors)",
$" {ANSIBuilder.Formatting.Color(ANSIBuilder.Formatting.Bold(GetUnambiguousPath(ProjectPath)), Finished ? ANSIBuilder.Formatting.ForegroundColor.Green : ANSIBuilder.Formatting.ForegroundColor.Default )}" +
// TFM
$" {ANSIBuilder.Formatting.Inverse(TargetFramework)} " +
(ProjectOutputExecutable.Length > 0 ? $"-> { ANSIBuilder.Formatting.Hyperlink(GetUnambiguousPath(ProjectOutputExecutable), Path.GetDirectoryName(ProjectOutputExecutable)!) }" : string.Empty)
,
$"({MessageCount} ℹ️, {WarningCount} ⚠️, {ErrorCount} ❌)",
// ProjectOutputExecutable,
Console.WindowWidth
);

Expand Down Expand Up @@ -116,6 +122,12 @@ public FancyLoggerTargetNode AddTarget(TargetStartedEventArgs args)
{
if (args.Importance != MessageImportance.High) return null;
MessageCount++;
// Detect output messages using regex
// var match = Regex.Match(args.Message, $"(?<={args.ProjectFile} -> )(.*)");
var match = Regex.Match(args.Message!, $"(?<=.* -> )(.*)");
if (match.Success)
ProjectOutputExecutable = match.Value;

edvilme marked this conversation as resolved.
Show resolved Hide resolved
FancyLoggerMessageNode node = new FancyLoggerMessageNode(args);
AdditionalDetails.Add(node);
return node;
Expand Down