Skip to content

Commit

Permalink
Fix logging messages sometimes being misinterpreted as having markup.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Mar 13, 2023
1 parent 2bff46d commit f1f2031
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 33 deletions.
7 changes: 6 additions & 1 deletion src/cli/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ public static void WriteLine()
}

public static void WriteLine(string value)
{
AnsiConsole.WriteLine(value);
}

public static void MarkupLine(string value)
{
AnsiConsole.MarkupLine(CultureInfo.CurrentCulture, value);
}

public static void WriteLine(FormattableString value)
public static void MarkupLineInterpolated(FormattableString value)
{
AnsiConsole.MarkupLineInterpolated(CultureInfo.CurrentCulture, value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/dc/Commands/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override Task PreExecuteAsync(
protected override async Task<int> ExecuteAsync(
dynamic expando, PackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Packing [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Packing [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var files = await progress.RunTaskAsync(
"Gather data sheet files",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/dc/Commands/RepackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public RepackCommandSettings(string input, string output)
protected override async Task<int> ExecuteAsync(
dynamic expando, RepackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Repacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Repacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var root = await progress.RunTaskAsync(
"Load data center",
Expand Down
5 changes: 2 additions & 3 deletions src/tools/dc/Commands/SchemaCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ This means that schemas generated from this command may reject modifications to
the resulting schemas, and construct a more accurate set of schemas using good human
judgement.[/]".ReplaceLineEndings());
Log.WriteLine();
Log.WriteLine(
$"Inferring data sheet schemas of [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/] " +
$"with strategy [cyan]{settings.Strategy}[/]...");
Log.MarkupLineInterpolated(
$"Inferring data sheet schemas of [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/] with strategy [cyan]{settings.Strategy}[/]...");

var root = await progress.RunTaskAsync(
"Load data center",
Expand Down
4 changes: 2 additions & 2 deletions src/tools/dc/Commands/UnpackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override Task PreExecuteAsync(
protected override async Task<int> ExecuteAsync(
dynamic expando, UnpackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Unpacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Unpacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var root = await progress.RunTaskAsync(
"Load data center",
Expand Down Expand Up @@ -181,7 +181,7 @@ protected override Task PostExecuteAsync(
dynamic expando, UnpackCommandSettings settings, CancellationToken cancellationToken)
{
foreach (var name in (List<string>)expando.Missing)
Log.WriteLine($"[yellow]Data sheet [cyan]{name}[/] does not have a known schema.[/]");
Log.MarkupLineInterpolated($"[yellow]Data sheet [cyan]{name}[/] does not have a known schema.[/]");

return Task.CompletedTask;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/dc/Commands/ValidateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override async Task<int> ExecuteAsync(
ProgressContext progress,
CancellationToken cancellationToken)
{
Log.WriteLine($"Validating data sheets in [cyan]{settings.Input}[/]...");
Log.MarkupLineInterpolated($"Validating data sheets in [cyan]{settings.Input}[/]...");

var files = await progress.RunTaskAsync(
"Gather data sheet files",
Expand Down
14 changes: 7 additions & 7 deletions src/tools/dc/Commands/VerifyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public VerifyCommandSettings(string input)
protected override async Task<int> ExecuteAsync(
dynamic expando, VerifyCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Verifying [cyan]{settings.Input}[/]...");
Log.MarkupLineInterpolated($"Verifying [cyan]{settings.Input}[/]...");

await progress.RunTaskAsync(
"Compute data center hashes",
Expand Down Expand Up @@ -106,13 +106,13 @@ void ForceLoad(DataCenterNode node)
protected override Task PostExecuteAsync(
dynamic expando, VerifyCommandSettings settings, CancellationToken cancellationToken)
{
Log.WriteLine($"SHA-1: [blue]{expando.SHA1}[/]");
Log.WriteLine($"SHA-256: [blue]{expando.SHA256}[/]");
Log.WriteLine($"SHA-384: [blue]{expando.SHA384}[/]");
Log.WriteLine($"SHA-512: [blue]{expando.SHA512}[/]");
Log.MarkupLineInterpolated($"SHA-1: [blue]{expando.SHA1}[/]");
Log.MarkupLineInterpolated($"SHA-256: [blue]{expando.SHA256}[/]");
Log.MarkupLineInterpolated($"SHA-384: [blue]{expando.SHA384}[/]");
Log.MarkupLineInterpolated($"SHA-512: [blue]{expando.SHA512}[/]");
Log.WriteLine();
Log.WriteLine($"Nodes: [blue]{expando.Nodes}[/]");
Log.WriteLine($"Attributes: [blue]{expando.Attributes}[/]");
Log.MarkupLineInterpolated($"Nodes: [blue]{expando.Nodes}[/]");
Log.MarkupLineInterpolated($"Attributes: [blue]{expando.Attributes}[/]");

return Task.CompletedTask;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/dc/DataSheetValidationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void Print()
_ => throw new UnreachableException(),
};

Log.WriteLine($" [[[{color}]{type}[/]]] ([blue]{line}[/],[blue]{col}[/]): {msg}");
Log.MarkupLineInterpolated($" [[[{color}]{type}[/]]] ([blue]{line}[/],[blue]{col}[/]): {msg}");
}

var remainingProblems = fileGroup.Count() - shownProblems.Length;

if (remainingProblems != 0)
Log.WriteLine($" ... [darkorange]{remainingProblems}[/] more problem(s) ...");
Log.MarkupLineInterpolated($" ... [darkorange]{remainingProblems}[/] more problem(s) ...");
}

Log.WriteLine();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rc/Commands/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PackCommandSettings(string input, string output)
protected override async Task<int> ExecuteAsync(
dynamic expando, PackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Packing [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Packing [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var files = await progress.RunTaskAsync(
"Gather resource files",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rc/Commands/RepackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RepackCommandSettings(string input, string output)
protected override async Task<int> ExecuteAsync(
dynamic expando, RepackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Repacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Repacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var rc = await progress.RunTaskAsync(
"Load resource container",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rc/Commands/UnpackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public UnpackCommandSettings(string input, string output)
protected override async Task<int> ExecuteAsync(
dynamic expando, UnpackCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Unpacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated($"Unpacking [cyan]{settings.Input}[/] to [cyan]{settings.Output}[/]...");

var rc = await progress.RunTaskAsync(
"Load resource container",
Expand Down
12 changes: 6 additions & 6 deletions src/tools/rc/Commands/VerifyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public VerifyCommandSettings(string input)
protected override async Task<int> ExecuteAsync(
dynamic expando, VerifyCommandSettings settings, ProgressContext progress, CancellationToken cancellationToken)
{
Log.WriteLine($"Verifying [cyan]{settings.Input}[/]...");
Log.MarkupLineInterpolated($"Verifying [cyan]{settings.Input}[/]...");

await progress.RunTaskAsync(
"Compute resource container hashes",
Expand Down Expand Up @@ -75,12 +75,12 @@ await progress.RunTaskAsync(
protected override Task PostExecuteAsync(
dynamic expando, VerifyCommandSettings settings, CancellationToken cancellationToken)
{
Log.WriteLine($"SHA-1: [blue]{expando.SHA1}[/]");
Log.WriteLine($"SHA-256: [blue]{expando.SHA256}[/]");
Log.WriteLine($"SHA-384: [blue]{expando.SHA384}[/]");
Log.WriteLine($"SHA-512: [blue]{expando.SHA512}[/]");
Log.MarkupLineInterpolated($"SHA-1: [blue]{expando.SHA1}[/]");
Log.MarkupLineInterpolated($"SHA-256: [blue]{expando.SHA256}[/]");
Log.MarkupLineInterpolated($"SHA-384: [blue]{expando.SHA384}[/]");
Log.MarkupLineInterpolated($"SHA-512: [blue]{expando.SHA512}[/]");
Log.WriteLine();
Log.WriteLine($"Entries: [blue]{expando.Entries}[/]");
Log.MarkupLineInterpolated($"Entries: [blue]{expando.Entries}[/]");

return Task.CompletedTask;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run/Commands/ClientCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override Task<int> ExecuteAsync(
null,
settings.ServerPort);

Log.WriteLine($"Running client and connecting to [cyan]{srvName}[/]...");
Log.MarkupLineInterpolated($"Running client and connecting to [cyan]{srvName}[/]...");

return progress.RunTaskAsync(
"Connecting to arbiter server",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run/Commands/LauncherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override Task<int> ExecuteAsync(
ProgressContext progress,
CancellationToken cancellationToken)
{
Log.WriteLine($"Running launcher and connecting to [cyan]{settings.ServerListUri}[/]...");
Log.MarkupLineInterpolated($"Running launcher and connecting to [cyan]{settings.ServerListUri}[/]...");

return progress.RunTaskAsync(
"Connecting to arbiter server",
Expand Down
9 changes: 5 additions & 4 deletions src/tools/scan/Commands/ScanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ protected override async Task<int> ExecuteAsync(

if (proc == null)
{
Log.WriteLine($"Could not find the TERA process.");
Log.WriteLine("Could not find the TERA process.");

return 1;
}

if (proc.MainModule?.ModuleName != "TERA.exe")
{
Log.WriteLine($"Process [cyan]{proc.Id}[/] does not look like TERA.");
Log.MarkupLineInterpolated($"Process [cyan]{proc.Id}[/] does not look like TERA.");

return 1;
}

Log.WriteLine($"Scanning TERA process [cyan]{proc.Id}[/] and writing results to [cyan]{settings.Output}[/]...");
Log.MarkupLineInterpolated(
$"Scanning TERA process [cyan]{proc.Id}[/] and writing results to [cyan]{settings.Output}[/]...");

NativeAddress teraExeBase;
byte[] teraExeImage;
Expand Down Expand Up @@ -107,7 +108,7 @@ protected override Task PostExecuteAsync(
dynamic expando, ScanCommandSettings settings, CancellationToken cancellationToken)
{
foreach (var name in (List<string>)expando.Failures)
Log.WriteLine($"[blue]{name}[/] failed to retrieve information from the TERA process.");
Log.MarkupLineInterpolated($"[blue]{name}[/] failed to retrieve information from the TERA process.");

return Task.CompletedTask;
}
Expand Down

0 comments on commit f1f2031

Please sign in to comment.