mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 05:48:14 +08:00
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:

committed by
Patrik Svensson

parent
1601ef24b3
commit
504746c5dc
@ -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")]
|
||||
|
Reference in New Issue
Block a user