Skip to content

Commit

Permalink
Right justify output
Browse files Browse the repository at this point in the history
Move cursor right (it stops at end of line), then back to justify the
output. This makes the localization less flexible since the formatting +
justification is handled in code, but makes it a lot easier to
understand. In the future reordering in translations would need to be
handled fairly carefully.

Avoid a bunch of overwrite problems by simplifiying the
should-we-do-a-fancy-overwrite decision to "is just time tick" or "just
overwrite it all".
  • Loading branch information
rainersigwald committed Nov 29, 2023
1 parent e50041a commit 8f8dd68
Show file tree
Hide file tree
Showing 28 changed files with 135 additions and 368 deletions.
9 changes: 9 additions & 0 deletions src/Framework/Logging/AnsiCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,13 @@ public static string MakeBold(string? s)

return $"{CSI}{SetBold}{s}{SetDefaultColor}";
}

public static string MoveCursorBackward(int count) => $"{CSI}{count}{MoveBackward}";

/// <summary>
/// Moves cursor to the specified column, or the rightmost column if <paramref name="column"/> is greater than the width of the terminal.
/// </summary>
/// <param name="column">Column index.</param>
/// <returns>Control codes to set the desired position.</returns>
public static string SetCursorHorizontal(int column) => $"{CSI}{column}G";
}
62 changes: 62 additions & 0 deletions src/MSBuild.UnitTests/NodeStatus_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Build.Logging.TerminalLogger;

using VerifyTests;
using VerifyXunit;
using Xunit;

using static VerifyXunit.Verifier;


namespace Microsoft.Build.CommandLine.UnitTests;

[UsesVerify]
public class NodeStatus_Tests
{
private readonly NodeStatus _status = new("Namespace.Project", "TargetFramework", "Target", new());

public NodeStatus_Tests()
{
UseProjectRelativeDirectory("Snapshots");
}

[Fact]
public async Task EverythingFits()
{
NodesFrame frame = new(new[] { _status }, width: 80, height: 5);

await Verify(frame.RenderNodeStatus(_status).ToString());
}

[Fact]
public async Task TargetIsTruncatedFirst()
{
NodesFrame frame = new(new[] { _status }, width: 45, height: 5);

await Verify(frame.RenderNodeStatus(_status).ToString());
}

[Fact]
public async Task NamespaceIsTruncatedNext()
{
NodesFrame frame = new(new[] { _status }, width: 40, height: 5);

await Verify(frame.RenderNodeStatus(_status).ToString());
}

[Fact]
public async Task GoesToProject()
{
NodesFrame frame = new(new[] { _status }, width: 10, height: 5);

await Verify(frame.RenderNodeStatus(_status).ToString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 Namespace.Project TargetFramework Target (0.0s)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 Project TargetFramework  (0.0s)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 Namespace.Project TargetFramework  (0.0s)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
]9;4;3;\[?25l
project tfName Build (0.0s)
project tfName Build (0.0s)
[?25h[?25l
project tf2 Build (0.0s)
 project tf2 Build (0.0s)
[?25h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[?25l
project tfName Build (0.0s)
project tfName Build (0.0s)
[?25h[?25l
project tf2 Build (0.0s)
 project tf2 Build (0.0s)
[?25h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
]9;4;3;\[?25l
project tfName Build (0.0s)
project tfName Build (0.0s)
[?25h[?25l
project tf2 Build (0.0s)
 project tf2 Build (0.0s)
[?25h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
]9;4;3;\[?25l
project Build (0.0s)
project Build (0.0s)
[?25h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[?25l
project Build (0.0s)
project Build (0.0s)
[?25h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
]9;4;3;\[?25l
project Build (0.0s)
project Build (0.0s)
[?25h
21 changes: 0 additions & 21 deletions src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1536,27 +1536,6 @@
{0}: VT100 coded hyperlink to project output directory
</comment>
</data>
<data name="ProjectBuilding_NoTF" xml:space="preserve">
<value>{0}{1} {2} ({3}s)</value>
<comment>
Project building.
{0}: indentation - few spaces to visually indent row
{1}: project name
{2}: target
{3}: duration in seconds with 1 decimal point
</comment>
</data>
<data name="ProjectBuilding_WithTF" xml:space="preserve">
<value>{0}{1} {2} {3} ({4}s)</value>
<comment>
Project building including target framework information.
{0}: indentation - few spaces to visually indent row
{1}: project name
{2}: target framework
{3}: target
{4}: duration in seconds with 1 decimal point
</comment>
</data>
<data name="DurationDisplay">
<value>({0:F1}s)</value>
<comment>
Expand Down
23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions src/MSBuild/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f8dd68

Please sign in to comment.