mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-14 16:02:50 +08:00
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:
parent
da9c6ee4c2
commit
e4dda283bb
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user