Add link support for supported terminals

Also refactors the code quite a bit, to make it a bit more
easier to add features like this in the future.

Closes #75
This commit is contained in:
Patrik Svensson
2020-09-11 00:34:45 +02:00
committed by Patrik Svensson
parent 1601ef24b3
commit 504746c5dc
33 changed files with 574 additions and 1539 deletions

View File

@ -35,6 +35,7 @@ namespace Spectre.Console.Internal
var effectiveDecoration = (Decoration?)null;
var effectiveForeground = (Color?)null;
var effectiveBackground = (Color?)null;
var effectiveLink = (string?)null;
var parts = text.Split(new[] { ' ' });
var foreground = true;
@ -51,6 +52,23 @@ namespace Spectre.Console.Internal
continue;
}
if (part.StartsWith("link=", StringComparison.OrdinalIgnoreCase))
{
if (effectiveLink != null)
{
error = "A link has already been set.";
return null;
}
effectiveLink = part.Substring(5);
continue;
}
else if (part.StartsWith("link", StringComparison.OrdinalIgnoreCase))
{
effectiveLink = Constants.EmptyLink;
continue;
}
var decoration = DecorationTable.GetDecoration(part);
if (decoration != null)
{
@ -116,7 +134,11 @@ namespace Spectre.Console.Internal
}
error = null;
return new Style(effectiveForeground, effectiveBackground, effectiveDecoration);
return new Style(
effectiveForeground,
effectiveBackground,
effectiveDecoration,
effectiveLink);
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types")]