mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2026-02-10 04:13:32 +01:00
Modernize and clean up the code base a bit
* Move extension methods closer to implementations * Fix namespaces * Make structs read-only where applicable * Use ArgumentNullException.ThrowIfNull * Use collection expressions
This commit is contained in:
committed by
Patrik Svensson
parent
fa071a9368
commit
86abe0cc12
@@ -14,6 +14,7 @@
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\..\resources\spectre.snk</AssemblyOriginatorKeyFile>
|
||||
<PublicKey>00240000048000009400000006020000002400005253413100040000010001006146d3789d31477cf4a3b508dcf772ff9ccad8613f6bd6b17b9c4a960a7a7b551ecd22e4f4119ced70ee8bbdf3ca0a117c99fd6248c16255ea9033110c2233d42e74e81bf4f3f7eb09bfe8b53ad399d957514f427171a86f5fe9fe0014be121d571c80c4a0cfc3531bdbf5a2900d936d93f2c94171b9134f7644a1ac3612a0d0</PublicKey>
|
||||
<PolyArgumentExceptions>true</PolyArgumentExceptions>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Disable nullability for netstandard2.0 since polyfills are not -->
|
||||
|
||||
@@ -16,10 +16,7 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage MaxWidth(this CanvasImage image, int? maxWidth)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.MaxWidth = maxWidth;
|
||||
return image;
|
||||
@@ -32,10 +29,7 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage NoMaxWidth(this CanvasImage image)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.MaxWidth = null;
|
||||
return image;
|
||||
@@ -50,10 +44,7 @@ public static class CanvasImageExtensions
|
||||
[Obsolete("Not used anymore. Will be removed in future update.")]
|
||||
public static CanvasImage PixelWidth(this CanvasImage image, int width)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.PixelWidth = width;
|
||||
return image;
|
||||
@@ -67,15 +58,9 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage Mutate(this CanvasImage image, Action<IImageProcessingContext> action)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
if (action is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
|
||||
image.Image.Mutate(action);
|
||||
return image;
|
||||
@@ -88,10 +73,7 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage BicubicResampler(this CanvasImage image)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.Resampler = KnownResamplers.Bicubic;
|
||||
return image;
|
||||
@@ -106,10 +88,7 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage BilinearResampler(this CanvasImage image)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.Resampler = KnownResamplers.Triangle;
|
||||
return image;
|
||||
@@ -124,10 +103,7 @@ public static class CanvasImageExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static CanvasImage NearestNeighborResampler(this CanvasImage image)
|
||||
{
|
||||
if (image is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(image);
|
||||
|
||||
image.Resampler = KnownResamplers.NearestNeighbor;
|
||||
return image;
|
||||
|
||||
@@ -13,10 +13,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BracesStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BracesStyle = style;
|
||||
return text;
|
||||
@@ -30,10 +27,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BracketStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BracketsStyle = style;
|
||||
return text;
|
||||
@@ -47,10 +41,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText MemberStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.MemberStyle = style;
|
||||
return text;
|
||||
@@ -64,10 +55,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText ColonStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.ColonStyle = style;
|
||||
return text;
|
||||
@@ -81,10 +69,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText CommaStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.CommaStyle = style;
|
||||
return text;
|
||||
@@ -98,10 +83,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText StringStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.StringStyle = style;
|
||||
return text;
|
||||
@@ -115,10 +97,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText NumberStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.NumberStyle = style;
|
||||
return text;
|
||||
@@ -132,10 +111,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BooleanStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BooleanStyle = style;
|
||||
return text;
|
||||
@@ -149,10 +125,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText NullStyle(this JsonText text, Style? style)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.NullStyle = style;
|
||||
return text;
|
||||
@@ -166,10 +139,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BracesColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BracesStyle = new Style(color);
|
||||
return text;
|
||||
@@ -183,10 +153,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BracketColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BracketsStyle = new Style(color);
|
||||
return text;
|
||||
@@ -200,10 +167,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText MemberColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.MemberStyle = new Style(color);
|
||||
return text;
|
||||
@@ -217,10 +181,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText ColonColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.ColonStyle = new Style(color);
|
||||
return text;
|
||||
@@ -234,10 +195,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText CommaColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.CommaStyle = new Style(color);
|
||||
return text;
|
||||
@@ -251,10 +209,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText StringColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.StringStyle = new Style(color);
|
||||
return text;
|
||||
@@ -268,10 +223,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText NumberColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.NumberStyle = new Style(color);
|
||||
return text;
|
||||
@@ -285,10 +237,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText BooleanColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.BooleanStyle = new Style(color);
|
||||
return text;
|
||||
@@ -302,10 +251,7 @@ public static class JsonTextExtensions
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static JsonText NullColor(this JsonText text, Color color)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
text.NullStyle = new Style(color);
|
||||
return text;
|
||||
|
||||
@@ -25,10 +25,10 @@ internal static class JsonTokenizer
|
||||
{ "null", JsonTokenType.Null },
|
||||
};
|
||||
|
||||
_allowedEscapedChars = new HashSet<char>
|
||||
{
|
||||
'\"', '\\', '/', 'b', 'f', 'n', 'r', 't', 'u',
|
||||
};
|
||||
_allowedEscapedChars =
|
||||
[
|
||||
'\"', '\\', '/', 'b', 'f', 'n', 'r', 't', 'u'
|
||||
];
|
||||
}
|
||||
|
||||
public static List<JsonToken> Tokenize(string text)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
global using System.Text;
|
||||
global using Spectre.Console.Internal;
|
||||
global using Spectre.Console.Json.Syntax;
|
||||
global using Spectre.Console.Rendering;
|
||||
@@ -11,8 +11,8 @@
|
||||
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Spectre.Console\Internal\Extensions\CharExtensions.cs" Link="Internal\CharExtensions.cs" />
|
||||
<Compile Include="..\..\Spectre.Console\Internal\Extensions\EnumerableExtensions.cs" Link="Internal\EnumerableExtensions.cs" />
|
||||
<Compile Include="..\..\Spectre.Console\Extensions\Bcl\CharExtensions.cs" Link="Internal\CharExtensions.cs" />
|
||||
<Compile Include="..\..\Spectre.Console\Extensions\Bcl\EnumerableExtensions.cs" Link="Internal\EnumerableExtensions.cs" />
|
||||
<Compile Include="..\..\Spectre.Console\Internal\Text\StringBuffer.cs" Link="Internal\StringBuffer.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -20,4 +20,8 @@
|
||||
<ProjectReference Include="..\..\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Polyfill" Condition="'$(TargetFramework)' == 'netstandard2.0'" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -15,7 +15,7 @@ public sealed class JsonArray : JsonSyntax
|
||||
/// </summary>
|
||||
public JsonArray()
|
||||
{
|
||||
Items = new List<JsonSyntax>();
|
||||
Items = [];
|
||||
}
|
||||
|
||||
internal override void Accept<T>(JsonSyntaxVisitor<T> visitor, T context)
|
||||
|
||||
@@ -15,7 +15,7 @@ public sealed class JsonObject : JsonSyntax
|
||||
/// </summary>
|
||||
public JsonObject()
|
||||
{
|
||||
Members = new List<JsonMember>();
|
||||
Members = [];
|
||||
}
|
||||
|
||||
internal override void Accept<T>(JsonSyntaxVisitor<T> visitor, T context)
|
||||
|
||||
@@ -16,14 +16,14 @@ internal static class EmojiEmitter
|
||||
/// Format: (OldName, OldIdentifier, NewName, Description)
|
||||
/// </summary>
|
||||
private static readonly (string OldName, string OldIdentifier, string NewName, string Description)[] LegacyAliases =
|
||||
{
|
||||
[
|
||||
// "hugging face" was renamed to "smiling face with open hands"
|
||||
("HuggingFace", "hugging_face", "SmilingFaceWithOpenHands", "Hugging face"),
|
||||
// "knocked out face" was renamed to "face with crossed-out eyes"
|
||||
("KnockedOutFace", "knocked_out_face", "FaceWithCrossedOutEyes", "Knocked-out face"),
|
||||
// "pouting face" was renamed to "enraged face"
|
||||
("PoutingFace", "pouting_face", "EnragedFace", "Pouting face"),
|
||||
};
|
||||
("PoutingFace", "pouting_face", "EnragedFace", "Pouting face")
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode escape sequence like "\U0001F9EE" to the actual character.
|
||||
|
||||
@@ -27,7 +27,7 @@ internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnu
|
||||
/// <summary>
|
||||
/// Creates a new EquatableArray from the given enumerable.
|
||||
/// </summary>
|
||||
public EquatableArray(IEnumerable<T> items) => _array = items.ToImmutableArray();
|
||||
public EquatableArray(IEnumerable<T> items) => _array = [.. items];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements.
|
||||
|
||||
@@ -18,10 +18,7 @@ public static class ShouldlyExtensions
|
||||
[DebuggerStepThrough]
|
||||
public static T And<T>(this T item, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
|
||||
action(item);
|
||||
return item;
|
||||
|
||||
@@ -18,7 +18,7 @@ public static class StringExtensions
|
||||
}
|
||||
|
||||
var result = new List<string>();
|
||||
foreach (var line in value.NormalizeLineEndings().Split(new[] { '\n' }))
|
||||
foreach (var line in value.NormalizeLineEndings().Split(['\n']))
|
||||
{
|
||||
result.Add(line.TrimEnd());
|
||||
}
|
||||
|
||||
@@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Polyfill" Condition="'$(TargetFramework)' == 'netstandard2.0'" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -33,10 +33,7 @@ public sealed class TestCapabilities : IReadOnlyCapabilities
|
||||
/// <returns>A <see cref="RenderOptions"/> with the same capabilities as this instace.</returns>
|
||||
public RenderOptions CreateRenderContext(IAnsiConsole console)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return RenderOptions.Create(console, this);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public sealed class TestConsole : IAnsiConsole, IDisposable
|
||||
/// <summary>
|
||||
/// Gets the console output lines.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Lines => Output.NormalizeLineEndings().TrimEnd('\n').Split(new char[] { '\n' });
|
||||
public IReadOnlyList<string> Lines => Output.NormalizeLineEndings().TrimEnd('\n').Split(['\n']);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not VT/ANSI sequences
|
||||
|
||||
@@ -21,10 +21,7 @@ public sealed class TestConsoleInput : IAnsiConsoleInput
|
||||
/// <param name="input">The input string.</param>
|
||||
public void PushText(string input)
|
||||
{
|
||||
if (input is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
|
||||
foreach (var character in input)
|
||||
{
|
||||
|
||||
@@ -34,14 +34,14 @@ public static class TestExceptions
|
||||
|
||||
public static List<T> GenericMethodWithOutThatThrows<T>(out List<T> firstFewItems)
|
||||
{
|
||||
firstFewItems = new List<T>();
|
||||
firstFewItems = [];
|
||||
throw new InvalidOperationException("Throwing!");
|
||||
}
|
||||
|
||||
public static (string Key, List<T> Values) GetTuplesWithInnerException<T>((int First, string Second) myValue)
|
||||
{
|
||||
MethodThatThrows(0);
|
||||
return ("key", new List<T>());
|
||||
return ("key", []);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ public static class StreamExtensions
|
||||
{
|
||||
public static string ReadText(this Stream stream)
|
||||
{
|
||||
if (stream is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(stream);
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ global using System.Text.RegularExpressions;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
global using Shouldly;
|
||||
global using Spectre.Console.Advanced;
|
||||
global using Spectre.Console.Json;
|
||||
global using Spectre.Console.Rendering;
|
||||
global using Spectre.Console.Testing;
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace Spectre.Console.Tests.Unit;
|
||||
|
||||
public sealed partial class AnsiConsoleTests
|
||||
{
|
||||
public sealed class Advanced
|
||||
public sealed class Ansi
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Write_Ansi_Codes_To_Console_If_Supported()
|
||||
@@ -83,7 +83,7 @@ public sealed class MultiSelectionPromptTests
|
||||
var actual = prompt.GetParents("item");
|
||||
|
||||
// Then
|
||||
actual.ShouldBe(new[] { "root", "level-1", "level-2" });
|
||||
actual.ShouldBe(["root", "level-1", "level-2"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -50,16 +50,15 @@ public sealed class SegmentTests
|
||||
{
|
||||
// Given, When
|
||||
var lines = Segment.SplitLines(
|
||||
new[]
|
||||
{
|
||||
new Segment("Foo"),
|
||||
[
|
||||
new Segment("Foo"),
|
||||
new Segment("Bar"),
|
||||
new Segment("\n"),
|
||||
new Segment("Baz"),
|
||||
new Segment("Qux"),
|
||||
new Segment("\n"),
|
||||
new Segment("Corgi"),
|
||||
});
|
||||
new Segment("Corgi")
|
||||
]);
|
||||
|
||||
// Then
|
||||
lines.Count.ShouldBe(3);
|
||||
@@ -81,16 +80,15 @@ public sealed class SegmentTests
|
||||
{
|
||||
// Given, When
|
||||
var lines = Segment.SplitLines(
|
||||
new[]
|
||||
{
|
||||
new Segment("Foo"),
|
||||
[
|
||||
new Segment("Foo"),
|
||||
new Segment("Bar"),
|
||||
new Segment("\r\n"),
|
||||
new Segment("Baz"),
|
||||
new Segment("Qux"),
|
||||
new Segment("\r\n"),
|
||||
new Segment("Corgi"),
|
||||
});
|
||||
new Segment("Corgi")
|
||||
]);
|
||||
|
||||
// Then
|
||||
lines.Count.ShouldBe(3);
|
||||
@@ -112,14 +110,13 @@ public sealed class SegmentTests
|
||||
{
|
||||
// Given, Given
|
||||
var lines = Segment.SplitLines(
|
||||
new[]
|
||||
{
|
||||
new Segment("Foo\n"),
|
||||
[
|
||||
new Segment("Foo\n"),
|
||||
new Segment("Bar\n"),
|
||||
new Segment("Baz"),
|
||||
new Segment("Qux\n"),
|
||||
new Segment("Corgi"),
|
||||
});
|
||||
new Segment("Corgi")
|
||||
]);
|
||||
|
||||
// Then
|
||||
lines.Count.ShouldBe(4);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Spectre.Console.Extensions;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit;
|
||||
|
||||
[ExpectationPath("Widgets/Align")]
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
|
||||
// When
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
table.Rows.Add([Text.Empty]);
|
||||
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(1);
|
||||
@@ -39,10 +39,10 @@ public sealed class TableRowCollectionTests
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
table.Rows.Add([Text.Empty]);
|
||||
|
||||
// When
|
||||
var result = table.Rows.Add(new[] { Text.Empty });
|
||||
var result = table.Rows.Add([Text.Empty]);
|
||||
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
@@ -56,9 +56,9 @@ public sealed class TableRowCollectionTests
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3")]);
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
@@ -90,10 +90,10 @@ public sealed class TableRowCollectionTests
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
table.Rows.Add([Text.Empty]);
|
||||
|
||||
// When
|
||||
table.Rows.Insert(0, new[] { Text.Empty });
|
||||
table.Rows.Insert(0, [Text.Empty]);
|
||||
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(2);
|
||||
@@ -105,11 +105,11 @@ public sealed class TableRowCollectionTests
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
|
||||
// When
|
||||
var result = table.Rows.Insert(1, new[] { new Text("3") });
|
||||
var result = table.Rows.Insert(1, [new Text("3")]);
|
||||
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
@@ -123,9 +123,9 @@ public sealed class TableRowCollectionTests
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Insert(1, new[] { new Text("3") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Insert(1, [new Text("3")]);
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
@@ -158,9 +158,9 @@ public sealed class TableRowCollectionTests
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3")]);
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.RemoveAt(3));
|
||||
@@ -178,9 +178,9 @@ public sealed class TableRowCollectionTests
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3")]);
|
||||
table.Rows.RemoveAt(1);
|
||||
|
||||
// When
|
||||
@@ -199,9 +199,9 @@ public sealed class TableRowCollectionTests
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3")]);
|
||||
table.Rows.Clear();
|
||||
|
||||
// When
|
||||
@@ -223,9 +223,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
@@ -245,9 +245,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
|
||||
table.UpdateCell(2, 2, new Markup("5"));
|
||||
|
||||
@@ -267,9 +267,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
@@ -289,9 +289,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
@@ -311,9 +311,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
@@ -333,9 +333,9 @@ public sealed class TableRowCollectionTests
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.Rows.Add([new Text("1")]);
|
||||
table.Rows.Add([new Text("2")]);
|
||||
table.Rows.Add([new Text("3"), new Text("4"), new Text("8")]);
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
|
||||
@@ -4,10 +4,7 @@ public static class EmbeddedResourceReader
|
||||
{
|
||||
public static Stream LoadResourceStream(string resourceName)
|
||||
{
|
||||
if (resourceName is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(resourceName));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(resourceName);
|
||||
|
||||
var assembly = Assembly.GetCallingAssembly();
|
||||
resourceName = resourceName.Replace("/", ".");
|
||||
@@ -23,15 +20,9 @@ public static class EmbeddedResourceReader
|
||||
|
||||
public static Stream LoadResourceStream(Assembly assembly, string resourceName)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(assembly);
|
||||
|
||||
if (resourceName is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(resourceName));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(resourceName);
|
||||
|
||||
resourceName = resourceName.Replace("/", ".");
|
||||
var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
|
||||
@@ -30,7 +30,7 @@ public static class TestConsoleExtensions
|
||||
text = _filenameRegex.Replace(text, match =>
|
||||
{
|
||||
var value = match.Value;
|
||||
var index = value.LastIndexOfAny(new[] { '\\', '/' });
|
||||
var index = value.LastIndexOfAny(['\\', '/']);
|
||||
var filename = value.Substring(index + 1, value.Length - index - 1);
|
||||
|
||||
return $" in /xyz/{filename}";
|
||||
|
||||
@@ -13,10 +13,7 @@ public static partial class AnsiConsole
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static T Prompt<T>(IPrompt<T> prompt)
|
||||
{
|
||||
if (prompt is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prompt));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(prompt);
|
||||
|
||||
return prompt.Show(Console);
|
||||
}
|
||||
@@ -30,10 +27,7 @@ public static partial class AnsiConsole
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static Task<T> PromptAsync<T>(IPrompt<T> prompt, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (prompt is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prompt));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(prompt);
|
||||
|
||||
return prompt.ShowAsync(Console, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -56,10 +56,7 @@ public static partial class AnsiConsole
|
||||
throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
|
||||
}
|
||||
|
||||
if (encoder is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoder));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(encoder);
|
||||
|
||||
return _recorder.Export(encoder);
|
||||
}
|
||||
|
||||
@@ -21,10 +21,7 @@ public static partial class AnsiConsole
|
||||
/// <param name="renderable">The object to render.</param>
|
||||
public static void Write(IRenderable renderable)
|
||||
{
|
||||
if (renderable is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(renderable));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(renderable);
|
||||
|
||||
Console.Write(renderable);
|
||||
}
|
||||
|
||||
@@ -213,10 +213,7 @@ public static partial class AnsiConsole
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, char[] value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
for (var index = 0; index < value.Length; index++)
|
||||
{
|
||||
|
||||
@@ -229,10 +229,7 @@ public static partial class AnsiConsole
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, char[] value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
for (var index = 0; index < value.Length; index++)
|
||||
{
|
||||
|
||||
@@ -13,10 +13,7 @@ public sealed class AnsiConsoleFactory
|
||||
/// <returns>An implementation of <see cref="IAnsiConsole"/>.</returns>
|
||||
public IAnsiConsole Create(AnsiConsoleSettings settings)
|
||||
{
|
||||
if (settings is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
var output = settings.Out ?? new AnsiConsoleOutput(System.Console.Out);
|
||||
if (output.Writer == null)
|
||||
|
||||
@@ -16,4 +16,28 @@ public abstract partial class BoxBorder
|
||||
/// <param name="part">The part to get the character representation for.</param>
|
||||
/// <returns>A character representation of the specified border part.</returns>
|
||||
public abstract string GetPart(BoxBorderPart part);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="BoxBorder"/>.
|
||||
/// </summary>
|
||||
public static class BoxExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the safe border for a border.
|
||||
/// </summary>
|
||||
/// <param name="border">The border to get the safe border for.</param>
|
||||
/// <param name="safe">Whether or not to return the safe border.</param>
|
||||
/// <returns>The safe border if one exist, otherwise the original border.</returns>
|
||||
public static BoxBorder GetSafeBorder(this BoxBorder border, bool safe)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(border);
|
||||
|
||||
if (safe && border.SafeBorder != null)
|
||||
{
|
||||
border = border.SafeBorder;
|
||||
}
|
||||
|
||||
return border;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ namespace Spectre.Console;
|
||||
/// <summary>
|
||||
/// Represents a color.
|
||||
/// </summary>
|
||||
public partial struct Color : IEquatable<Color>
|
||||
public readonly partial struct Color : IEquatable<Color>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default color.
|
||||
@@ -220,10 +220,7 @@ public partial struct Color : IEquatable<Color>
|
||||
/// <returns>The color created from the hexadecimal string.</returns>
|
||||
public static Color FromHex(string hex)
|
||||
{
|
||||
if (hex is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hex));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(hex);
|
||||
|
||||
if (hex.StartsWith("#"))
|
||||
{
|
||||
|
||||
@@ -19,15 +19,8 @@ public static partial class Emoji
|
||||
/// <param name="emoji">The emoji.</param>
|
||||
public static void Remap(string tag, string emoji)
|
||||
{
|
||||
if (tag is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tag));
|
||||
}
|
||||
|
||||
if (emoji is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emoji));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(tag);
|
||||
ArgumentNullException.ThrowIfNull(emoji);
|
||||
|
||||
tag = tag.TrimStart(':').TrimEnd(':');
|
||||
emoji = emoji.TrimStart(':').TrimEnd(':');
|
||||
|
||||
@@ -2,33 +2,30 @@ namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal static class ProfileEnricher
|
||||
{
|
||||
private static readonly List<IProfileEnricher> _defaultEnrichers = new List<IProfileEnricher>
|
||||
{
|
||||
new AppVeyorEnricher(),
|
||||
new AzurePipelinesEnricher(),
|
||||
new BambooEnricher(),
|
||||
new BitbucketEnricher(),
|
||||
new BitriseEnricher(),
|
||||
new ContinuaEnricher(),
|
||||
new GitHubEnricher(),
|
||||
new GitLabEnricher(),
|
||||
new GoCDEnricher(),
|
||||
new JenkinsEnricher(),
|
||||
new MyGetEnricher(),
|
||||
new TeamCityEnricher(),
|
||||
new TfsEnricher(),
|
||||
new TravisEnricher(),
|
||||
};
|
||||
private static readonly List<IProfileEnricher> _defaultEnrichers =
|
||||
[
|
||||
new AppVeyorEnricher(),
|
||||
new AzurePipelinesEnricher(),
|
||||
new BambooEnricher(),
|
||||
new BitbucketEnricher(),
|
||||
new BitriseEnricher(),
|
||||
new ContinuaEnricher(),
|
||||
new GitHubEnricher(),
|
||||
new GitLabEnricher(),
|
||||
new GoCDEnricher(),
|
||||
new JenkinsEnricher(),
|
||||
new MyGetEnricher(),
|
||||
new TeamCityEnricher(),
|
||||
new TfsEnricher(),
|
||||
new TravisEnricher()
|
||||
];
|
||||
|
||||
public static void Enrich(
|
||||
Profile profile,
|
||||
ProfileEnrichment settings,
|
||||
IDictionary<string, string>? environmentVariables)
|
||||
{
|
||||
if (profile is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(profile));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(profile);
|
||||
|
||||
settings ??= new ProfileEnrichment();
|
||||
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
namespace Spectre.Console.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Align"/>.
|
||||
/// </summary>
|
||||
public static class AlignExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the width.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <param name="width">The width, or <c>null</c> for no explicit width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align Width(this Align align, int? width)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Width = width;
|
||||
return align;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the height.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <param name="height">The height, or <c>null</c> for no explicit height.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align Height(this Align align, int? height)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Height = height;
|
||||
return align;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the vertical alignment.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <param name="vertical">The vertical alignment, or <c>null</c> for no vertical alignment.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align VerticalAlignment(this Align align, VerticalAlignment? vertical)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Vertical = vertical;
|
||||
return align;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Align"/> object to be top aligned.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align TopAligned(this Align align)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Vertical = Console.VerticalAlignment.Top;
|
||||
return align;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Align"/> object to be middle aligned.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align MiddleAligned(this Align align)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Vertical = Console.VerticalAlignment.Middle;
|
||||
return align;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Align"/> object to be bottom aligned.
|
||||
/// </summary>
|
||||
/// <param name="align">The <see cref="Align"/> object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Align BottomAligned(this Align align)
|
||||
{
|
||||
if (align is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(align));
|
||||
}
|
||||
|
||||
align.Vertical = Console.VerticalAlignment.Bottom;
|
||||
return align;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAlignable"/>.
|
||||
/// </summary>
|
||||
public static class AlignableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the alignment for an <see cref="IAlignable"/> object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The alignable object type.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <param name="alignment">The alignment.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Alignment<T>(this T obj, Justify? alignment)
|
||||
where T : class, IAlignable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Alignment = alignment;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IAlignable"/> object to be left aligned.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The alignable type.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T LeftAligned<T>(this T obj)
|
||||
where T : class, IAlignable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Alignment = Justify.Left;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IAlignable"/> object to be centered.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The alignable type.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Centered<T>(this T obj)
|
||||
where T : class, IAlignable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Alignment = Justify.Center;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IAlignable"/> object to be right aligned.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The alignable type.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T RightAligned<T>(this T obj)
|
||||
where T : class, IAlignable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Alignment = Justify.Right;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace Spectre.Console.Advanced;
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||
/// </summary>
|
||||
public static class AnsiConsoleExtensions
|
||||
public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes a VT/Ansi control code sequence to the console (if supported).
|
||||
@@ -12,10 +12,7 @@ public static class AnsiConsoleExtensions
|
||||
/// <param name="sequence">The VT/Ansi control code sequence to write.</param>
|
||||
public static void WriteAnsi(this IAnsiConsole console, string sequence)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
if (console.Profile.Capabilities.Ansi)
|
||||
{
|
||||
@@ -31,6 +28,8 @@ public static class AnsiConsoleExtensions
|
||||
/// <returns>The VT/ANSI control code sequence.</returns>
|
||||
public static string ToAnsi(this IAnsiConsole console, IRenderable renderable)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return AnsiBuilder.Build(console, renderable);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Spectre.Console.Extensions;
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for running tasks with a spinner animation.
|
||||
@@ -13,8 +13,11 @@ public static class SpinnerExtensions
|
||||
/// <param name="style">The style to apply to the spinner.</param>
|
||||
/// <param name="ansiConsole">The console to write to.</param>
|
||||
/// <returns>The result of the task.</returns>
|
||||
public static async Task Spinner(this Task task, Spinner? spinner = null, Style? style = null, IAnsiConsole? ansiConsole = null)
|
||||
public static async Task Spinner(this Task task, Spinner? spinner = null, Style? style = null,
|
||||
IAnsiConsole? ansiConsole = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(task);
|
||||
|
||||
await SpinnerInternal<object>(task, spinner ?? Console.Spinner.Known.Default, style, ansiConsole);
|
||||
}
|
||||
|
||||
@@ -27,12 +30,16 @@ public static class SpinnerExtensions
|
||||
/// <param name="style">The style to apply to the spinner.</param>
|
||||
/// <param name="ansiConsole">The console to write to.</param>
|
||||
/// <returns>The result of the task.</returns>
|
||||
public static async Task<T> Spinner<T>(this Task<T> task, Spinner? spinner = null, Style? style = null, IAnsiConsole? ansiConsole = null)
|
||||
public static async Task<T> Spinner<T>(this Task<T> task, Spinner? spinner = null, Style? style = null,
|
||||
IAnsiConsole? ansiConsole = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(task);
|
||||
|
||||
return (await SpinnerInternal<T>(task, spinner ?? Console.Spinner.Known.Default, style, ansiConsole))!;
|
||||
}
|
||||
|
||||
private static async Task<T?> SpinnerInternal<T>(Task task, Spinner spinner, Style? style = null, IAnsiConsole? ansiConsole = null)
|
||||
private static async Task<T?> SpinnerInternal<T>(Task task, Spinner spinner, Style? style = null,
|
||||
IAnsiConsole? ansiConsole = null)
|
||||
{
|
||||
ansiConsole ??= AnsiConsole.Console;
|
||||
|
||||
@@ -43,21 +50,21 @@ public static class SpinnerExtensions
|
||||
// Start spinner animation in background
|
||||
var spinnerTask = Task.Run(
|
||||
async () =>
|
||||
{
|
||||
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
ansiConsole.Cursor.Show(false);
|
||||
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
ansiConsole.Cursor.Show(false);
|
||||
|
||||
var spinnerFrame = spinner.Frames[currentFrame];
|
||||
var spinnerFrame = spinner.Frames[currentFrame];
|
||||
|
||||
// Write the spinner frame
|
||||
ansiConsole.Write(new Text(spinnerFrame, style));
|
||||
ansiConsole.Write(new ControlCode(AnsiSequences.CUB(spinnerFrame.Length)));
|
||||
// Write the spinner frame
|
||||
ansiConsole.Write(new Text(spinnerFrame, style));
|
||||
ansiConsole.Write(new ControlCode(AnsiSequences.CUB(spinnerFrame.Length)));
|
||||
|
||||
currentFrame = (currentFrame + 1) % spinner.Frames.Count;
|
||||
await Task.Delay(spinner.Interval, cancellationTokenSource.Token);
|
||||
}
|
||||
}, cancellationTokenSource.Token);
|
||||
currentFrame = (currentFrame + 1) % spinner.Frames.Count;
|
||||
await Task.Delay(spinner.Interval, cancellationTokenSource.Token);
|
||||
}
|
||||
}, cancellationTokenSource.Token);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -12,8 +12,11 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="exception">The exception to write to the console.</param>
|
||||
/// <param name="format">The exception format options.</param>
|
||||
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
|
||||
public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionFormats format = ExceptionFormats.Default)
|
||||
public static void WriteException(this IAnsiConsole console, Exception exception,
|
||||
ExceptionFormats format = ExceptionFormats.Default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
console.Write(exception.GetRenderable(format));
|
||||
}
|
||||
|
||||
@@ -26,6 +29,8 @@ public static partial class AnsiConsoleExtensions
|
||||
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
|
||||
public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionSettings settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
console.Write(exception.GetRenderable(settings));
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The result of the function.</returns>
|
||||
public static T RunExclusive<T>(this IAnsiConsole console, Func<T> func)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return console.ExclusivityMode.Run(func);
|
||||
}
|
||||
|
||||
@@ -26,6 +28,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The result of the function.</returns>
|
||||
public static Task<T> RunExclusive<T>(this IAnsiConsole console, Func<Task<T>> func)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return console.ExclusivityMode.RunAsync(func);
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,12 @@ public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
internal static async Task<string> ReadLine(this IAnsiConsole console, Style? style, bool secret, char? mask, IEnumerable<string>? items = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
style ??= Style.Plain;
|
||||
var text = string.Empty;
|
||||
|
||||
var autocomplete = new List<string>(items ?? Enumerable.Empty<string>());
|
||||
var autocomplete = new List<string>(items ?? []);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -13,15 +13,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>A <see cref="LiveDisplay"/> instance.</returns>
|
||||
public static LiveDisplay Live(this IAnsiConsole console, IRenderable target)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
if (target is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(target);
|
||||
|
||||
return new LiveDisplay(console, target);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void Markup(this IAnsiConsole console, string format, params object[] args)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
Markup(console, CultureInfo.CurrentCulture, format, args);
|
||||
}
|
||||
|
||||
@@ -32,6 +34,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The interpolated string value to write.</param>
|
||||
public static void MarkupInterpolated(this IAnsiConsole console, FormattableString value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
MarkupInterpolated(console, CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
@@ -44,6 +48,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void Markup(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
Markup(console, string.Format(provider, format, args));
|
||||
}
|
||||
|
||||
@@ -64,6 +70,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The interpolated string value to write.</param>
|
||||
public static void MarkupInterpolated(this IAnsiConsole console, IFormatProvider provider, FormattableString value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
Markup(console, Console.Markup.EscapeInterpolated(provider, value));
|
||||
}
|
||||
|
||||
@@ -74,6 +82,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Markup(this IAnsiConsole console, string value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
console.Write(MarkupParser.Parse(value));
|
||||
}
|
||||
|
||||
@@ -85,6 +95,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void MarkupLine(this IAnsiConsole console, string format, params object[] args)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
MarkupLine(console, CultureInfo.CurrentCulture, format, args);
|
||||
}
|
||||
|
||||
@@ -104,6 +116,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The interpolated string value to write.</param>
|
||||
public static void MarkupLineInterpolated(this IAnsiConsole console, FormattableString value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
MarkupLineInterpolated(console, CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
@@ -114,6 +128,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void MarkupLine(this IAnsiConsole console, string value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
Markup(console, value + Environment.NewLine);
|
||||
}
|
||||
|
||||
@@ -126,6 +142,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void MarkupLine(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
Markup(console, provider, format + Environment.NewLine, args);
|
||||
}
|
||||
|
||||
@@ -146,6 +164,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="value">The interpolated string value to write.</param>
|
||||
public static void MarkupLineInterpolated(this IAnsiConsole console, IFormatProvider provider, FormattableString value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
MarkupLine(console, Console.Markup.EscapeInterpolated(provider, value));
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,7 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>A <see cref="Progress"/> instance.</returns>
|
||||
public static Progress Progress(this IAnsiConsole console)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new Progress(console);
|
||||
}
|
||||
@@ -27,10 +24,7 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>A <see cref="Status"/> instance.</returns>
|
||||
public static Status Status(this IAnsiConsole console)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new Status(console);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static T Prompt<T>(this IAnsiConsole console, IPrompt<T> prompt)
|
||||
{
|
||||
if (prompt is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prompt));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(prompt);
|
||||
|
||||
return prompt.Show(console);
|
||||
}
|
||||
@@ -31,6 +28,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static T Ask<T>(this IAnsiConsole console, string prompt)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new TextPrompt<T>(prompt).Show(console);
|
||||
}
|
||||
|
||||
@@ -44,6 +43,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static T Ask<T>(this IAnsiConsole console, string prompt, CultureInfo? culture)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
var textPrompt = new TextPrompt<T>(prompt);
|
||||
textPrompt.Culture = culture;
|
||||
return textPrompt.Show(console);
|
||||
@@ -58,6 +59,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
|
||||
public static bool Confirm(this IAnsiConsole console, string prompt, bool defaultValue = true)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new ConfirmationPrompt(prompt)
|
||||
{
|
||||
DefaultValue = defaultValue,
|
||||
@@ -75,10 +78,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static Task<T> PromptAsync<T>(this IAnsiConsole console, IPrompt<T> prompt, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (prompt is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prompt));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(prompt);
|
||||
|
||||
return prompt.ShowAsync(console, cancellationToken);
|
||||
}
|
||||
@@ -93,6 +94,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static Task<T> AskAsync<T>(this IAnsiConsole console, string prompt, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new TextPrompt<T>(prompt).ShowAsync(console, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -107,6 +110,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns>The prompt input result.</returns>
|
||||
public static Task<T> AskAsync<T>(this IAnsiConsole console, string prompt, CultureInfo? culture, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
var textPrompt = new TextPrompt<T>(prompt);
|
||||
textPrompt.Culture = culture;
|
||||
return textPrompt.ShowAsync(console, cancellationToken);
|
||||
@@ -122,6 +127,8 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
|
||||
public static Task<bool> ConfirmAsync(this IAnsiConsole console, string prompt, bool defaultValue = true, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new ConfirmationPrompt(prompt)
|
||||
{
|
||||
DefaultValue = defaultValue,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||
/// </summary>
|
||||
public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a recorder for the specified console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to record.</param>
|
||||
/// <returns>A recorder for the specified console.</returns>
|
||||
public static Recorder CreateRecorder(this IAnsiConsole console)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
return new Recorder(console);
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,8 @@ public static partial class AnsiConsoleExtensions
|
||||
[Obsolete("Consider using IAnsiConsole.Write instead.")]
|
||||
public static void Render(this IAnsiConsole console, IRenderable renderable)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
if (renderable is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(renderable));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(renderable);
|
||||
|
||||
console.Write(renderable);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ public static partial class AnsiConsoleExtensions
|
||||
/// <param name="action">The action to execute within the alternate screen buffer.</param>
|
||||
public static void AlternateScreen(this IAnsiConsole console, Action action)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
if (!console.Profile.Capabilities.Ansi)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||
/// </summary>
|
||||
public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the specified string value to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
public static void Write(this IAnsiConsole console, string text)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
console.Write(new Text(text, Style.Plain));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
/// <param name="style">The text style or <see cref="Style.Plain"/> if <see langword="null"/>.</param>
|
||||
public static void Write(this IAnsiConsole console, string text, Style? style)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
console.Write(new Text(text, style));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||
/// </summary>
|
||||
public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes an empty line to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
public static void WriteLine(this IAnsiConsole console)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
console.Write(Text.NewLine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
public static void WriteLine(this IAnsiConsole console, string text)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
WriteLine(console, text, Style.Plain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
/// <param name="style">The text style or <see cref="Style.Plain"/> if <see langword="null"/>.</param>
|
||||
public static void WriteLine(this IAnsiConsole console, string text, Style? style)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
console.Write(text + Environment.NewLine, style);
|
||||
}
|
||||
}
|
||||
@@ -5,103 +5,14 @@ namespace Spectre.Console;
|
||||
/// </summary>
|
||||
public static partial class AnsiConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a recorder for the specified console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to record.</param>
|
||||
/// <returns>A recorder for the specified console.</returns>
|
||||
public static Recorder CreateRecorder(this IAnsiConsole console)
|
||||
{
|
||||
return new Recorder(console);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to clear.</param>
|
||||
public static void Clear(this IAnsiConsole console)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(console);
|
||||
|
||||
console.Clear(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
public static void Write(this IAnsiConsole console, string text)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
console.Write(new Text(text, Style.Plain));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
/// <param name="style">The text style or <see cref="Style.Plain"/> if <see langword="null"/>.</param>
|
||||
public static void Write(this IAnsiConsole console, string text, Style? style)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
console.Write(new Text(text, style));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an empty line to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
public static void WriteLine(this IAnsiConsole console)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
console.Write(Text.NewLine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
public static void WriteLine(this IAnsiConsole console, string text)
|
||||
{
|
||||
WriteLine(console, text, Style.Plain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||
/// </summary>
|
||||
/// <param name="console">The console to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
/// <param name="style">The text style or <see cref="Style.Plain"/> if <see langword="null"/>.</param>
|
||||
public static void WriteLine(this IAnsiConsole console, string text, Style? style)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
if (text is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
console.Write(text + Environment.NewLine, style);
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="BarChart"/>.
|
||||
/// </summary>
|
||||
public static class BarChartExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds an item to the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="label">The item label.</param>
|
||||
/// <param name="value">The item value.</param>
|
||||
/// <param name="color">The item color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart AddItem(this BarChart chart, string label, double value, Color? color = null)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Data.Add(new BarChartItem(label, value, color));
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the bar chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBarChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart AddItem<T>(this BarChart chart, T item)
|
||||
where T : IBarChartItem
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (item is BarChartItem barChartItem)
|
||||
{
|
||||
chart.Data.Add(barChartItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
chart.Data.Add(
|
||||
new BarChartItem(
|
||||
item.Label,
|
||||
item.Value,
|
||||
item.Color));
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds multiple items to the bar chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBarChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart AddItems<T>(this BarChart chart, IEnumerable<T> items)
|
||||
where T : IBarChartItem
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (items is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(items));
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
AddItem(chart, item);
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds multiple items to the bar chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBarChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="converter">The converter that converts instances of <c>T</c> to <see cref="BarChartItem"/>.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart AddItems<T>(this BarChart chart, IEnumerable<T> items, Func<T, BarChartItem> converter)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (items is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(items));
|
||||
}
|
||||
|
||||
if (converter is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(converter));
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
chart.Data.Add(converter(item));
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value formatter for the bar chart using culture info.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="func">The value formatter function with culture info.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart UseValueFormatter(this BarChart chart, Func<double, CultureInfo, string>? func)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueFormatter = func;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value formatter for the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="func">The value formatter to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart UseValueFormatter(this BarChart chart, Func<double, string>? func)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueFormatter = func != null
|
||||
? (value, _) => func(value)
|
||||
: null;
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the width of the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="width">The bar chart width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart Width(this BarChart chart, int? width)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Width = width;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the label of the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="label">The bar chart label.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart Label(this BarChart chart, string? label)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Label = label;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows values next to each bar in the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart ShowValues(this BarChart chart)
|
||||
{
|
||||
return ShowValues(chart, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides values next to each bar in the bar chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart HideValues(this BarChart chart)
|
||||
{
|
||||
return ShowValues(chart, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not values should be shown
|
||||
/// next to each bar.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="show">Whether or not values should be shown next to each bar.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart ShowValues(this BarChart chart, bool show)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ShowValues = show;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns the label to the left.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart LeftAlignLabel(this BarChart chart)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.LabelAlignment = Justify.Left;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Centers the label.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart CenterLabel(this BarChart chart)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.LabelAlignment = Justify.Center;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns the label to the right.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart RightAlignLabel(this BarChart chart)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.LabelAlignment = Justify.Right;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the max fixed value for the chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The bar chart.</param>
|
||||
/// <param name="maxValue">Max value for the chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BarChart WithMaxValue(this BarChart chart, double maxValue)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.MaxValue = maxValue;
|
||||
return chart;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Spectre.Console;
|
||||
/// </summary>
|
||||
public static partial class CharExtensions
|
||||
{
|
||||
#if WCWIDTH
|
||||
/// <summary>
|
||||
/// Gets the cell width of a character.
|
||||
/// </summary>
|
||||
@@ -14,4 +15,10 @@ public static partial class CharExtensions
|
||||
{
|
||||
return Cell.GetCellLength(character);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static bool IsDigit(this char character, int min = 0)
|
||||
{
|
||||
return char.IsDigit(character) && character >= (char)min;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ internal static class EnumerableExtensions
|
||||
// so we won't have to cast List<T> to IEnumerable<T>.
|
||||
public static IEnumerable<T> ReverseEnumerable<T>(this IEnumerable<T> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
return source.Reverse();
|
||||
}
|
||||
@@ -76,20 +73,14 @@ internal static class EnumerableExtensions
|
||||
|
||||
public static IEnumerable<(int Index, bool First, bool Last, T Item)> Enumerate<T>(this IEnumerable<T> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
return Enumerate(source.GetEnumerator());
|
||||
}
|
||||
|
||||
public static IEnumerable<(int Index, bool First, bool Last, T Item)> Enumerate<T>(this IEnumerator<T> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
var first = true;
|
||||
var last = !source.MoveNext();
|
||||
@@ -14,10 +14,7 @@ public static class ExceptionExtensions
|
||||
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
|
||||
public static IRenderable GetRenderable(this Exception exception, ExceptionFormats format = ExceptionFormats.Default)
|
||||
{
|
||||
if (exception is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(exception));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(exception);
|
||||
|
||||
return GetRenderable(exception, new ExceptionSettings
|
||||
{
|
||||
@@ -34,15 +31,9 @@ public static class ExceptionExtensions
|
||||
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
|
||||
public static IRenderable GetRenderable(this Exception exception, ExceptionSettings settings)
|
||||
{
|
||||
if (exception is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(exception));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(exception);
|
||||
|
||||
if (settings is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
return ExceptionFormatter.Format(exception, settings);
|
||||
}
|
||||
@@ -4,10 +4,7 @@ internal static class ListExtensions
|
||||
{
|
||||
public static void RemoveLast<T>(this List<T> list)
|
||||
{
|
||||
if (list is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(list));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(list);
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
@@ -17,10 +14,7 @@ internal static class ListExtensions
|
||||
|
||||
public static void AddOrReplaceLast<T>(this List<T> list, T item)
|
||||
{
|
||||
if (list is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(list));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(list);
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
@@ -4,10 +4,7 @@ internal static class StackExtensions
|
||||
{
|
||||
public static void PushRange<T>(this Stack<T> stack, IEnumerable<T> source)
|
||||
{
|
||||
if (stack is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stack));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(stack);
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
@@ -101,8 +101,8 @@ public static class StringExtensions
|
||||
|
||||
internal static string[] SplitLines(this string text)
|
||||
{
|
||||
var result = text?.NormalizeNewLines()?.Split(new[] { '\n' }, StringSplitOptions.None);
|
||||
return result ?? Array.Empty<string>();
|
||||
var result = text?.NormalizeNewLines()?.Split(['\n'], StringSplitOptions.None);
|
||||
return result ?? [];
|
||||
}
|
||||
|
||||
internal static string[] SplitWords(this string word, StringSplitOptions options = StringSplitOptions.None)
|
||||
@@ -151,10 +151,7 @@ public static class StringExtensions
|
||||
|
||||
internal static string Repeat(this string text, int count)
|
||||
{
|
||||
if (text is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
@@ -219,20 +216,11 @@ public static class StringExtensions
|
||||
/// <returns>Markup of input with the first matched text highlighted.</returns>
|
||||
internal static string Highlight(this string value, string searchText, Style? highlightStyle)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
if (searchText is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(searchText));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(searchText);
|
||||
|
||||
if (highlightStyle is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(highlightStyle));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(highlightStyle);
|
||||
|
||||
if (searchText.Length == 0)
|
||||
{
|
||||
@@ -1,28 +0,0 @@
|
||||
namespace Spectre.Console.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="BoxBorder"/>.
|
||||
/// </summary>
|
||||
public static class BoxExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the safe border for a border.
|
||||
/// </summary>
|
||||
/// <param name="border">The border to get the safe border for.</param>
|
||||
/// <param name="safe">Whether or not to return the safe border.</param>
|
||||
/// <returns>The safe border if one exist, otherwise the original border.</returns>
|
||||
public static BoxBorder GetSafeBorder(this BoxBorder border, bool safe)
|
||||
{
|
||||
if (border is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(border));
|
||||
}
|
||||
|
||||
if (safe && border.SafeBorder != null)
|
||||
{
|
||||
border = border.SafeBorder;
|
||||
}
|
||||
|
||||
return border;
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="BreakdownChart"/>.
|
||||
/// </summary>
|
||||
public static class BreakdownChartExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds an item to the breakdown chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="label">The item label.</param>
|
||||
/// <param name="value">The item value.</param>
|
||||
/// <param name="color">The item color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart AddItem(this BreakdownChart chart, string label, double value, Color color)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Data.Add(new BreakdownChartItem(label, value, color));
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the breakdown chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBreakdownChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart AddItem<T>(this BreakdownChart chart, T item)
|
||||
where T : IBreakdownChartItem
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (item is BreakdownChartItem chartItem)
|
||||
{
|
||||
chart.Data.Add(chartItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
chart.Data.Add(
|
||||
new BreakdownChartItem(
|
||||
item.Label,
|
||||
item.Value,
|
||||
item.Color));
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds multiple items to the breakdown chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBreakdownChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart AddItems<T>(this BreakdownChart chart, IEnumerable<T> items)
|
||||
where T : IBreakdownChartItem
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (items is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(items));
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
AddItem(chart, item);
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds multiple items to the breakdown chart.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A type that implements <see cref="IBarChartItem"/>.</typeparam>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="converter">The converter that converts instances of <c>T</c> to <see cref="IBreakdownChartItem"/>.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart AddItems<T>(this BreakdownChart chart, IEnumerable<T> items, Func<T, IBreakdownChartItem> converter)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
if (items is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(items));
|
||||
}
|
||||
|
||||
if (converter is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(converter));
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
chart.Data.Add(converter(item));
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the width of the breakdown chart.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="width">The breakdown chart width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart Width(this BreakdownChart chart, int? width)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Width = width;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tags will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="func">The value formatter to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart UseValueFormatter(this BreakdownChart chart, Func<double, CultureInfo, string>? func)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueFormatter = func;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tags will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="func">The value formatter to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart UseValueFormatter(this BreakdownChart chart, Func<double, string>? func)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueFormatter = func != null
|
||||
? (value, _) => func(value)
|
||||
: null;
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tags will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart ShowPercentage(this BreakdownChart chart)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueFormatter = (value, culture) => string.Format(culture, "{0}%", value);
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tags will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart ShowTags(this BreakdownChart chart)
|
||||
{
|
||||
return ShowTags(chart, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tags will be not be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart HideTags(this BreakdownChart chart)
|
||||
{
|
||||
return ShowTags(chart, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not tags will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="show">Whether or not tags will be shown.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart ShowTags(this BreakdownChart chart, bool show)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ShowTags = show;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tag values will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart ShowTagValues(this BreakdownChart chart)
|
||||
{
|
||||
return ShowTagValues(chart, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tag values will be not be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart HideTagValues(this BreakdownChart chart)
|
||||
{
|
||||
return ShowTagValues(chart, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not tag values will be shown.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="show">Whether or not tag values will be shown.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart ShowTagValues(this BreakdownChart chart, bool show)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ShowTagValues = show;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chart and tags is rendered in compact mode.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart Compact(this BreakdownChart chart)
|
||||
{
|
||||
return Compact(chart, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chart and tags is rendered in full size mode.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart FullSize(this BreakdownChart chart)
|
||||
{
|
||||
return Compact(chart, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not the chart and tags should be rendered in compact mode.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="compact">Whether or not the chart and tags should be rendered in compact mode.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart Compact(this BreakdownChart chart, bool compact)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.Compact = compact;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="BreakdownChart.ValueColor"/>.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="color">The <see cref="Color"/> to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart WithValueColor(this BreakdownChart chart, Color color)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueColor = color;
|
||||
return chart;
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Calendar"/>.
|
||||
/// </summary>
|
||||
public static class CalendarExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="date">The calendar event date.</param>
|
||||
/// <param name="customEventHighlightStyle">The calendar event custom highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, DateTime date, Style? customEventHighlightStyle = null)
|
||||
{
|
||||
return AddCalendarEvent(calendar, string.Empty, date.Year, date.Month, date.Day, customEventHighlightStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="description">The calendar event description.</param>
|
||||
/// <param name="date">The calendar event date.</param>
|
||||
/// <param name="customEventHighlightStyle">The calendar event custom highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, string description, DateTime date, Style? customEventHighlightStyle = null)
|
||||
{
|
||||
return AddCalendarEvent(calendar, description, date.Year, date.Month, date.Day, customEventHighlightStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="year">The year of the calendar event.</param>
|
||||
/// <param name="month">The month of the calendar event.</param>
|
||||
/// <param name="day">The day of the calendar event.</param>
|
||||
/// <param name="customEventHighlightStyle">The calendar event custom highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, int year, int month, int day, Style? customEventHighlightStyle = null)
|
||||
{
|
||||
return AddCalendarEvent(calendar, string.Empty, year, month, day, customEventHighlightStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <param name="description">The calendar event description.</param>
|
||||
/// <param name="year">The year of the calendar event.</param>
|
||||
/// <param name="month">The month of the calendar event.</param>
|
||||
/// <param name="day">The day of the calendar event.</param>
|
||||
/// <param name="customEventHighlightStyle">The calendar event custom highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, string description, int year, int month, int day, Style? customEventHighlightStyle = null)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.CalendarEvents.Add(new CalendarEvent(description, year, month, day, customEventHighlightStyle));
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the calendar's highlight <see cref="Style"/>.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <param name="style">The default highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar HighlightStyle(this Calendar calendar, Style? style)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.HighlightStyle = style ?? Style.Plain;
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the calendar's header <see cref="Style"/>.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <param name="style">The header style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar HeaderStyle(this Calendar calendar, Style? style)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.HeaderStyle = style ?? Style.Plain;
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the calendar header.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar ShowHeader(this Calendar calendar)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.ShowHeader = true;
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the calendar header.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar HideHeader(this Calendar calendar)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.ShowHeader = false;
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IColumn"/>.
|
||||
/// </summary>
|
||||
public static class ColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Prevents a column from wrapping.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IColumn"/>.</typeparam>
|
||||
/// <param name="obj">The column.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T NoWrap<T>(this T obj)
|
||||
where T : class, IColumn
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.NoWrap = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the width of the column.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IColumn"/>.</typeparam>
|
||||
/// <param name="obj">The column.</param>
|
||||
/// <param name="width">The column width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Width<T>(this T obj, int? width)
|
||||
where T : class, IColumn
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Width = width;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="ConfirmationPrompt"/>.
|
||||
/// </summary>
|
||||
public static class ConfirmationPromptExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Show or hide choices.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="show">Whether or not the choices should be visible.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt ShowChoices(this ConfirmationPrompt obj, bool show)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.ShowChoices = show;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows choices.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt ShowChoices(this ConfirmationPrompt obj)
|
||||
{
|
||||
return ShowChoices(obj, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides choices.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt HideChoices(this ConfirmationPrompt obj)
|
||||
{
|
||||
return ShowChoices(obj, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style in which the list of choices is displayed.
|
||||
/// </summary>
|
||||
/// <param name="obj">The confirmation prompt.</param>
|
||||
/// <param name="style">The style to use for displaying the choices or <see langword="null"/> to use the default style (blue).</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt ChoicesStyle(this ConfirmationPrompt obj, Style? style)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.ChoicesStyle = style;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show or hide the default value.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="show">Whether or not the default value should be visible.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt ShowDefaultValue(this ConfirmationPrompt obj, bool show)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.ShowDefaultValue = show;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the default value.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt ShowDefaultValue(this ConfirmationPrompt obj)
|
||||
{
|
||||
return ShowDefaultValue(obj, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the default value.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt HideDefaultValue(this ConfirmationPrompt obj)
|
||||
{
|
||||
return ShowDefaultValue(obj, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style in which the default value is displayed.
|
||||
/// </summary>
|
||||
/// <param name="obj">The confirmation prompt.</param>
|
||||
/// <param name="style">The default value style or <see langword="null"/> to use the default style (green).</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt DefaultValueStyle(this ConfirmationPrompt obj, Style? style)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.DefaultValueStyle = style;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the "invalid choice" message for the prompt.
|
||||
/// </summary>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="message">The "invalid choice" message.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt InvalidChoiceMessage(this ConfirmationPrompt obj, string message)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.InvalidChoiceMessage = message;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the character to interpret as "yes".
|
||||
/// </summary>
|
||||
/// <param name="obj">The confirmation prompt.</param>
|
||||
/// <param name="character">The character to interpret as "yes".</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt Yes(this ConfirmationPrompt obj, char character)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Yes = character;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the character to interpret as "no".
|
||||
/// </summary>
|
||||
/// <param name="obj">The confirmation prompt.</param>
|
||||
/// <param name="character">The character to interpret as "no".</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ConfirmationPrompt No(this ConfirmationPrompt obj, char character)
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.No = character;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IAnsiConsoleCursor"/>.
|
||||
/// </summary>
|
||||
public static class CursorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the cursor.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void Show(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Show(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the cursor.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void Hide(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Show(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor up.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void MoveUp(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Up, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor up.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||
public static void MoveUp(this IAnsiConsoleCursor cursor, int steps)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Up, steps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor down.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void MoveDown(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Down, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor down.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||
public static void MoveDown(this IAnsiConsoleCursor cursor, int steps)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Down, steps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor to the left.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void MoveLeft(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Left, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor to the left.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||
public static void MoveLeft(this IAnsiConsoleCursor cursor, int steps)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Left, steps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor to the right.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
public static void MoveRight(this IAnsiConsoleCursor cursor)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Right, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor to the right.
|
||||
/// </summary>
|
||||
/// <param name="cursor">The cursor.</param>
|
||||
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||
public static void MoveRight(this IAnsiConsoleCursor cursor, int steps)
|
||||
{
|
||||
if (cursor is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(cursor));
|
||||
}
|
||||
|
||||
cursor.Move(CursorDirection.Right, steps);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IExpandable"/>.
|
||||
/// </summary>
|
||||
public static class ExpandableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tells the specified object to not expand to the available area
|
||||
/// but take as little space as possible.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The expandable object.</typeparam>
|
||||
/// <param name="obj">The object to collapse.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Collapse<T>(this T obj)
|
||||
where T : class, IExpandable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Expand = false;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tells the specified object to expand to the available area.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The expandable object.</typeparam>
|
||||
/// <param name="obj">The object to expand.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Expand<T>(this T obj)
|
||||
where T : class, IExpandable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Expand = true;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="FigletText"/>.
|
||||
/// </summary>
|
||||
public static class FigletTextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the color of the FIGlet text.
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <param name="color">The color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static FigletText Color(this FigletText text, Color? color)
|
||||
{
|
||||
if (text is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
text.Color = color ?? Console.Color.Default;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Grid"/>.
|
||||
/// </summary>
|
||||
public static class GridExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a column to the grid.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid to add the column to.</param>
|
||||
/// <param name="count">The number of columns to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Grid AddColumns(this Grid grid, int count)
|
||||
{
|
||||
if (grid is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(grid));
|
||||
}
|
||||
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
grid.AddColumn(new GridColumn());
|
||||
}
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a column to the grid.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid to add the column to.</param>
|
||||
/// <param name="columns">The columns to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Grid AddColumns(this Grid grid, params GridColumn[] columns)
|
||||
{
|
||||
if (grid is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(grid));
|
||||
}
|
||||
|
||||
if (columns is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columns));
|
||||
}
|
||||
|
||||
foreach (var column in columns)
|
||||
{
|
||||
grid.AddColumn(column);
|
||||
}
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an empty row to the grid.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid to add the row to.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Grid AddEmptyRow(this Grid grid)
|
||||
{
|
||||
if (grid is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(grid));
|
||||
}
|
||||
|
||||
var columns = new IRenderable[grid.Columns.Count];
|
||||
Enumerable.Range(0, grid.Columns.Count).ForEach(index => columns[index] = Text.Empty);
|
||||
grid.AddRow(columns);
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new row to the grid.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid to add the row to.</param>
|
||||
/// <param name="columns">The columns to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Grid AddRow(this Grid grid, params string[] columns)
|
||||
{
|
||||
if (grid is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(grid));
|
||||
}
|
||||
|
||||
if (columns is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columns));
|
||||
}
|
||||
|
||||
grid.AddRow(columns.Select(column => new Markup(column)).ToArray());
|
||||
return grid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the grid width.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid.</param>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Grid Width(this Grid grid, int? width)
|
||||
{
|
||||
if (grid is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(grid));
|
||||
}
|
||||
|
||||
grid.Width = width;
|
||||
return grid;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasBorder"/>.
|
||||
/// </summary>
|
||||
public static class HasBorderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables the safe border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to enable the safe border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SafeBorder<T>(this T obj)
|
||||
where T : class, IHasBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.UseSafeBorder = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the safe border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to disable the safe border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T NoSafeBorder<T>(this T obj)
|
||||
where T : class, IHasBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.UseSafeBorder = false;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the border style.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border style for.</param>
|
||||
/// <param name="style">The border style to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T BorderStyle<T>(this T obj, Style style)
|
||||
where T : class, IHasBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.BorderStyle = style;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the border color.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border color for.</param>
|
||||
/// <param name="color">The border color to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T BorderColor<T>(this T obj, Color color)
|
||||
where T : class, IHasBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).Foreground(color);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasBoxBorder"/>.
|
||||
/// </summary>
|
||||
public static class HasBoxBorderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <param name="border">The border to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Border<T>(this T obj, BoxBorder border)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Border = border;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do not display a border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T NoBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a square border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SquareBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.Square);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display an ASCII border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T AsciiBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.Ascii);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a rounded border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T RoundedBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.Rounded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a heavy border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T HeavyBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.Heavy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a double border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T DoubleBorder<T>(this T obj)
|
||||
where T : class, IHasBoxBorder
|
||||
{
|
||||
return Border(obj, BoxBorder.Double);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasCulture"/>.
|
||||
/// </summary>
|
||||
public static class HasCultureExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="culture">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Culture<T>(this T obj, CultureInfo culture)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (culture is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(culture));
|
||||
}
|
||||
|
||||
obj.Culture = culture;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="name">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Culture<T>(this T obj, string name)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
if (name is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
return Culture(obj, CultureInfo.GetCultureInfo(name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="culture">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Culture<T>(this T obj, int culture)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
return Culture(obj, CultureInfo.GetCultureInfo(culture));
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasJustification"/>.
|
||||
/// </summary>
|
||||
public static class HasJustificationExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the justification for an <see cref="IHasJustification"/> object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type that can be justified.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <param name="alignment">The alignment.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Justify<T>(this T obj, Justify? alignment)
|
||||
where T : class, IHasJustification
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Justification = alignment;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IHasJustification"/> object to be left justified.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type that can be justified.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T LeftJustified<T>(this T obj)
|
||||
where T : class, IHasJustification
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Justification = Console.Justify.Left;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IHasJustification"/> object to be centered.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type that can be justified.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Centered<T>(this T obj)
|
||||
where T : class, IHasJustification
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Justification = Console.Justify.Center;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IHasJustification"/> object to be right justified.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type that can be justified.</typeparam>
|
||||
/// <param name="obj">The alignable object.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T RightJustified<T>(this T obj)
|
||||
where T : class, IHasJustification
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Justification = Console.Justify.Right;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasTableBorder"/>.
|
||||
/// </summary>
|
||||
public static class HasTableBorderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Do not display a border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T NoBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a square border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SquareBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Square);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display an ASCII border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T AsciiBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Ascii);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display another ASCII border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Ascii2Border<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Ascii2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display an ASCII border with a double header border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T AsciiDoubleHeadBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.AsciiDoubleHead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a rounded border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T RoundedBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Rounded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a minimal border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T MinimalBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Minimal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a minimal border with a heavy head.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T MinimalHeavyHeadBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.MinimalHeavyHead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a minimal border with a double header border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T MinimalDoubleHeadBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.MinimalDoubleHead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a simple border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SimpleBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Simple);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a simple border with heavy lines.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SimpleHeavyBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.SimpleHeavy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a simple border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T HorizontalBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Horizontal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a heavy border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T HeavyBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Heavy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a border with a heavy edge.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T HeavyEdgeBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.HeavyEdge);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a border with a heavy header.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T HeavyHeadBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.HeavyHead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a double border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T DoubleBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Double);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a border with a double edge.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T DoubleEdgeBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.DoubleEdge);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a markdown border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T MarkdownBorder<T>(this T obj)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
return Border(obj, TableBorder.Markdown);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the border.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||
/// <param name="obj">The object to set the border for.</param>
|
||||
/// <param name="border">The border to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Border<T>(this T obj, TableBorder border)
|
||||
where T : class, IHasTableBorder
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Border = border;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasTreeNodes"/>.
|
||||
/// </summary>
|
||||
public static class HasTreeNodeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a tree node.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree node to.</param>
|
||||
/// <param name="markup">The node's markup text.</param>
|
||||
/// <returns>The added tree node.</returns>
|
||||
public static TreeNode AddNode<T>(this T obj, string markup)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (markup is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(markup));
|
||||
}
|
||||
|
||||
return AddNode(obj, new Markup(markup));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a tree node.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree node to.</param>
|
||||
/// <param name="renderable">The renderable to add.</param>
|
||||
/// <returns>The added tree node.</returns>
|
||||
public static TreeNode AddNode<T>(this T obj, IRenderable renderable)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (renderable is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(renderable));
|
||||
}
|
||||
|
||||
var node = new TreeNode(renderable);
|
||||
obj.Nodes.Add(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a tree node.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree node to.</param>
|
||||
/// <param name="node">The tree node to add.</param>
|
||||
/// <returns>The added tree node.</returns>
|
||||
public static TreeNode AddNode<T>(this T obj, TreeNode node)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (node is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(node));
|
||||
}
|
||||
|
||||
obj.Nodes.Add(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, params string[] nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes.Select(node => new TreeNode(new Markup(node))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, IEnumerable<string> nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes.Select(node => new TreeNode(new Markup(node))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, params IRenderable[] nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes.Select(node => new TreeNode(node)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, IEnumerable<IRenderable> nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes.Select(node => new TreeNode(node)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, params TreeNode[] nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add multiple tree nodes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object with tree nodes.</typeparam>
|
||||
/// <param name="obj">The object to add the tree nodes to.</param>
|
||||
/// <param name="nodes">The tree nodes to add.</param>
|
||||
public static void AddNodes<T>(this T obj, IEnumerable<TreeNode> nodes)
|
||||
where T : IHasTreeNodes
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (nodes is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodes));
|
||||
}
|
||||
|
||||
obj.Nodes.AddRange(nodes);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Layout"/>.
|
||||
/// </summary>
|
||||
public static class LayoutExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the ratio of the layout.
|
||||
/// </summary>
|
||||
/// <param name="layout">The layout.</param>
|
||||
/// <param name="ratio">The ratio.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Layout Ratio(this Layout layout, int ratio)
|
||||
{
|
||||
if (layout is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(layout));
|
||||
}
|
||||
|
||||
layout.Ratio = ratio;
|
||||
return layout;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of the layout.
|
||||
/// </summary>
|
||||
/// <param name="layout">The layout.</param>
|
||||
/// <param name="size">The size.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Layout Size(this Layout layout, int size)
|
||||
{
|
||||
if (layout is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(layout));
|
||||
}
|
||||
|
||||
layout.Size = size;
|
||||
return layout;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the minimum width of the layout.
|
||||
/// </summary>
|
||||
/// <param name="layout">The layout.</param>
|
||||
/// <param name="size">The size.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Layout MinimumSize(this Layout layout, int size)
|
||||
{
|
||||
if (layout is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(layout));
|
||||
}
|
||||
|
||||
layout.MinimumSize = size;
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="LiveDisplay"/>.
|
||||
/// </summary>
|
||||
public static class LiveDisplayExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets whether or not auto clear is enabled.
|
||||
/// If enabled, the live display will be cleared when done.
|
||||
/// </summary>
|
||||
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not auto clear is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static LiveDisplay AutoClear(this LiveDisplay live, bool enabled)
|
||||
{
|
||||
if (live is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(live));
|
||||
}
|
||||
|
||||
live.AutoClear = enabled;
|
||||
|
||||
return live;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the vertical overflow strategy.
|
||||
/// </summary>
|
||||
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
|
||||
/// <param name="overflow">The overflow strategy to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static LiveDisplay Overflow(this LiveDisplay live, VerticalOverflow overflow)
|
||||
{
|
||||
if (live is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(live));
|
||||
}
|
||||
|
||||
live.Overflow = overflow;
|
||||
|
||||
return live;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the vertical overflow cropping strategy.
|
||||
/// </summary>
|
||||
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
|
||||
/// <param name="cropping">The overflow cropping strategy to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static LiveDisplay Cropping(this LiveDisplay live, VerticalOverflowCropping cropping)
|
||||
{
|
||||
if (live is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(live));
|
||||
}
|
||||
|
||||
live.Cropping = cropping;
|
||||
|
||||
return live;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IOverflowable"/>.
|
||||
/// </summary>
|
||||
public static class OverflowableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Folds any overflowing text.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IOverflowable"/>.</typeparam>
|
||||
/// <param name="obj">The overflowable object instance.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Fold<T>(this T obj)
|
||||
where T : class, IOverflowable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Overflow(obj, Console.Overflow.Fold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crops any overflowing text.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IOverflowable"/>.</typeparam>
|
||||
/// <param name="obj">The overflowable object instance.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Crop<T>(this T obj)
|
||||
where T : class, IOverflowable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Overflow(obj, Console.Overflow.Crop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crops any overflowing text and adds an ellipsis to the end.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IOverflowable"/>.</typeparam>
|
||||
/// <param name="obj">The overflowable object instance.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Ellipsis<T>(this T obj)
|
||||
where T : class, IOverflowable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Overflow(obj, Console.Overflow.Ellipsis);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the overflow strategy.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IOverflowable"/>.</typeparam>
|
||||
/// <param name="obj">The overflowable object instance.</param>
|
||||
/// <param name="overflow">The overflow strategy to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Overflow<T>(this T obj, Overflow overflow)
|
||||
where T : class, IOverflowable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Overflow = overflow;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IPaddable"/>.
|
||||
/// </summary>
|
||||
public static class PaddableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the left padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="left">The left padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadLeft<T>(this T obj, int left)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Padding(obj, new Padding(left, obj.Padding.GetTopSafe(), obj.Padding.GetRightSafe(), obj.Padding.GetBottomSafe()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the top padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="top">The top padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadTop<T>(this T obj, int top)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), top, obj.Padding.GetRightSafe(), obj.Padding.GetBottomSafe()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the right padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="right">The right padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadRight<T>(this T obj, int right)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), obj.Padding.GetTopSafe(), right, obj.Padding.GetBottomSafe()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the bottom padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="bottom">The bottom padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadBottom<T>(this T obj, int bottom)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), obj.Padding.GetTopSafe(), obj.Padding.GetRightSafe(), bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the left, top, right and bottom padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="left">The left padding to apply.</param>
|
||||
/// <param name="top">The top padding to apply.</param>
|
||||
/// <param name="right">The right padding to apply.</param>
|
||||
/// <param name="bottom">The bottom padding to apply.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Padding<T>(this T obj, int left, int top, int right, int bottom)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
return Padding(obj, new Padding(left, top, right, bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the horizontal and vertical padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="horizontal">The left and right padding.</param>
|
||||
/// <param name="vertical">The top and bottom padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Padding<T>(this T obj, int horizontal, int vertical)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
return Padding(obj, new Padding(horizontal, vertical));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="padding">The padding to apply.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T Padding<T>(this T obj, Padding padding)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Padding = padding;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Padding"/>.
|
||||
/// </summary>
|
||||
public static class PaddingExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the left padding.
|
||||
/// </summary>
|
||||
/// <param name="padding">The padding.</param>
|
||||
/// <returns>The left padding or zero if <c>padding</c> is null.</returns>
|
||||
public static int GetLeftSafe(this Padding? padding)
|
||||
{
|
||||
return padding?.Left ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the right padding.
|
||||
/// </summary>
|
||||
/// <param name="padding">The padding.</param>
|
||||
/// <returns>The right padding or zero if <c>padding</c> is null.</returns>
|
||||
public static int GetRightSafe(this Padding? padding)
|
||||
{
|
||||
return padding?.Right ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top padding.
|
||||
/// </summary>
|
||||
/// <param name="padding">The padding.</param>
|
||||
/// <returns>The top padding or zero if <c>padding</c> is null.</returns>
|
||||
public static int GetTopSafe(this Padding? padding)
|
||||
{
|
||||
return padding?.Top ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom padding.
|
||||
/// </summary>
|
||||
/// <param name="padding">The padding.</param>
|
||||
/// <returns>The bottom padding or zero if <c>padding</c> is null.</returns>
|
||||
public static int GetBottomSafe(this Padding? padding)
|
||||
{
|
||||
return padding?.Bottom ?? 0;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Panel"/>.
|
||||
/// </summary>
|
||||
public static class PanelExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the panel header.
|
||||
/// </summary>
|
||||
/// <param name="panel">The panel.</param>
|
||||
/// <param name="text">The header text.</param>
|
||||
/// <param name="alignment">The header alignment.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Panel Header(this Panel panel, string text, Justify? alignment = null)
|
||||
{
|
||||
if (panel is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(panel));
|
||||
}
|
||||
|
||||
if (text is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
alignment ??= panel.Header?.Justification;
|
||||
return Header(panel, new PanelHeader(text, alignment));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the panel header alignment.
|
||||
/// </summary>
|
||||
/// <param name="panel">The panel.</param>
|
||||
/// <param name="alignment">The header alignment.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Panel HeaderAlignment(this Panel panel, Justify alignment)
|
||||
{
|
||||
if (panel is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(panel));
|
||||
}
|
||||
|
||||
if (panel.Header != null)
|
||||
{
|
||||
// Update existing style
|
||||
panel.Header.Justification = alignment;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create header
|
||||
Header(panel, string.Empty, alignment);
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the panel header.
|
||||
/// </summary>
|
||||
/// <param name="panel">The panel.</param>
|
||||
/// <param name="header">The header to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Panel Header(this Panel panel, PanelHeader header)
|
||||
{
|
||||
if (panel is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(panel));
|
||||
}
|
||||
|
||||
panel.Header = header;
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="PercentageColumn"/>.
|
||||
/// </summary>
|
||||
public static class PercentageColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the style for a non-complete task.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static PercentageColumn Style(this PercentageColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.Style = style;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style for a completed task.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static PercentageColumn CompletedStyle(this PercentageColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.CompletedStyle = style;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="ProgressBarColumn"/>.
|
||||
/// </summary>
|
||||
public static class ProgressBarColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the style of completed portions of the progress bar.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressBarColumn CompletedStyle(this ProgressBarColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.CompletedStyle = style;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style of a finished progress bar.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressBarColumn FinishedStyle(this ProgressBarColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.FinishedStyle = style;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style of remaining portions of the progress bar.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressBarColumn RemainingStyle(this ProgressBarColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.RemainingStyle = style;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Progress"/>.
|
||||
/// </summary>
|
||||
public static class ProgressExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the columns to be used for an <see cref="Progress"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="columns">The columns to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress Columns(this Progress progress, params ProgressColumn[] columns)
|
||||
{
|
||||
if (progress is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
}
|
||||
|
||||
if (columns is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columns));
|
||||
}
|
||||
|
||||
if (!columns.Any())
|
||||
{
|
||||
throw new InvalidOperationException("At least one column must be specified.");
|
||||
}
|
||||
|
||||
progress.Columns.Clear();
|
||||
progress.Columns.AddRange(columns);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets an optional hook to intercept rendering.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="renderHook">The custom render function.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress UseRenderHook(this Progress progress, Func<IRenderable, IReadOnlyList<ProgressTask>, IRenderable> renderHook)
|
||||
{
|
||||
progress.RenderHook = renderHook;
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not auto refresh is enabled.
|
||||
/// If disabled, you will manually have to refresh the progress.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not auto refresh is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress AutoRefresh(this Progress progress, bool enabled)
|
||||
{
|
||||
if (progress is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
}
|
||||
|
||||
progress.AutoRefresh = enabled;
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not auto clear is enabled.
|
||||
/// If enabled, the task tabled will be removed once
|
||||
/// all tasks have completed.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not auto clear is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress AutoClear(this Progress progress, bool enabled)
|
||||
{
|
||||
if (progress is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
}
|
||||
|
||||
progress.AutoClear = enabled;
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not hide completed is enabled.
|
||||
/// If enabled, the task tabled will be removed once it is
|
||||
/// completed.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not hide completed is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress HideCompleted(this Progress progress, bool enabled)
|
||||
{
|
||||
if (progress is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
}
|
||||
|
||||
progress.HideCompleted = enabled;
|
||||
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="ProgressTask"/>.
|
||||
/// </summary>
|
||||
public static class ProgressTaskExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the task description.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="description">The description.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressTask Description(this ProgressTask task, string description)
|
||||
{
|
||||
if (task is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(task));
|
||||
}
|
||||
|
||||
task.Description = description;
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the max value of the task.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="value">The max value.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressTask MaxValue(this ProgressTask task, double value)
|
||||
{
|
||||
if (task is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(task));
|
||||
}
|
||||
|
||||
task.MaxValue = value;
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of the task.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressTask Value(this ProgressTask task, double value)
|
||||
{
|
||||
if (task is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(task));
|
||||
}
|
||||
|
||||
task.Value = value;
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the task is considered indeterminate or not.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="indeterminate">Whether the task is considered indeterminate or not.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressTask IsIndeterminate(this ProgressTask task, bool indeterminate = true)
|
||||
{
|
||||
if (task is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(task));
|
||||
}
|
||||
|
||||
task.IsIndeterminate = indeterminate;
|
||||
return task;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="RemainingTimeColumn"/>.
|
||||
/// </summary>
|
||||
public static class RemainingTimeColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the style of the remaining time text.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static RemainingTimeColumn Style(this RemainingTimeColumn column, Style style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
column.Style = style;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="SpinnerColumn"/>.
|
||||
/// </summary>
|
||||
public static class SpinnerColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the style of the spinner.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SpinnerColumn Style(this SpinnerColumn column, Style? style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
column.Style = style;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the text that should be shown instead of the spinner
|
||||
/// once a task completes.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SpinnerColumn CompletedText(this SpinnerColumn column, string? text)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
column.CompletedText = text;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the completed style of the spinner.
|
||||
/// </summary>
|
||||
/// <param name="column">The column.</param>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SpinnerColumn CompletedStyle(this SpinnerColumn column, Style? style)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
column.CompletedStyle = style;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="StatusContext"/>.
|
||||
/// </summary>
|
||||
public static class StatusContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the status message.
|
||||
/// </summary>
|
||||
/// <param name="context">The status context.</param>
|
||||
/// <param name="status">The status message.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static StatusContext Status(this StatusContext context, string status)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
context.Status = status;
|
||||
return context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spinner.
|
||||
/// </summary>
|
||||
/// <param name="context">The status context.</param>
|
||||
/// <param name="spinner">The spinner.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static StatusContext Spinner(this StatusContext context, Spinner spinner)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
context.Spinner = spinner;
|
||||
return context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spinner style.
|
||||
/// </summary>
|
||||
/// <param name="context">The status context.</param>
|
||||
/// <param name="style">The spinner style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static StatusContext SpinnerStyle(this StatusContext context, Style? style)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
context.SpinnerStyle = style;
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Status"/>.
|
||||
/// </summary>
|
||||
public static class StatusExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets whether or not auto refresh is enabled.
|
||||
/// If disabled, you will manually have to refresh the progress.
|
||||
/// </summary>
|
||||
/// <param name="status">The <see cref="Status"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not auto refresh is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Status AutoRefresh(this Status status, bool enabled)
|
||||
{
|
||||
if (status is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(status));
|
||||
}
|
||||
|
||||
status.AutoRefresh = enabled;
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spinner.
|
||||
/// </summary>
|
||||
/// <param name="status">The <see cref="Status"/> instance.</param>
|
||||
/// <param name="spinner">The spinner.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Status Spinner(this Status status, Spinner spinner)
|
||||
{
|
||||
if (status is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(status));
|
||||
}
|
||||
|
||||
status.Spinner = spinner;
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spinner style.
|
||||
/// </summary>
|
||||
/// <param name="status">The <see cref="Status"/> instance.</param>
|
||||
/// <param name="style">The spinner style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Status SpinnerStyle(this Status status, Style? style)
|
||||
{
|
||||
if (status is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(status));
|
||||
}
|
||||
|
||||
status.SpinnerStyle = style;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Recorder"/>.
|
||||
/// </summary>
|
||||
public static class RecorderExtensions
|
||||
{
|
||||
private static readonly TextEncoder _textEncoder = new TextEncoder();
|
||||
private static readonly HtmlEncoder _htmlEncoder = new HtmlEncoder();
|
||||
|
||||
/// <summary>
|
||||
/// Exports the recorded content as text.
|
||||
/// </summary>
|
||||
/// <param name="recorder">The recorder.</param>
|
||||
/// <returns>The recorded content as text.</returns>
|
||||
public static string ExportText(this Recorder recorder)
|
||||
{
|
||||
if (recorder is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(recorder));
|
||||
}
|
||||
|
||||
return recorder.Export(_textEncoder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports the recorded content as HTML.
|
||||
/// </summary>
|
||||
/// <param name="recorder">The recorder.</param>
|
||||
/// <returns>The recorded content as HTML.</returns>
|
||||
public static string ExportHtml(this Recorder recorder)
|
||||
{
|
||||
if (recorder is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(recorder));
|
||||
}
|
||||
|
||||
return recorder.Export(_htmlEncoder);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
internal static class RenderOptionsExtensions
|
||||
{
|
||||
public static BoxBorder GetSafeBorder<T>(this RenderOptions options, T border)
|
||||
where T : IHasBoxBorder, IHasBorder
|
||||
{
|
||||
return BoxExtensions.GetSafeBorder(border.Border, !options.Unicode && border.UseSafeBorder);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="RuleExtensions"/>.
|
||||
/// </summary>
|
||||
public static class RuleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the rule title.
|
||||
/// </summary>
|
||||
/// <param name="rule">The rule.</param>
|
||||
/// <param name="title">The title.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Rule RuleTitle(this Rule rule, string title)
|
||||
{
|
||||
if (rule is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(rule));
|
||||
}
|
||||
|
||||
if (title is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(title));
|
||||
}
|
||||
|
||||
rule.Title = title;
|
||||
return rule;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the rule style.
|
||||
/// </summary>
|
||||
/// <param name="rule">The rule.</param>
|
||||
/// <param name="style">The rule style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Rule RuleStyle(this Rule rule, Style style)
|
||||
{
|
||||
if (rule is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(rule));
|
||||
}
|
||||
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
rule.Style = style;
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Style"/>.
|
||||
/// </summary>
|
||||
public static class StyleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new style from the specified one with
|
||||
/// the specified foreground color.
|
||||
/// </summary>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <param name="color">The foreground color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Style Foreground(this Style style, Color color)
|
||||
{
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
return new Style(
|
||||
foreground: color,
|
||||
background: style.Background,
|
||||
decoration: style.Decoration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new style from the specified one with
|
||||
/// the specified background color.
|
||||
/// </summary>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <param name="color">The background color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Style Background(this Style style, Color color)
|
||||
{
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
return new Style(
|
||||
foreground: style.Foreground,
|
||||
background: color,
|
||||
decoration: style.Decoration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new style from the specified one with
|
||||
/// the specified text decoration.
|
||||
/// </summary>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <param name="decoration">The text decoration.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Style Decoration(this Style style, Decoration decoration)
|
||||
{
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
return new Style(
|
||||
foreground: style.Foreground,
|
||||
background: style.Background,
|
||||
decoration: decoration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new style from the specified one with
|
||||
/// the specified link.
|
||||
/// </summary>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <param name="link">The link.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Style Link(this Style style, string link)
|
||||
{
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
return new Style(
|
||||
foreground: style.Foreground,
|
||||
background: style.Background,
|
||||
decoration: style.Decoration,
|
||||
link: link);
|
||||
}
|
||||
|
||||
internal static Style Combine(this Style style, IEnumerable<Style> source)
|
||||
{
|
||||
if (style is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(style));
|
||||
}
|
||||
|
||||
var current = style;
|
||||
foreach (var item in source)
|
||||
{
|
||||
current = current.Combine(item);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
namespace Spectre.Console.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="TableBorder"/>.
|
||||
/// </summary>
|
||||
public static class TableBorderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the safe border for a border.
|
||||
/// </summary>
|
||||
/// <param name="border">The border to get the safe border for.</param>
|
||||
/// <param name="safe">Whether or not to return the safe border.</param>
|
||||
/// <returns>The safe border if one exist, otherwise the original border.</returns>
|
||||
public static TableBorder GetSafeBorder(this TableBorder border, bool safe)
|
||||
{
|
||||
if (border is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(border));
|
||||
}
|
||||
|
||||
if (safe && border.SafeBorder != null)
|
||||
{
|
||||
border = border.SafeBorder;
|
||||
}
|
||||
|
||||
return border;
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="TableColumn"/>.
|
||||
/// </summary>
|
||||
public static class TableColumnExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the table column header.
|
||||
/// </summary>
|
||||
/// <param name="column">The table column.</param>
|
||||
/// <param name="header">The table column header markup text.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TableColumn Header(this TableColumn column, string header)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (header is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(header));
|
||||
}
|
||||
|
||||
column.Header = new Markup(header);
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the table column header.
|
||||
/// </summary>
|
||||
/// <param name="column">The table column.</param>
|
||||
/// <param name="header">The table column header.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TableColumn Header(this TableColumn column, IRenderable header)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (header is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(header));
|
||||
}
|
||||
|
||||
column.Header = header;
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the table column footer.
|
||||
/// </summary>
|
||||
/// <param name="column">The table column.</param>
|
||||
/// <param name="footer">The table column footer markup text.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TableColumn Footer(this TableColumn column, string footer)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (footer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(footer));
|
||||
}
|
||||
|
||||
column.Footer = new Markup(footer);
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the table column footer.
|
||||
/// </summary>
|
||||
/// <param name="column">The table column.</param>
|
||||
/// <param name="footer">The table column footer.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TableColumn Footer(this TableColumn column, IRenderable footer)
|
||||
{
|
||||
if (column is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(column));
|
||||
}
|
||||
|
||||
if (footer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(footer));
|
||||
}
|
||||
|
||||
column.Footer = footer;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user