diff --git a/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs b/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs index b38c92a..41715bb 100644 --- a/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs +++ b/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs @@ -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)) { diff --git a/src/Spectre.Console/Internal/AnsiConsoleRenderer.cs b/src/Spectre.Console/Internal/AnsiConsoleRenderer.cs index 792d57b..3df80f7 100644 --- a/src/Spectre.Console/Internal/AnsiConsoleRenderer.cs +++ b/src/Spectre.Console/Internal/AnsiConsoleRenderer.cs @@ -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)