mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-05-02 23:52:52 +08:00
30 lines
826 B
C#
30 lines
826 B
C#
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);
|
|
}
|
|
}
|
|
}
|