mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Patrik Svensson

parent
a5125d640c
commit
4f6eca4fcb
29
src/Spectre.Console/Extensions/StringBuilderExtensions.cs
Normal file
29
src/Spectre.Console/Extensions/StringBuilderExtensions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
internal static class StringBuilderExtensions
|
||||
{
|
||||
public static StringBuilder AppendWithStyle(this StringBuilder builder, Style? style, int? value)
|
||||
{
|
||||
return AppendWithStyle(builder, style, value?.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendWithStyle(this StringBuilder builder, Style? style, string? value)
|
||||
{
|
||||
value ??= string.Empty;
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
return builder.Append('[')
|
||||
.Append(style.ToMarkup())
|
||||
.Append(']')
|
||||
.Append(value.EscapeMarkup())
|
||||
.Append("[/]");
|
||||
}
|
||||
|
||||
return builder.Append(value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user