Adds overloads for MarkUp methods without args

These methods don't require a string.format call so we'll directly call the Render method without a call to string.format.

Added bonus of a a couple fewer allocations too.
This commit is contained in:
Phil Scott 2021-03-06 09:57:31 -05:00 committed by Patrik Svensson
parent da9c6ee4c2
commit e4dda283bb
2 changed files with 36 additions and 2 deletions

View File

@ -71,5 +71,19 @@ namespace Spectre.Console.Tests.Unit
// Then
console.Output.ShouldBe(output);
}
[Fact]
public void Should_not_fail_with_brackets_on_calls_without_args()
{
// Given
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
// When
console.MarkupLine("{");
// Then
console.Output.NormalizeLineEndings()
.ShouldBe("{\n");
}
}
}

View File

@ -28,7 +28,17 @@ namespace Spectre.Console
/// <param name="args">An array of objects to write.</param>
public static void Markup(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args)
{
console.Render(MarkupParser.Parse(string.Format(provider, format, args)));
Markup(console, string.Format(provider, format, args));
}
/// <summary>
/// Writes the specified markup to the console.
/// </summary>
/// <param name="console">The console to write to.</param>
/// <param name="value">The value to write.</param>
public static void Markup(this IAnsiConsole console, string value)
{
console.Render(MarkupParser.Parse(value));
}
/// <summary>
@ -42,6 +52,16 @@ namespace Spectre.Console
MarkupLine(console, CultureInfo.CurrentCulture, format, args);
}
/// <summary>
/// Writes the specified markup, followed by the current line terminator, to the console.
/// </summary>
/// <param name="console">The console to write to.</param>
/// <param name="value">The value to write.</param>
public static void MarkupLine(this IAnsiConsole console, string value)
{
Markup(console, value + Environment.NewLine);
}
/// <summary>
/// Writes the specified markup, followed by the current line terminator, to the console.
/// </summary>
@ -54,4 +74,4 @@ namespace Spectre.Console
Markup(console, provider, format + Environment.NewLine, args);
}
}
}
}