diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
index 61af9540..df0f204a 100644
--- a/.git-blame-ignore-revs
+++ b/.git-blame-ignore-revs
@@ -1,8 +1,5 @@
# Use file scoped namespace declarations
7b2da0a4f63bf3ceab99d2c88535e74155f2b99c
-# Fix line-endings
+# fix line-endings
e2ad4b1ea5555e701cda4fd400bb6592e318e1ff
-
-# Modernization of code base (extension blocks)
-3f57df5af667beeaab128d865a8818c246af8ea1
\ No newline at end of file
diff --git a/build.cs b/build.cs
index a4dae10a..81da16f4 100644
--- a/build.cs
+++ b/build.cs
@@ -21,7 +21,10 @@ Task("Clean")
Task("Lint")
.Does(ctx =>
{
- ctx.DotNetFormatStyle(solution);
+ ctx.DotNetFormatStyle(solution, new DotNetFormatSettings
+ {
+ VerifyNoChanges = true,
+ });
});
Task("Build")
diff --git a/src/.editorconfig b/src/.editorconfig
index 3372de8b..bf817945 100644
--- a/src/.editorconfig
+++ b/src/.editorconfig
@@ -1,12 +1,6 @@
-[*.cs]
-# ========================================================
-# Temporarily disable warnings related to extension blocks
-# ========================================================
-dotnet_diagnostic.RCS1139.severity = none
-dotnet_diagnostic.RCS1263.severity = none
-dotnet_diagnostic.CS1572.severity = none
-dotnet_diagnostic.CA1510.severity = warning
+root = false
+[*.cs]
# Prefer file scoped namespace declarations
csharp_style_namespace_declarations = file_scoped:warning
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 12edbf01..0eecf4ad 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -1,4 +1,4 @@
-
+true14
@@ -14,12 +14,6 @@
true$(MSBuildThisFileDirectory)\..\resources\spectre.snk00240000048000009400000006020000002400005253413100040000010001006146d3789d31477cf4a3b508dcf772ff9ccad8613f6bd6b17b9c4a960a7a7b551ecd22e4f4119ced70ee8bbdf3ca0a117c99fd6248c16255ea9033110c2233d42e74e81bf4f3f7eb09bfe8b53ad399d957514f427171a86f5fe9fe0014be121d571c80c4a0cfc3531bdbf5a2900d936d93f2c94171b9134f7644a1ac3612a0d0
- true
-
-
-
-
- $(NoWarn);AD0001
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index d799e93d..e5b973e6 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -4,7 +4,7 @@
-
+
@@ -18,12 +18,12 @@
-
+
-
+
diff --git a/src/Extensions/Spectre.Console.ImageSharp/CanvasImageExtensions.cs b/src/Extensions/Spectre.Console.ImageSharp/CanvasImageExtensions.cs
index 5b0e93ae..0da36c36 100644
--- a/src/Extensions/Spectre.Console.ImageSharp/CanvasImageExtensions.cs
+++ b/src/Extensions/Spectre.Console.ImageSharp/CanvasImageExtensions.cs
@@ -8,100 +8,127 @@ namespace Spectre.Console;
///
public static class CanvasImageExtensions
{
+ ///
+ /// Sets the maximum width of the rendered image.
+ ///
/// The canvas image.
- extension(CanvasImage image)
+ /// The maximum width.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage MaxWidth(this CanvasImage image, int? maxWidth)
{
- ///
- /// Sets the maximum width of the rendered image.
- ///
- /// The maximum width.
- /// The same instance so that multiple calls can be chained.
- public CanvasImage MaxWidth(int? maxWidth)
+ if (image is null)
{
- ArgumentNullException.ThrowIfNull(image);
-
- image.MaxWidth = maxWidth;
- return image;
+ throw new ArgumentNullException(nameof(image));
}
- ///
- /// Disables the maximum width of the rendered image.
- ///
- /// The same instance so that multiple calls can be chained.
- public CanvasImage NoMaxWidth()
- {
- ArgumentNullException.ThrowIfNull(image);
+ image.MaxWidth = maxWidth;
+ return image;
+ }
- image.MaxWidth = null;
- return image;
+ ///
+ /// Disables the maximum width of the rendered image.
+ ///
+ /// The canvas image.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage NoMaxWidth(this CanvasImage image)
+ {
+ if (image is null)
+ {
+ throw new ArgumentNullException(nameof(image));
}
- ///
- /// Sets the pixel width.
- ///
- /// The pixel width.
- /// The same instance so that multiple calls can be chained.
- public CanvasImage PixelWidth(int width)
- {
- ArgumentNullException.ThrowIfNull(image);
+ image.MaxWidth = null;
+ return image;
+ }
- image.PixelWidth = width;
- return image;
+ ///
+ /// Sets the pixel width.
+ ///
+ /// The canvas image.
+ /// The pixel width.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage PixelWidth(this CanvasImage image, int width)
+ {
+ if (image is null)
+ {
+ throw new ArgumentNullException(nameof(image));
}
- ///
- /// Mutates the underlying image.
- ///
- /// The action that mutates the underlying image.
- /// The same instance so that multiple calls can be chained.
- public CanvasImage Mutate(Action action)
+ image.PixelWidth = width;
+ return image;
+ }
+
+ ///
+ /// Mutates the underlying image.
+ ///
+ /// The canvas image.
+ /// The action that mutates the underlying image.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage Mutate(this CanvasImage image, Action action)
+ {
+ if (image is null)
{
- ArgumentNullException.ThrowIfNull(image);
-
- ArgumentNullException.ThrowIfNull(action);
-
- image.Image.Mutate(action);
- return image;
+ throw new ArgumentNullException(nameof(image));
}
- ///
- /// Uses a bicubic sampler that implements the bicubic kernel algorithm W(x).
- ///
- /// The same instance so that multiple calls can be chained.
- public CanvasImage BicubicResampler()
+ if (action is null)
{
- ArgumentNullException.ThrowIfNull(image);
-
- image.Resampler = KnownResamplers.Bicubic;
- return image;
+ throw new ArgumentNullException(nameof(action));
}
- ///
- /// Uses a bilinear sampler. This interpolation algorithm
- /// can be used where perfect image transformation with pixel matching is impossible,
- /// so that one can calculate and assign appropriate intensity values to pixels.
- ///
- /// The same instance so that multiple calls can be chained.
- public CanvasImage BilinearResampler()
- {
- ArgumentNullException.ThrowIfNull(image);
+ image.Image.Mutate(action);
+ return image;
+ }
- image.Resampler = KnownResamplers.Triangle;
- return image;
+ ///
+ /// Uses a bicubic sampler that implements the bicubic kernel algorithm W(x).
+ ///
+ /// The canvas image.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage BicubicResampler(this CanvasImage image)
+ {
+ if (image is null)
+ {
+ throw new ArgumentNullException(nameof(image));
}
- ///
- /// Uses a Nearest-Neighbour sampler that implements the nearest neighbor algorithm.
- /// This uses a very fast, unscaled filter which will select the closest pixel to
- /// the new pixels position.
- ///
- /// The same instance so that multiple calls can be chained.
- public CanvasImage NearestNeighborResampler()
- {
- ArgumentNullException.ThrowIfNull(image);
+ image.Resampler = KnownResamplers.Bicubic;
+ return image;
+ }
- image.Resampler = KnownResamplers.NearestNeighbor;
- return image;
+ ///
+ /// Uses a bilinear sampler. This interpolation algorithm
+ /// can be used where perfect image transformation with pixel matching is impossible,
+ /// so that one can calculate and assign appropriate intensity values to pixels.
+ ///
+ /// The canvas image.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage BilinearResampler(this CanvasImage image)
+ {
+ if (image is null)
+ {
+ throw new ArgumentNullException(nameof(image));
}
+
+ image.Resampler = KnownResamplers.Triangle;
+ return image;
+ }
+
+ ///
+ /// Uses a Nearest-Neighbour sampler that implements the nearest neighbor algorithm.
+ /// This uses a very fast, unscaled filter which will select the closest pixel to
+ /// the new pixels position.
+ ///
+ /// The canvas image.
+ /// The same instance so that multiple calls can be chained.
+ public static CanvasImage NearestNeighborResampler(this CanvasImage image)
+ {
+ if (image is null)
+ {
+ throw new ArgumentNullException(nameof(image));
+ }
+
+ image.Resampler = KnownResamplers.NearestNeighbor;
+ return image;
}
}
\ No newline at end of file
diff --git a/src/Extensions/Spectre.Console.Json/JsonTextExtensions.cs b/src/Extensions/Spectre.Console.Json/JsonTextExtensions.cs
index db8b46e7..634d72ac 100644
--- a/src/Extensions/Spectre.Console.Json/JsonTextExtensions.cs
+++ b/src/Extensions/Spectre.Console.Json/JsonTextExtensions.cs
@@ -5,241 +5,309 @@ namespace Spectre.Console.Json;
///
public static class JsonTextExtensions
{
+ ///
+ /// Sets the style used for braces.
+ ///
/// The JSON text instance.
- extension(JsonText text)
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BracesStyle(this JsonText text, Style? style)
{
- ///
- /// Sets the style used for braces.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BracesStyle(Style style)
+ if (text == null)
{
- ArgumentNullException.ThrowIfNull(text);
-
- text.BracesStyle = style;
- return text;
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for brackets.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BracketStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BracesStyle = style;
+ return text;
+ }
- text.BracketsStyle = style;
- return text;
+ ///
+ /// Sets the style used for brackets.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BracketStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for member names.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText MemberStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BracketsStyle = style;
+ return text;
+ }
- text.MemberStyle = style;
- return text;
+ ///
+ /// Sets the style used for member names.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText MemberStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for colons.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText ColonStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.MemberStyle = style;
+ return text;
+ }
- text.ColonStyle = style;
- return text;
+ ///
+ /// Sets the style used for colons.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText ColonStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for commas.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText CommaStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.ColonStyle = style;
+ return text;
+ }
- text.CommaStyle = style;
- return text;
+ ///
+ /// Sets the style used for commas.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText CommaStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for string literals.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText StringStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.CommaStyle = style;
+ return text;
+ }
- text.StringStyle = style;
- return text;
+ ///
+ /// Sets the style used for string literals.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText StringStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for number literals.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText NumberStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.StringStyle = style;
+ return text;
+ }
- text.NumberStyle = style;
- return text;
+ ///
+ /// Sets the style used for number literals.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText NumberStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for boolean literals.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BooleanStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.NumberStyle = style;
+ return text;
+ }
- text.BooleanStyle = style;
- return text;
+ ///
+ /// Sets the style used for boolean literals.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BooleanStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the style used for null literals.
- ///
- /// The style to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText NullStyle(Style? style)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BooleanStyle = style;
+ return text;
+ }
- text.NullStyle = style;
- return text;
+ ///
+ /// Sets the style used for null literals.
+ ///
+ /// The JSON text instance.
+ /// The style to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText NullStyle(this JsonText text, Style? style)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for braces.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BracesColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.NullStyle = style;
+ return text;
+ }
- text.BracesStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for braces.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BracesColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for brackets.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BracketColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BracesStyle = new Style(color);
+ return text;
+ }
- text.BracketsStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for brackets.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BracketColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for member names.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText MemberColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BracketsStyle = new Style(color);
+ return text;
+ }
- text.MemberStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for member names.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText MemberColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for colons.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText ColonColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.MemberStyle = new Style(color);
+ return text;
+ }
- text.ColonStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for colons.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText ColonColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for commas.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText CommaColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.ColonStyle = new Style(color);
+ return text;
+ }
- text.CommaStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for commas.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText CommaColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for string literals.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText StringColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.CommaStyle = new Style(color);
+ return text;
+ }
- text.StringStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for string literals.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText StringColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for number literals.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText NumberColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.StringStyle = new Style(color);
+ return text;
+ }
- text.NumberStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for number literals.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText NumberColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for boolean literals.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText BooleanColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.NumberStyle = new Style(color);
+ return text;
+ }
- text.BooleanStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for boolean literals.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText BooleanColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
- ///
- /// Sets the color used for null literals.
- ///
- /// The color to set.
- /// The same instance so that multiple calls can be chained.
- public JsonText NullColor(Color color)
- {
- ArgumentNullException.ThrowIfNull(text);
+ text.BooleanStyle = new Style(color);
+ return text;
+ }
- text.NullStyle = new Style(color);
- return text;
+ ///
+ /// Sets the color used for null literals.
+ ///
+ /// The JSON text instance.
+ /// The color to set.
+ /// The same instance so that multiple calls can be chained.
+ public static JsonText NullColor(this JsonText text, Color color)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException(nameof(text));
}
+
+ text.NullStyle = new Style(color);
+ return text;
}
}
\ No newline at end of file
diff --git a/src/Extensions/Spectre.Console.Json/Properties/Usings.cs b/src/Extensions/Spectre.Console.Json/Properties/Usings.cs
index 22d00926..bd90d278 100644
--- a/src/Extensions/Spectre.Console.Json/Properties/Usings.cs
+++ b/src/Extensions/Spectre.Console.Json/Properties/Usings.cs
@@ -1,3 +1,4 @@
global using System.Text;
+global using Spectre.Console.Internal;
global using Spectre.Console.Json.Syntax;
global using Spectre.Console.Rendering;
\ No newline at end of file
diff --git a/src/Extensions/Spectre.Console.Json/Spectre.Console.Json.csproj b/src/Extensions/Spectre.Console.Json/Spectre.Console.Json.csproj
index cbf71ca5..13c4279f 100644
--- a/src/Extensions/Spectre.Console.Json/Spectre.Console.Json.csproj
+++ b/src/Extensions/Spectre.Console.Json/Spectre.Console.Json.csproj
@@ -11,20 +11,13 @@
true
-
- Internal\Polyfills.cs
-
-
-
+
+
-
-
-
-
diff --git a/src/Polyfills.cs b/src/Polyfills.cs
deleted file mode 100644
index 53adf145..00000000
--- a/src/Polyfills.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-#if NETSTANDARD
-namespace Spectre.Console;
-
-internal static class Polyfills
-{
- extension(CancellationTokenSource cts)
- {
- public Task CancelAsync()
- {
- cts.Cancel();
- return Task.CompletedTask;
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Spectre.Console.Testing/Extensions/ShouldlyExtensions.cs b/src/Spectre.Console.Testing/Extensions/ShouldlyExtensions.cs
index 4cb6cc52..4f1d8172 100644
--- a/src/Spectre.Console.Testing/Extensions/ShouldlyExtensions.cs
+++ b/src/Spectre.Console.Testing/Extensions/ShouldlyExtensions.cs
@@ -5,25 +5,25 @@ namespace Spectre.Console.Testing;
///
public static class ShouldlyExtensions
{
- /// The object to operate on.
+ ///
+ /// Performs the specified action on the given object and then returns the object.
+ /// Useful for fluent testing patterns where additional assertions or operations
+ /// are chained together in a readable manner.
+ ///
/// The type of the object.
- extension(T item)
+ /// The object to operate on.
+ /// An action to perform on the object.
+ /// The original object, to allow further chaining.
+ /// Thrown if is null.
+ [DebuggerStepThrough]
+ public static T And(this T item, Action action)
{
- ///
- /// Performs the specified action on the given object and then returns the object.
- /// Useful for fluent testing patterns where additional assertions or operations
- /// are chained together in a readable manner.
- ///
- /// An action to perform on the object.
- /// The original object, to allow further chaining.
- /// Thrown if is null.
- [DebuggerStepThrough]
- public T And(Action action)
+ if (action == null)
{
- ArgumentNullException.ThrowIfNull(action);
-
- action(item);
- return item;
+ throw new ArgumentNullException(nameof(action));
}
+
+ action(item);
+ return item;
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Testing/Extensions/StringExtensions.cs b/src/Spectre.Console.Testing/Extensions/StringExtensions.cs
index dc56063c..72c0cd86 100644
--- a/src/Spectre.Console.Testing/Extensions/StringExtensions.cs
+++ b/src/Spectre.Console.Testing/Extensions/StringExtensions.cs
@@ -5,42 +5,40 @@ namespace Spectre.Console.Testing;
///
public static class StringExtensions
{
+ ///
+ /// Returns a new string with all lines trimmed of trailing whitespace.
+ ///
/// The string to trim.
- extension(string value)
+ /// A new string with all lines trimmed of trailing whitespace.
+ public static string TrimLines(this string value)
{
- ///
- /// Returns a new string with all lines trimmed of trailing whitespace.
- ///
- /// A new string with all lines trimmed of trailing whitespace.
- public string TrimLines()
+ if (value is null)
{
- if (value is null)
- {
- return string.Empty;
- }
-
- var result = new List();
- foreach (var line in value.NormalizeLineEndings().Split(new[] { '\n' }))
- {
- result.Add(line.TrimEnd());
- }
-
- return string.Join("\n", result);
- }
-
- ///
- /// Returns a new string with normalized line endings.
- ///
- /// A new string with normalized line endings.
- public string NormalizeLineEndings()
- {
- if (value != null)
- {
- value = value.Replace("\r\n", "\n");
- return value.Replace("\r", string.Empty);
- }
-
return string.Empty;
}
+
+ var result = new List();
+ foreach (var line in value.NormalizeLineEndings().Split(new[] { '\n' }))
+ {
+ result.Add(line.TrimEnd());
+ }
+
+ return string.Join("\n", result);
+ }
+
+ ///
+ /// Returns a new string with normalized line endings.
+ ///
+ /// The string to normalize line endings for.
+ /// A new string with normalized line endings.
+ public static string NormalizeLineEndings(this string value)
+ {
+ if (value != null)
+ {
+ value = value.Replace("\r\n", "\n");
+ return value.Replace("\r", string.Empty);
+ }
+
+ return string.Empty;
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs b/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs
index 1405cc26..24168042 100644
--- a/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs
+++ b/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs
@@ -5,23 +5,20 @@ namespace Spectre.Console.Testing;
///
public static class StyleExtensions
{
+ ///
+ /// Sets the foreground or background color of the specified style.
+ ///
/// The style.
- extension(Style style)
+ /// The color.
+ /// Whether or not to set the foreground color.
+ /// The same instance so that multiple calls can be chained.
+ public static Style SetColor(this Style style, Color color, bool foreground)
{
- ///
- /// Sets the foreground or background color of the specified style.
- ///
- /// The color.
- /// Whether or not to set the foreground color.
- /// The same instance so that multiple calls can be chained.
- public Style SetColor(Color color, bool foreground)
+ if (foreground)
{
- if (foreground)
- {
- return style.Foreground(color);
- }
-
- return style.Background(color);
+ return style.Foreground(color);
}
+
+ return style.Background(color);
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Testing/Extensions/TestConsoleExtensions.cs b/src/Spectre.Console.Testing/Extensions/TestConsoleExtensions.cs
index 88692068..ffe6a8b1 100644
--- a/src/Spectre.Console.Testing/Extensions/TestConsoleExtensions.cs
+++ b/src/Spectre.Console.Testing/Extensions/TestConsoleExtensions.cs
@@ -5,84 +5,87 @@ namespace Spectre.Console.Testing;
///
public static partial class TestConsoleExtensions
{
+ ///
+ /// Sets the console's color system.
+ ///
/// The console.
- extension(TestConsole console)
+ /// The color system to use.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole Colors(this TestConsole console, ColorSystem colors)
{
- ///
- /// Sets the console's color system.
- ///
- /// The color system to use.
- /// The same instance so that multiple calls can be chained.
- public TestConsole Colors(ColorSystem colors)
- {
- console.Profile.Capabilities.ColorSystem = colors;
- return console;
- }
+ console.Profile.Capabilities.ColorSystem = colors;
+ return console;
+ }
- ///
- /// Sets whether or not ANSI is supported.
- ///
- /// Whether or not VT/ANSI control codes are supported.
- /// The same instance so that multiple calls can be chained.
- public TestConsole SupportsAnsi(bool enable)
- {
- console.Profile.Capabilities.Ansi = enable;
- return console;
- }
+ ///
+ /// Sets whether or not ANSI is supported.
+ ///
+ /// The console.
+ /// Whether or not VT/ANSI control codes are supported.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole SupportsAnsi(this TestConsole console, bool enable)
+ {
+ console.Profile.Capabilities.Ansi = enable;
+ return console;
+ }
- ///
- /// Makes the console interactive.
- ///
- /// The same instance so that multiple calls can be chained.
- public TestConsole Interactive()
- {
- console.Profile.Capabilities.Interactive = true;
- return console;
- }
+ ///
+ /// Makes the console interactive.
+ ///
+ /// The console.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole Interactive(this TestConsole console)
+ {
+ console.Profile.Capabilities.Interactive = true;
+ return console;
+ }
- ///
- /// Sets the console width.
- ///
- /// The console width.
- /// The same instance so that multiple calls can be chained.
- public TestConsole Width(int width)
- {
- console.Profile.Width = width;
- return console;
- }
+ ///
+ /// Sets the console width.
+ ///
+ /// The console.
+ /// The console width.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole Width(this TestConsole console, int width)
+ {
+ console.Profile.Width = width;
+ return console;
+ }
- ///
- /// Sets the console height.
- ///
- /// The console height.
- /// The same instance so that multiple calls can be chained.
- public TestConsole Height(int width)
- {
- console.Profile.Height = width;
- return console;
- }
+ ///
+ /// Sets the console height.
+ ///
+ /// The console.
+ /// The console height.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole Height(this TestConsole console, int width)
+ {
+ console.Profile.Height = width;
+ return console;
+ }
- ///
- /// Sets the console size.
- ///
- /// The console size.
- /// The same instance so that multiple calls can be chained.
- public TestConsole Size(Size size)
- {
- console.Profile.Width = size.Width;
- console.Profile.Height = size.Height;
- return console;
- }
+ ///
+ /// Sets the console size.
+ ///
+ /// The console.
+ /// The console size.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole Size(this TestConsole console, Size size)
+ {
+ console.Profile.Width = size.Width;
+ console.Profile.Height = size.Height;
+ return console;
+ }
- ///
- /// Turns on emitting of VT/ANSI sequences.
- ///
- /// The same instance so that multiple calls can be chained.
- public TestConsole EmitAnsiSequences()
- {
- console.SetCursor(null);
- console.EmitAnsiSequences = true;
- return console;
- }
+ ///
+ /// Turns on emitting of VT/ANSI sequences.
+ ///
+ /// The console.
+ /// The same instance so that multiple calls can be chained.
+ public static TestConsole EmitAnsiSequences(this TestConsole console)
+ {
+ console.SetCursor(null);
+ console.EmitAnsiSequences = true;
+ return console;
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj b/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj
index 2854dad0..367360f4 100644
--- a/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj
+++ b/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj
@@ -10,15 +10,5 @@
-
-
-
-
-
-
-
- Extensions\Polyfills.cs
-
-
diff --git a/src/Spectre.Console.Testing/TestCapabilities.cs b/src/Spectre.Console.Testing/TestCapabilities.cs
index 6d75f54d..d4f702b8 100644
--- a/src/Spectre.Console.Testing/TestCapabilities.cs
+++ b/src/Spectre.Console.Testing/TestCapabilities.cs
@@ -33,7 +33,10 @@ public sealed class TestCapabilities : IReadOnlyCapabilities
/// A with the same capabilities as this instace.
public RenderOptions CreateRenderContext(IAnsiConsole console)
{
- ArgumentNullException.ThrowIfNull(console);
+ if (console is null)
+ {
+ throw new ArgumentNullException(nameof(console));
+ }
return RenderOptions.Create(console, this);
}
diff --git a/src/Spectre.Console.Testing/TestConsoleInput.cs b/src/Spectre.Console.Testing/TestConsoleInput.cs
index 178f743d..e471d30e 100644
--- a/src/Spectre.Console.Testing/TestConsoleInput.cs
+++ b/src/Spectre.Console.Testing/TestConsoleInput.cs
@@ -21,7 +21,10 @@ public sealed class TestConsoleInput : IAnsiConsoleInput
/// The input string.
public void PushText(string input)
{
- ArgumentNullException.ThrowIfNull(input);
+ if (input is null)
+ {
+ throw new ArgumentNullException(nameof(input));
+ }
foreach (var character in input)
{
diff --git a/src/Spectre.Console.Tests/Extensions/ConsoleKeyExtensions.cs b/src/Spectre.Console.Tests/Extensions/ConsoleKeyExtensions.cs
index 735332c2..fee4ec22 100644
--- a/src/Spectre.Console.Tests/Extensions/ConsoleKeyExtensions.cs
+++ b/src/Spectre.Console.Tests/Extensions/ConsoleKeyExtensions.cs
@@ -2,17 +2,14 @@ namespace Spectre.Console.Tests;
public static class ConsoleKeyExtensions
{
- extension(ConsoleKey key)
+ public static ConsoleKeyInfo ToConsoleKeyInfo(this ConsoleKey key)
{
- public ConsoleKeyInfo ToConsoleKeyInfo()
+ var ch = (char)key;
+ if (char.IsControl(ch))
{
- var ch = (char)key;
- if (char.IsControl(ch))
- {
- ch = '\0';
- }
-
- return new ConsoleKeyInfo(ch, key, false, false, false);
+ ch = '\0';
}
+
+ return new ConsoleKeyInfo(ch, key, false, false, false);
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Tests/Extensions/StreamExtensions.cs b/src/Spectre.Console.Tests/Extensions/StreamExtensions.cs
index fd1527fc..0eed3b87 100644
--- a/src/Spectre.Console.Tests/Extensions/StreamExtensions.cs
+++ b/src/Spectre.Console.Tests/Extensions/StreamExtensions.cs
@@ -2,16 +2,16 @@ namespace Spectre.Console.Tests;
public static class StreamExtensions
{
- extension(Stream stream)
+ public static string ReadText(this Stream stream)
{
- public string ReadText()
+ if (stream is null)
{
- ArgumentNullException.ThrowIfNull(stream);
+ throw new ArgumentNullException(nameof(stream));
+ }
- using (var reader = new StreamReader(stream))
- {
- return reader.ReadToEnd();
- }
+ using (var reader = new StreamReader(stream))
+ {
+ return reader.ReadToEnd();
}
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console.Tests/Unit/BackwardsCompatibilityTests.cs b/src/Spectre.Console.Tests/Unit/BackwardsCompatibilityTests.cs
index 1e275cbc..093a0041 100644
--- a/src/Spectre.Console.Tests/Unit/BackwardsCompatibilityTests.cs
+++ b/src/Spectre.Console.Tests/Unit/BackwardsCompatibilityTests.cs
@@ -1,9 +1,3 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Shouldly;
-using Xunit;
-
namespace Spectre.Console.Tests.Unit;
///
diff --git a/src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs b/src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs
index 5400bafd..2b0163f0 100644
--- a/src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs
+++ b/src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs
@@ -1,3 +1,5 @@
+using Spectre.Console.Extensions;
+
namespace Spectre.Console.Tests.Unit;
[ExpectationPath("Widgets/Align")]
diff --git a/src/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs b/src/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs
index bb10c3c5..8d74d9e6 100644
--- a/src/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs
+++ b/src/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs
@@ -4,7 +4,10 @@ public static class EmbeddedResourceReader
{
public static Stream LoadResourceStream(string resourceName)
{
- ArgumentNullException.ThrowIfNull(resourceName);
+ if (resourceName is null)
+ {
+ throw new ArgumentNullException(nameof(resourceName));
+ }
var assembly = Assembly.GetCallingAssembly();
resourceName = resourceName.Replace("/", ".");
@@ -20,9 +23,15 @@ public static class EmbeddedResourceReader
public static Stream LoadResourceStream(Assembly assembly, string resourceName)
{
- ArgumentNullException.ThrowIfNull(assembly);
+ if (assembly is null)
+ {
+ throw new ArgumentNullException(nameof(assembly));
+ }
- ArgumentNullException.ThrowIfNull(resourceName);
+ if (resourceName is null)
+ {
+ throw new ArgumentNullException(nameof(resourceName));
+ }
resourceName = resourceName.Replace("/", ".");
var stream = assembly.GetManifestResourceStream(resourceName);
diff --git a/src/Spectre.Console.Tests/Utilities/TestConsoleExtensions.cs b/src/Spectre.Console.Tests/Utilities/TestConsoleExtensions.cs
index 777bcf41..9e020fa3 100644
--- a/src/Spectre.Console.Tests/Utilities/TestConsoleExtensions.cs
+++ b/src/Spectre.Console.Tests/Utilities/TestConsoleExtensions.cs
@@ -6,25 +6,22 @@ public static class TestConsoleExtensions
private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline);
private static readonly Regex _pathSeparatorRegex = new Regex(@"[/\\]+");
- extension(TestConsole console)
+ public static string WriteNormalizedException(this TestConsole console, Exception ex, ExceptionFormats formats = ExceptionFormats.Default)
{
- public string WriteNormalizedException(Exception ex, ExceptionFormats formats = ExceptionFormats.Default)
+ if (!string.IsNullOrWhiteSpace(console.Output))
{
- if (!string.IsNullOrWhiteSpace(console.Output))
- {
- throw new InvalidOperationException("Output buffer is not empty.");
- }
-
- console.WriteException(ex, formats);
-
- return string.Join("\n", NormalizeStackTrace(console.Output)
- .NormalizeLineEndings()
- .Split(['\n'])
- .Select(line => line.TrimEnd()));
+ throw new InvalidOperationException("Output buffer is not empty.");
}
+
+ console.WriteException(ex, formats);
+
+ return string.Join("\n", NormalizeStackTrace(console.Output)
+ .NormalizeLineEndings()
+ .Split(['\n'])
+ .Select(line => line.TrimEnd()));
}
- private static string NormalizeStackTrace(string text)
+ public static string NormalizeStackTrace(string text)
{
// First normalize line numbers
text = _lineNumberRegex.Replace(text, ":nn");
diff --git a/src/Spectre.Console/AnsiConsole.Exceptions.cs b/src/Spectre.Console/AnsiConsole.Exceptions.cs
new file mode 100644
index 00000000..de3a4733
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Exceptions.cs
@@ -0,0 +1,29 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Writes an exception to the console.
+ ///
+ /// The exception to write to the console.
+ /// The exception format options.
+ [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
+ public static void WriteException(Exception exception, ExceptionFormats format = ExceptionFormats.Default)
+ {
+ Console.WriteException(exception, format);
+ }
+
+ ///
+ /// Writes an exception to the console.
+ ///
+ /// The exception to write to the console.
+ /// The exception settings.
+ [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
+ public static void WriteException(Exception exception, ExceptionSettings settings)
+ {
+ Console.WriteException(exception, settings);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Live.cs b/src/Spectre.Console/AnsiConsole.Live.cs
new file mode 100644
index 00000000..3d3e4b8f
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Live.cs
@@ -0,0 +1,17 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Creates a new instance.
+ ///
+ /// The target renderable to update.
+ /// A instance.
+ public static LiveDisplay Live(IRenderable target)
+ {
+ return Console.Live(target);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Markup.cs b/src/Spectre.Console/AnsiConsole.Markup.cs
new file mode 100644
index 00000000..b9d47f09
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Markup.cs
@@ -0,0 +1,141 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// The value to write.
+ public static void Markup(string value)
+ {
+ Console.Markup(value);
+ }
+
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void Markup(string format, params object[] args)
+ {
+ Console.Markup(format, args);
+ }
+
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// All interpolation holes which contain a string are automatically escaped so you must not call .
+ ///
+ ///
+ ///
+ /// string input = args[0];
+ /// string output = Process(input);
+ /// AnsiConsole.MarkupInterpolated($"[blue]{input}[/] -> [green]{output}[/]");
+ ///
+ ///
+ /// The interpolated string value to write.
+ public static void MarkupInterpolated(FormattableString value)
+ {
+ Console.MarkupInterpolated(value);
+ }
+
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void Markup(IFormatProvider provider, string format, params object[] args)
+ {
+ Console.Markup(provider, format, args);
+ }
+
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// All interpolation holes which contain a string are automatically escaped so you must not call .
+ ///
+ ///
+ ///
+ /// string input = args[0];
+ /// string output = Process(input);
+ /// AnsiConsole.MarkupInterpolated(CultureInfo.InvariantCulture, $"[blue]{input}[/] -> [green]{output}[/]");
+ ///
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The interpolated string value to write.
+ public static void MarkupInterpolated(IFormatProvider provider, FormattableString value)
+ {
+ Console.MarkupInterpolated(provider, value);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void MarkupLine(string value)
+ {
+ Console.MarkupLine(value);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void MarkupLine(string format, params object[] args)
+ {
+ Console.MarkupLine(format, args);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// All interpolation holes which contain a string are automatically escaped so you must not call .
+ ///
+ ///
+ ///
+ /// string input = args[0];
+ /// string output = Process(input);
+ /// AnsiConsole.MarkupLineInterpolated($"[blue]{input}[/] -> [green]{output}[/]");
+ ///
+ ///
+ /// The interpolated string value to write.
+ public static void MarkupLineInterpolated(FormattableString value)
+ {
+ Console.MarkupLineInterpolated(value);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void MarkupLine(IFormatProvider provider, string format, params object[] args)
+ {
+ Console.MarkupLine(provider, format, args);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// All interpolation holes which contain a string are automatically escaped so you must not call .
+ ///
+ ///
+ ///
+ /// string input = args[0];
+ /// string output = Process(input);
+ /// AnsiConsole.MarkupLineInterpolated(CultureInfo.InvariantCulture, $"[blue]{input}[/] -> [green]{output}[/]");
+ ///
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The interpolated string value to write.
+ public static void MarkupLineInterpolated(IFormatProvider provider, FormattableString value)
+ {
+ Console.MarkupLineInterpolated(provider, value);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Progress.cs b/src/Spectre.Console/AnsiConsole.Progress.cs
new file mode 100644
index 00000000..144c923b
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Progress.cs
@@ -0,0 +1,25 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Creates a new instance.
+ ///
+ /// A instance.
+ public static Progress Progress()
+ {
+ return Console.Progress();
+ }
+
+ ///
+ /// Creates a new instance.
+ ///
+ /// A instance.
+ public static Status Status()
+ {
+ return Console.Status();
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Prompt.cs b/src/Spectre.Console/AnsiConsole.Prompt.cs
new file mode 100644
index 00000000..d51577c6
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Prompt.cs
@@ -0,0 +1,123 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Displays a prompt to the user.
+ ///
+ /// The prompt result type.
+ /// The prompt to display.
+ /// The prompt input result.
+ public static T Prompt(IPrompt prompt)
+ {
+ if (prompt is null)
+ {
+ throw new ArgumentNullException(nameof(prompt));
+ }
+
+ return prompt.Show(Console);
+ }
+
+ ///
+ /// Displays a prompt to the user.
+ ///
+ /// The prompt result type.
+ /// The prompt to display.
+ /// The token to monitor for cancellation requests.
+ /// The prompt input result.
+ public static Task PromptAsync(IPrompt prompt, CancellationToken cancellationToken = default)
+ {
+ if (prompt is null)
+ {
+ throw new ArgumentNullException(nameof(prompt));
+ }
+
+ return prompt.ShowAsync(Console, cancellationToken);
+ }
+
+ ///
+ /// Displays a prompt to the user.
+ ///
+ /// The prompt result type.
+ /// The prompt markup text.
+ /// The prompt input result.
+ public static T Ask(string prompt)
+ {
+ return new TextPrompt(prompt).Show(Console);
+ }
+
+ ///
+ /// Displays a prompt to the user.
+ ///
+ /// The prompt result type.
+ /// The prompt markup text.
+ /// The token to monitor for cancellation requests.
+ /// The prompt input result.
+ public static Task AskAsync(string prompt, CancellationToken cancellationToken = default)
+ {
+ return new TextPrompt(prompt).ShowAsync(Console, cancellationToken);
+ }
+
+ ///
+ /// Displays a prompt to the user with a given default.
+ ///
+ /// The prompt result type.
+ /// The prompt markup text.
+ /// The default value.
+ /// The prompt input result.
+ public static T Ask(string prompt, T defaultValue)
+ {
+ return new TextPrompt(prompt)
+ .DefaultValue(defaultValue)
+ .Show(Console);
+ }
+
+ ///
+ /// Displays a prompt to the user with a given default.
+ ///
+ /// The prompt result type.
+ /// The prompt markup text.
+ /// The default value.
+ /// The token to monitor for cancellation requests.
+ /// The prompt input result.
+ public static Task AskAsync(string prompt, T defaultValue, CancellationToken cancellationToken = default)
+ {
+ return new TextPrompt(prompt)
+ .DefaultValue(defaultValue)
+ .ShowAsync(Console, cancellationToken);
+ }
+
+ ///
+ /// Displays a prompt with two choices, yes or no.
+ ///
+ /// The prompt markup text.
+ /// Specifies the default answer.
+ /// true if the user selected "yes", otherwise false.
+ public static bool Confirm(string prompt, bool defaultValue = true)
+ {
+ return new ConfirmationPrompt(prompt)
+ {
+ DefaultValue = defaultValue,
+ }
+ .Show(Console);
+ }
+
+ ///
+ /// Displays a prompt with two choices, yes or no.
+ ///
+ /// The prompt markup text.
+ /// Specifies the default answer.
+ /// The token to monitor for cancellation requests.
+ /// true if the user selected "yes", otherwise false.
+ public static Task ConfirmAsync(string prompt, bool defaultValue = true, CancellationToken cancellationToken = default)
+ {
+ return new ConfirmationPrompt(prompt)
+ {
+ DefaultValue = defaultValue,
+ }
+ .ShowAsync(Console, cancellationToken);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Recording.cs b/src/Spectre.Console/AnsiConsole.Recording.cs
new file mode 100644
index 00000000..a398a374
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Recording.cs
@@ -0,0 +1,66 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Starts recording the console output.
+ ///
+ public static void Record()
+ {
+ if (_recorder == null)
+ {
+ _recorder = new Recorder(Console);
+ }
+ }
+
+ ///
+ /// Exports all recorded console output as text.
+ ///
+ /// The recorded output as text.
+ public static string ExportText()
+ {
+ if (_recorder == null)
+ {
+ throw new InvalidOperationException("Cannot export text since a recording hasn't been started.");
+ }
+
+ return _recorder.ExportText();
+ }
+
+ ///
+ /// Exports all recorded console output as HTML text.
+ ///
+ /// The recorded output as HTML text.
+ public static string ExportHtml()
+ {
+ if (_recorder == null)
+ {
+ throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
+ }
+
+ return _recorder.ExportHtml();
+ }
+
+ ///
+ /// Exports all recorded console output using a custom encoder.
+ ///
+ /// The encoder to use.
+ /// The recorded output.
+ public static string ExportCustom(IAnsiConsoleEncoder encoder)
+ {
+ if (_recorder == null)
+ {
+ throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
+ }
+
+ if (encoder is null)
+ {
+ throw new ArgumentNullException(nameof(encoder));
+ }
+
+ return _recorder.Export(encoder);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Rendering.cs b/src/Spectre.Console/AnsiConsole.Rendering.cs
new file mode 100644
index 00000000..ca56a900
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Rendering.cs
@@ -0,0 +1,31 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Renders the specified object to the console.
+ ///
+ /// The object to render.
+ [Obsolete("Consider using AnsiConsole.Write instead.")]
+ public static void Render(IRenderable renderable)
+ {
+ Write(renderable);
+ }
+
+ ///
+ /// Renders the specified to the console.
+ ///
+ /// The object to render.
+ public static void Write(IRenderable renderable)
+ {
+ if (renderable is null)
+ {
+ throw new ArgumentNullException(nameof(renderable));
+ }
+
+ Console.Write(renderable);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Screen.cs b/src/Spectre.Console/AnsiConsole.Screen.cs
new file mode 100644
index 00000000..f89fd594
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Screen.cs
@@ -0,0 +1,16 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Switches to an alternate screen buffer if the terminal supports it.
+ ///
+ /// The action to execute within the alternate screen buffer.
+ public static void AlternateScreen(Action action)
+ {
+ Console.AlternateScreen(action);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.State.cs b/src/Spectre.Console/AnsiConsole.State.cs
new file mode 100644
index 00000000..ca6e209e
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.State.cs
@@ -0,0 +1,62 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ internal static Style CurrentStyle { get; private set; } = Style.Plain;
+ internal static bool Created { get; private set; }
+
+ ///
+ /// Gets or sets the foreground color.
+ ///
+ public static Color Foreground
+ {
+ get => CurrentStyle.Foreground;
+ set => CurrentStyle = CurrentStyle.Foreground(value);
+ }
+
+ ///
+ /// Gets or sets the background color.
+ ///
+ public static Color Background
+ {
+ get => CurrentStyle.Background;
+ set => CurrentStyle = CurrentStyle.Background(value);
+ }
+
+ ///
+ /// Gets or sets the text decoration.
+ ///
+ public static Decoration Decoration
+ {
+ get => CurrentStyle.Decoration;
+ set => CurrentStyle = CurrentStyle.Decoration(value);
+ }
+
+ ///
+ /// Resets colors and text decorations.
+ ///
+ public static void Reset()
+ {
+ ResetColors();
+ ResetDecoration();
+ }
+
+ ///
+ /// Resets the current applied text decorations.
+ ///
+ public static void ResetDecoration()
+ {
+ Decoration = Decoration.None;
+ }
+
+ ///
+ /// Resets the current applied foreground and background colors.
+ ///
+ public static void ResetColors()
+ {
+ CurrentStyle = Style.Plain;
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.Write.cs b/src/Spectre.Console/AnsiConsole.Write.cs
new file mode 100644
index 00000000..8d40819a
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.Write.cs
@@ -0,0 +1,249 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Writes the specified string value to the console.
+ ///
+ /// The value to write.
+ public static void Write(string value)
+ {
+ Write(value, CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit
+ /// signed integer value to the console.
+ ///
+ /// The value to write.
+ public static void Write(int value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit
+ /// signed integer value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, int value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit
+ /// unsigned integer value to the console.
+ ///
+ /// The value to write.
+ public static void Write(uint value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit
+ /// unsigned integer value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, uint value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit
+ /// signed integer value to the console.
+ ///
+ /// The value to write.
+ public static void Write(long value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit
+ /// signed integer value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, long value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit
+ /// unsigned integer value to the console.
+ ///
+ /// The value to write.
+ public static void Write(ulong value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit
+ /// unsigned integer value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, ulong value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified single-precision
+ /// floating-point value to the console.
+ ///
+ /// The value to write.
+ public static void Write(float value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified single-precision
+ /// floating-point value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, float value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified double-precision
+ /// floating-point value to the console.
+ ///
+ /// The value to write.
+ public static void Write(double value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified double-precision
+ /// floating-point value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, double value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified decimal value, to the console.
+ ///
+ /// The value to write.
+ public static void Write(decimal value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified decimal value, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, decimal value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified boolean value to the console.
+ ///
+ /// The value to write.
+ public static void Write(bool value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified boolean value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, bool value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the specified Unicode character to the console.
+ ///
+ /// The value to write.
+ public static void Write(char value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the specified Unicode character to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, char value)
+ {
+ Console.Write(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the specified array of Unicode characters to the console.
+ ///
+ /// The value to write.
+ public static void Write(char[] value)
+ {
+ Write(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the specified array of Unicode characters to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void Write(IFormatProvider provider, char[] value)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+
+ for (var index = 0; index < value.Length; index++)
+ {
+ Console.Write(value[index].ToString(provider), CurrentStyle);
+ }
+ }
+
+ ///
+ /// Writes the text representation of the specified array of objects,
+ /// to the console using the specified format information.
+ ///
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void Write(string format, params object[] args)
+ {
+ Write(CultureInfo.CurrentCulture, format, args);
+ }
+
+ ///
+ /// Writes the text representation of the specified array of objects,
+ /// to the console using the specified format information.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void Write(IFormatProvider provider, string format, params object[] args)
+ {
+ Console.Write(string.Format(provider, format, args), CurrentStyle);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.WriteLine.cs b/src/Spectre.Console/AnsiConsole.WriteLine.cs
new file mode 100644
index 00000000..57ba6b77
--- /dev/null
+++ b/src/Spectre.Console/AnsiConsole.WriteLine.cs
@@ -0,0 +1,269 @@
+namespace Spectre.Console;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static partial class AnsiConsole
+{
+ ///
+ /// Writes an empty line to the console.
+ ///
+ public static void WriteLine()
+ {
+ Console.WriteLine();
+ }
+
+ ///
+ /// Writes the specified string value, followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(string value)
+ {
+ Console.WriteLine(value, CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit signed integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(int value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit signed integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, int value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit unsigned integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(uint value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 32-bit unsigned integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, uint value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit signed integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(long value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit signed integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, long value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit unsigned integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(ulong value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified 64-bit unsigned integer value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, ulong value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified single-precision floating-point
+ /// value, followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(float value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified single-precision floating-point
+ /// value, followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, float value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified double-precision floating-point
+ /// value, followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(double value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified double-precision floating-point
+ /// value, followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, double value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified decimal value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(decimal value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified decimal value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, decimal value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the text representation of the specified boolean value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(bool value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the text representation of the specified boolean value,
+ /// followed by the current line terminator, to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, bool value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the specified Unicode character, followed by the current
+ /// line terminator, value to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(char value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the specified Unicode character, followed by the current
+ /// line terminator, value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, char value)
+ {
+ Console.WriteLine(value.ToString(provider), CurrentStyle);
+ }
+
+ ///
+ /// Writes the specified array of Unicode characters, followed by the current
+ /// line terminator, value to the console.
+ ///
+ /// The value to write.
+ public static void WriteLine(char[] value)
+ {
+ WriteLine(CultureInfo.CurrentCulture, value);
+ }
+
+ ///
+ /// Writes the specified array of Unicode characters, followed by the current
+ /// line terminator, value to the console.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// The value to write.
+ public static void WriteLine(IFormatProvider provider, char[] value)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+
+ for (var index = 0; index < value.Length; index++)
+ {
+ Console.Write(value[index].ToString(provider), CurrentStyle);
+ }
+
+ Console.WriteLine();
+ }
+
+ ///
+ /// Writes the text representation of the specified array of objects,
+ /// followed by the current line terminator, to the console
+ /// using the specified format information.
+ ///
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void WriteLine(string format, params object[] args)
+ {
+ WriteLine(CultureInfo.CurrentCulture, format, args);
+ }
+
+ ///
+ /// Writes the text representation of the specified array of objects,
+ /// followed by the current line terminator, to the console
+ /// using the specified format information.
+ ///
+ /// An object that supplies culture-specific formatting information.
+ /// A composite format string.
+ /// An array of objects to write.
+ public static void WriteLine(IFormatProvider provider, string format, params object[] args)
+ {
+ Console.WriteLine(string.Format(provider, format, args), CurrentStyle);
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsole.cs b/src/Spectre.Console/AnsiConsole.cs
index 929d8c49..090434de 100644
--- a/src/Spectre.Console/AnsiConsole.cs
+++ b/src/Spectre.Console/AnsiConsole.cs
@@ -9,11 +9,7 @@ public static partial class AnsiConsole
private static readonly AnsiConsoleFactory _factory = new AnsiConsoleFactory();
#pragma warning restore CS0618
- internal static Style CurrentStyle { get; set; } = Style.Plain;
- internal static Recorder? Recorder { get; set; }
-
- internal static bool Created { get; private set; }
-
+ private static Recorder? _recorder;
private static Lazy _console = new Lazy(
() =>
{
@@ -35,12 +31,18 @@ public static partial class AnsiConsole
{
get
{
- return Recorder ?? _console.Value;
+ return _recorder ?? _console.Value;
}
set
{
_console = new Lazy(() => value);
- Recorder = Recorder?.Clone(value); // Recreate the recorder
+
+ if (_recorder != null)
+ {
+ // Recreate the recorder
+ _recorder = _recorder.Clone(value);
+ }
+
Created = true;
}
}
@@ -48,7 +50,7 @@ public static partial class AnsiConsole
///
/// Gets the .
///
- public static IAnsiConsoleCursor Cursor => Recorder?.Cursor ?? _console.Value.Cursor;
+ public static IAnsiConsoleCursor Cursor => _recorder?.Cursor ?? _console.Value.Cursor;
///
/// Gets the console profile.
@@ -65,99 +67,12 @@ public static partial class AnsiConsole
{
return _factory.Create(settings);
}
-}
-
-// TODO: This is here temporary due to a bug in the .NET SDK
-// See issue: https://github.com/dotnet/roslyn/issues/80024
-public static partial class AnsiConsole
-{
- ///
- /// Writes the text representation of the specified array of objects,
- /// to the console using the specified format information.
- ///
- /// A composite format string.
- /// An array of objects to write.
- public static void Write(string format, params object[] args)
- {
- Write(CultureInfo.CurrentCulture, format, args);
- }
///
- /// Writes the text representation of the specified array of objects,
- /// to the console using the specified format information.
+ /// Clears the console.
///
- /// An object that supplies culture-specific formatting information.
- /// A composite format string.
- /// An array of objects to write.
- public static void Write(IFormatProvider provider, string format, params object[] args)
+ public static void Clear()
{
- Console.Write(string.Format(provider, format, args), CurrentStyle);
- }
-
- ///
- /// Writes the text representation of the specified array of objects,
- /// followed by the current line terminator, to the console
- /// using the specified format information.
- ///
- /// A composite format string.
- /// An array of objects to write.
- public static void WriteLine(string format, params object[] args)
- {
- WriteLine(CultureInfo.CurrentCulture, format, args);
- }
-
- ///
- /// Writes the text representation of the specified array of objects,
- /// followed by the current line terminator, to the console
- /// using the specified format information.
- ///
- /// An object that supplies culture-specific formatting information.
- /// A composite format string.
- /// An array of objects to write.
- public static void WriteLine(IFormatProvider provider, string format, params object[] args)
- {
- Console.WriteLine(string.Format(provider, format, args), CurrentStyle);
- }
-
- ///
- /// Writes the specified markup to the console.
- ///
- /// A composite format string.
- /// An array of objects to write.
- public static void Markup(string format, params object[] args)
- {
- Console.Markup(format, args);
- }
-
- ///
- /// Writes the specified markup to the console.
- ///
- /// An object that supplies culture-specific formatting information.
- /// A composite format string.
- /// An array of objects to write.
- public static void Markup(IFormatProvider provider, string format, params object[] args)
- {
- Console.Markup(provider, format, args);
- }
-
- ///
- /// Writes the specified markup, followed by the current line terminator, to the console.
- ///
- /// A composite format string.
- /// An array of objects to write.
- public static void MarkupLine(string format, params object[] args)
- {
- Console.MarkupLine(format, args);
- }
-
- ///
- /// Writes the specified markup, followed by the current line terminator, to the console.
- ///
- /// An object that supplies culture-specific formatting information.
- /// A composite format string.
- /// An array of objects to write.
- public static void MarkupLine(IFormatProvider provider, string format, params object[] args)
- {
- Console.MarkupLine(provider, format, args);
+ Console.Clear();
}
}
\ No newline at end of file
diff --git a/src/Spectre.Console/AnsiConsoleFactory.cs b/src/Spectre.Console/AnsiConsoleFactory.cs
index 266a84ea..b4406b3e 100644
--- a/src/Spectre.Console/AnsiConsoleFactory.cs
+++ b/src/Spectre.Console/AnsiConsoleFactory.cs
@@ -13,7 +13,10 @@ public sealed class AnsiConsoleFactory
/// An implementation of .
public IAnsiConsole Create(AnsiConsoleSettings settings)
{
- ArgumentNullException.ThrowIfNull(settings);
+ if (settings is null)
+ {
+ throw new ArgumentNullException(nameof(settings));
+ }
var output = settings.Out ?? new AnsiConsoleOutput(System.Console.Out);
if (output.Writer == null)
diff --git a/src/Spectre.Console/BoxBorder.cs b/src/Spectre.Console/BoxBorder.cs
index 50960548..e30d5f31 100644
--- a/src/Spectre.Console/BoxBorder.cs
+++ b/src/Spectre.Console/BoxBorder.cs
@@ -16,31 +16,4 @@ public abstract partial class BoxBorder
/// The part to get the character representation for.
/// A character representation of the specified border part.
public abstract string GetPart(BoxBorderPart part);
-}
-
-///
-/// Contains extension methods for .
-///
-public static class BoxExtensions
-{
- /// The border to get the safe border for.
- extension(BoxBorder border)
- {
- ///
- /// Gets the safe border for a border.
- ///
- /// Whether or not to return the safe border.
- /// The safe border if one exist, otherwise the original border.
- public BoxBorder GetSafeBorder(bool safe)
- {
- ArgumentNullException.ThrowIfNull(border);
-
- if (safe && border.SafeBorder != null)
- {
- border = border.SafeBorder;
- }
-
- return border;
- }
- }
}
\ No newline at end of file
diff --git a/src/Spectre.Console/Color.cs b/src/Spectre.Console/Color.cs
index 9934ec63..9c87d62f 100644
--- a/src/Spectre.Console/Color.cs
+++ b/src/Spectre.Console/Color.cs
@@ -220,7 +220,10 @@ public partial struct Color : IEquatable
/// The color created from the hexadecimal string.
public static Color FromHex(string hex)
{
- ArgumentNullException.ThrowIfNull(hex);
+ if (hex is null)
+ {
+ throw new ArgumentNullException(nameof(hex));
+ }
if (hex.StartsWith("#"))
{
diff --git a/src/Spectre.Console/Emoji.cs b/src/Spectre.Console/Emoji.cs
index 95273e11..aaea7467 100644
--- a/src/Spectre.Console/Emoji.cs
+++ b/src/Spectre.Console/Emoji.cs
@@ -19,9 +19,15 @@ public static partial class Emoji
/// The emoji.
public static void Remap(string tag, string emoji)
{
- ArgumentNullException.ThrowIfNull(tag);
+ if (tag is null)
+ {
+ throw new ArgumentNullException(nameof(tag));
+ }
- ArgumentNullException.ThrowIfNull(emoji);
+ if (emoji is null)
+ {
+ throw new ArgumentNullException(nameof(emoji));
+ }
tag = tag.TrimStart(':').TrimEnd(':');
emoji = emoji.TrimStart(':').TrimEnd(':');
@@ -106,4 +112,16 @@ public static partial class Emoji
value = string.Empty;
return false;
}
+
+ private static int IndexOf(this ReadOnlySpan span, char value, int startIndex)
+ {
+ var indexInSlice = span.Slice(startIndex).IndexOf(value);
+
+ if (indexInSlice == -1)
+ {
+ return -1;
+ }
+
+ return startIndex + indexInSlice;
+ }
}
\ No newline at end of file
diff --git a/src/Spectre.Console/Enrichment/ProfileEnricher.cs b/src/Spectre.Console/Enrichment/ProfileEnricher.cs
index 4632d781..7ae68f34 100644
--- a/src/Spectre.Console/Enrichment/ProfileEnricher.cs
+++ b/src/Spectre.Console/Enrichment/ProfileEnricher.cs
@@ -25,7 +25,10 @@ internal static class ProfileEnricher
ProfileEnrichment settings,
IDictionary? environmentVariables)
{
- ArgumentNullException.ThrowIfNull(profile);
+ if (profile is null)
+ {
+ throw new ArgumentNullException(nameof(profile));
+ }
settings ??= new ProfileEnrichment();
diff --git a/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs b/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs
index 253b9ea5..5df87d48 100644
--- a/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs
+++ b/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs
@@ -3,36 +3,34 @@ namespace Spectre.Console.Advanced;
///
/// Contains extension methods for .
///
-[Obsolete("Use methods on IAnsiConsole instead")]
public static class AnsiConsoleExtensions
{
+ ///
+ /// Writes a VT/Ansi control code sequence to the console (if supported).
+ ///
/// The console to write to.
- extension(IAnsiConsole console)
+ /// The VT/Ansi control code sequence to write.
+ public static void WriteAnsi(this IAnsiConsole console, string sequence)
{
- ///
- /// Writes a VT/Ansi control code sequence to the console (if supported).
- ///
- /// The VT/Ansi control code sequence to write.
- [Obsolete("Use Spectre.Console.IAnsiConsole.WriteAnsi instead")]
- public void WriteAnsi(string sequence)
+ if (console is null)
{
- ArgumentNullException.ThrowIfNull(console);
-
- if (console.Profile.Capabilities.Ansi)
- {
- console.Write(new ControlCode(sequence));
- }
+ throw new ArgumentNullException(nameof(console));
}
- ///
- /// Gets the VT/ANSI control code sequence for a .
- ///
- /// The renderable to the VT/ANSI control code sequence for.
- /// The VT/ANSI control code sequence.
- [Obsolete("Use Spectre.Console.IAnsiConsole.ToAnsi instead")]
- public string ToAnsi(IRenderable renderable)
+ if (console.Profile.Capabilities.Ansi)
{
- return AnsiBuilder.Build(console, renderable);
+ console.Write(new ControlCode(sequence));
}
}
+
+ ///
+ /// Gets the VT/ANSI control code sequence for a .
+ ///
+ /// The console.
+ /// The renderable to the VT/ANSI control code sequence for.
+ /// The VT/ANSI control code sequence.
+ public static string ToAnsi(this IAnsiConsole console, IRenderable renderable)
+ {
+ return AnsiBuilder.Build(console, renderable);
+ }
}
\ No newline at end of file
diff --git a/src/Spectre.Console/Extensions/AlignExtensions.cs b/src/Spectre.Console/Extensions/AlignExtensions.cs
new file mode 100644
index 00000000..ad0413b7
--- /dev/null
+++ b/src/Spectre.Console/Extensions/AlignExtensions.cs
@@ -0,0 +1,106 @@
+namespace Spectre.Console.Extensions;
+
+///
+/// Contains extension methods for .
+///
+public static class AlignExtensions
+{
+ ///
+ /// Sets the width.
+ ///
+ /// The object.
+ /// The width, or null for no explicit width.
+ /// The same instance so that multiple calls can be chained.
+ public static Align Width(this Align align, int? width)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Width = width;
+ return align;
+ }
+
+ ///
+ /// Sets the height.
+ ///
+ /// The object.
+ /// The height, or null for no explicit height.
+ /// The same instance so that multiple calls can be chained.
+ public static Align Height(this Align align, int? height)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Height = height;
+ return align;
+ }
+
+ ///
+ /// Sets the vertical alignment.
+ ///
+ /// The object.
+ /// The vertical alignment, or null for no vertical alignment.
+ /// The same instance so that multiple calls can be chained.
+ public static Align VerticalAlignment(this Align align, VerticalAlignment? vertical)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Vertical = vertical;
+ return align;
+ }
+
+ ///
+ /// Sets the object to be top aligned.
+ ///
+ /// The object.
+ /// The same instance so that multiple calls can be chained.
+ public static Align TopAligned(this Align align)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Vertical = Console.VerticalAlignment.Top;
+ return align;
+ }
+
+ ///
+ /// Sets the object to be middle aligned.
+ ///
+ /// The object.
+ /// The same instance so that multiple calls can be chained.
+ public static Align MiddleAligned(this Align align)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Vertical = Console.VerticalAlignment.Middle;
+ return align;
+ }
+
+ ///
+ /// Sets the object to be bottom aligned.
+ ///
+ /// The object.
+ /// The same instance so that multiple calls can be chained.
+ public static Align BottomAligned(this Align align)
+ {
+ if (align is null)
+ {
+ throw new ArgumentNullException(nameof(align));
+ }
+
+ align.Vertical = Console.VerticalAlignment.Bottom;
+ return align;
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/Extensions/AlignableExtensions.cs b/src/Spectre.Console/Extensions/AlignableExtensions.cs
new file mode 100644
index 00000000..4efc934a
--- /dev/null
+++ b/src/Spectre.Console/Extensions/AlignableExtensions.cs
@@ -0,0 +1,80 @@
+namespace Spectre.Console;
+
+///
+/// Contains extension methods for .
+///
+public static class AlignableExtensions
+{
+ ///
+ /// Sets the alignment for an object.
+ ///
+ /// The alignable object type.
+ /// The alignable object.
+ /// The alignment.
+ /// The same instance so that multiple calls can be chained.
+ public static T Alignment(this T obj, Justify? alignment)
+ where T : class, IAlignable
+ {
+ if (obj is null)
+ {
+ throw new System.ArgumentNullException(nameof(obj));
+ }
+
+ obj.Alignment = alignment;
+ return obj;
+ }
+
+ ///
+ /// Sets the object to be left aligned.
+ ///
+ /// The alignable type.
+ /// The alignable object.
+ /// The same instance so that multiple calls can be chained.
+ public static T LeftAligned(this T obj)
+ where T : class, IAlignable
+ {
+ if (obj is null)
+ {
+ throw new System.ArgumentNullException(nameof(obj));
+ }
+
+ obj.Alignment = Justify.Left;
+ return obj;
+ }
+
+ ///
+ /// Sets the object to be centered.
+ ///
+ /// The alignable type.
+ /// The alignable object.
+ /// The same instance so that multiple calls can be chained.
+ public static T Centered(this T obj)
+ where T : class, IAlignable
+ {
+ if (obj is null)
+ {
+ throw new System.ArgumentNullException(nameof(obj));
+ }
+
+ obj.Alignment = Justify.Center;
+ return obj;
+ }
+
+ ///
+ /// Sets the object to be right aligned.
+ ///
+ /// The alignable type.
+ /// The alignable object.
+ /// The same instance so that multiple calls can be chained.
+ public static T RightAligned(this T obj)
+ where T : class, IAlignable
+ {
+ if (obj is null)
+ {
+ throw new System.ArgumentNullException(nameof(obj));
+ }
+
+ obj.Alignment = Justify.Right;
+ return obj;
+ }
+}
\ No newline at end of file
diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Ansi.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Ansi.cs
deleted file mode 100644
index 44a74ce1..00000000
--- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Ansi.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-namespace Spectre.Console;
-
-public static partial class AnsiConsoleExtensions
-{
- extension(AnsiConsole)
- {
- ///
- /// Writes a VT/Ansi control code sequence to the console (if supported).
- ///
- /// The VT/Ansi control code sequence to write.
- public static void WriteAnsi(string sequence)
- {
- AnsiConsole.Console.WriteAnsi(sequence);
- }
-
- ///
- /// Gets the VT/ANSI control code sequence for a .
- ///
- /// The renderable to the VT/ANSI control code sequence for.
- /// The VT/ANSI control code sequence.
- public static string ToAnsi(IRenderable renderable)
- {
- return AnsiConsole.Console.ToAnsi(renderable);
- }
- }
-
- extension(IAnsiConsole console)
- {
- ///
- /// Writes a VT/Ansi control code sequence to the console (if supported).
- ///
- /// The VT/Ansi control code sequence to write.
- public void WriteAnsi(string sequence)
- {
- ArgumentNullException.ThrowIfNull(console);
-
- if (console.Profile.Capabilities.Ansi)
- {
- console.Write(new ControlCode(sequence));
- }
- }
-
- ///
- /// Gets the VT/ANSI control code sequence for a .
- ///
- /// The renderable to the VT/ANSI control code sequence for.
- /// The VT/ANSI control code sequence.
- public string ToAnsi(IRenderable renderable)
- {
- return AnsiBuilder.Build(console, renderable);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Async.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Async.cs
new file mode 100644
index 00000000..34504880
--- /dev/null
+++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Async.cs
@@ -0,0 +1,92 @@
+namespace Spectre.Console.Extensions;
+
+///
+/// Provides extension methods for running tasks with a spinner animation.
+///
+public static class SpinnerExtensions
+{
+ ///
+ /// Runs a task with a spinner animation.
+ ///
+ /// The task to run.
+ /// The spinner to use.
+ /// The style to apply to the spinner.
+ /// The console to write to.
+ /// The result of the task.
+ public static async Task Spinner(this Task task, Spinner? spinner = null, Style? style = null, IAnsiConsole? ansiConsole = null)
+ {
+ await SpinnerInternal