mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-17 17:32:50 +08:00
Minor clean up
This commit is contained in:
parent
504746c5dc
commit
101e244059
@ -8,35 +8,37 @@ namespace Spectre.Console.Internal
|
|||||||
public static string GetAnsi(
|
public static string GetAnsi(
|
||||||
Capabilities capabilities,
|
Capabilities capabilities,
|
||||||
string text,
|
string text,
|
||||||
Decoration decoration,
|
Style style)
|
||||||
Color foreground,
|
|
||||||
Color background,
|
|
||||||
string? link)
|
|
||||||
{
|
{
|
||||||
var codes = AnsiDecorationBuilder.GetAnsiCodes(decoration);
|
if (style is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(style));
|
||||||
|
}
|
||||||
|
|
||||||
|
var codes = AnsiDecorationBuilder.GetAnsiCodes(style.Decoration);
|
||||||
|
|
||||||
// Got foreground?
|
// Got foreground?
|
||||||
if (foreground != Color.Default)
|
if (style.Foreground != Color.Default)
|
||||||
{
|
{
|
||||||
codes = codes.Concat(
|
codes = codes.Concat(
|
||||||
AnsiColorBuilder.GetAnsiCodes(
|
AnsiColorBuilder.GetAnsiCodes(
|
||||||
capabilities.ColorSystem,
|
capabilities.ColorSystem,
|
||||||
foreground,
|
style.Foreground,
|
||||||
true));
|
true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Got background?
|
// Got background?
|
||||||
if (background != Color.Default)
|
if (style.Background != Color.Default)
|
||||||
{
|
{
|
||||||
codes = codes.Concat(
|
codes = codes.Concat(
|
||||||
AnsiColorBuilder.GetAnsiCodes(
|
AnsiColorBuilder.GetAnsiCodes(
|
||||||
capabilities.ColorSystem,
|
capabilities.ColorSystem,
|
||||||
background,
|
style.Background,
|
||||||
false));
|
false));
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = codes.ToArray();
|
var result = codes.ToArray();
|
||||||
if (result.Length == 0 && link == null)
|
if (result.Length == 0 && style.Link == null)
|
||||||
{
|
{
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -46,8 +48,10 @@ namespace Spectre.Console.Internal
|
|||||||
? $"\u001b[{ansiCodes}m{text}\u001b[0m"
|
? $"\u001b[{ansiCodes}m{text}\u001b[0m"
|
||||||
: text;
|
: 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.
|
// Empty links means we should take the URL from the text.
|
||||||
if (link.Equals(Constants.EmptyLink, StringComparison.Ordinal))
|
if (link.Equals(Constants.EmptyLink, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ namespace Spectre.Console.Internal
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(part))
|
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)
|
if (!last)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user