Minor clean up

This commit is contained in:
Patrik Svensson 2020-09-12 10:46:57 +02:00
parent 504746c5dc
commit 101e244059
2 changed files with 16 additions and 12 deletions

View File

@ -8,35 +8,37 @@ namespace Spectre.Console.Internal
public static string GetAnsi(
Capabilities capabilities,
string text,
Decoration decoration,
Color foreground,
Color background,
string? link)
Style style)
{
var codes = AnsiDecorationBuilder.GetAnsiCodes(decoration);
if (style is null)
{
throw new ArgumentNullException(nameof(style));
}
var codes = AnsiDecorationBuilder.GetAnsiCodes(style.Decoration);
// Got foreground?
if (foreground != Color.Default)
if (style.Foreground != Color.Default)
{
codes = codes.Concat(
AnsiColorBuilder.GetAnsiCodes(
capabilities.ColorSystem,
foreground,
style.Foreground,
true));
}
// Got background?
if (background != Color.Default)
if (style.Background != Color.Default)
{
codes = codes.Concat(
AnsiColorBuilder.GetAnsiCodes(
capabilities.ColorSystem,
background,
style.Background,
false));
}
var result = codes.ToArray();
if (result.Length == 0 && link == null)
if (result.Length == 0 && style.Link == null)
{
return text;
}
@ -46,8 +48,10 @@ namespace Spectre.Console.Internal
? $"\u001b[{ansiCodes}m{text}\u001b[0m"
: text;
if (link != null && !capabilities.LegacyConsole)
if (style.Link != null && !capabilities.LegacyConsole)
{
var link = style.Link;
// Empty links means we should take the URL from the text.
if (link.Equals(Constants.EmptyLink, StringComparison.Ordinal))
{

View File

@ -59,7 +59,7 @@ namespace Spectre.Console.Internal
{
if (!string.IsNullOrEmpty(part))
{
_out.Write(AnsiBuilder.GetAnsi(Capabilities, part, style.Decoration, style.Foreground, style.Background, style.Link));
_out.Write(AnsiBuilder.GetAnsi(Capabilities, part, style));
}
if (!last)