mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-26 21:22:50 +08:00

* Introduce MarkupInterpolated and MarkupLineInterpolated extensions These new methods enable easily writing markup with a nice and intuitive syntax without having to worry about escaping the markup. ```csharp string input = args[0]; string output = Process(input); AnsiConsole.MarkupLineInterpolated($"[blue]{input}[/] -> [green]{output}[/]"); ``` The `Interpolated` suffix was inspired by the Entity Framework Core [FromSqlInterpolated][1] method. [1]: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#passing-parameters * Fixing whitespace to match file scoped namespaces * Adding FromInterpolated helper to Markup widget Allows automatic handling of interpolated strings to be used on the Markup widget. This would be helpful for people working with Tables and the Tree control who would not be using the MarkupInterpolated methods. * Documentation for markup interpolated methods. Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com>
141 lines
5.4 KiB
C#
141 lines
5.4 KiB
C#
namespace Spectre.Console;
|
|
|
|
/// <summary>
|
|
/// A console capable of writing ANSI escape sequences.
|
|
/// </summary>
|
|
public static partial class AnsiConsole
|
|
{
|
|
/// <summary>
|
|
/// Writes the specified markup to the console.
|
|
/// </summary>
|
|
/// <param name="value">The value to write.</param>
|
|
public static void Markup(string value)
|
|
{
|
|
Console.Markup(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup to the console.
|
|
/// </summary>
|
|
/// <param name="format">A composite format string.</param>
|
|
/// <param name="args">An array of objects to write.</param>
|
|
public static void Markup(string format, params object[] args)
|
|
{
|
|
Console.Markup(format, args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup to the console.
|
|
/// <para/>
|
|
/// All interpolation holes which contain a string are automatically escaped so you must not call <see cref="StringExtensions.EscapeMarkup"/>.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// string input = args[0];
|
|
/// string output = Process(input);
|
|
/// AnsiConsole.MarkupInterpolated($"[blue]{input}[/] -> [green]{output}[/]");
|
|
/// </code>
|
|
/// </example>
|
|
/// <param name="value">The interpolated string value to write.</param>
|
|
public static void MarkupInterpolated(FormattableString value)
|
|
{
|
|
Console.MarkupInterpolated(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup to the console.
|
|
/// </summary>
|
|
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
|
/// <param name="format">A composite format string.</param>
|
|
/// <param name="args">An array of objects to write.</param>
|
|
public static void Markup(IFormatProvider provider, string format, params object[] args)
|
|
{
|
|
Console.Markup(provider, format, args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup to the console.
|
|
/// <para/>
|
|
/// All interpolation holes which contain a string are automatically escaped so you must not call <see cref="StringExtensions.EscapeMarkup"/>.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// string input = args[0];
|
|
/// string output = Process(input);
|
|
/// AnsiConsole.MarkupInterpolated(CultureInfo.InvariantCulture, $"[blue]{input}[/] -> [green]{output}[/]");
|
|
/// </code>
|
|
/// </example>
|
|
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
|
/// <param name="value">The interpolated string value to write.</param>
|
|
public static void MarkupInterpolated(IFormatProvider provider, FormattableString value)
|
|
{
|
|
Console.MarkupInterpolated(provider, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup, followed by the current line terminator, to the console.
|
|
/// </summary>
|
|
/// <param name="value">The value to write.</param>
|
|
public static void MarkupLine(string value)
|
|
{
|
|
Console.MarkupLine(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup, followed by the current line terminator, to the console.
|
|
/// </summary>
|
|
/// <param name="format">A composite format string.</param>
|
|
/// <param name="args">An array of objects to write.</param>
|
|
public static void MarkupLine(string format, params object[] args)
|
|
{
|
|
Console.MarkupLine(format, args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup, followed by the current line terminator, to the console.
|
|
/// <para/>
|
|
/// All interpolation holes which contain a string are automatically escaped so you must not call <see cref="StringExtensions.EscapeMarkup"/>.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// string input = args[0];
|
|
/// string output = Process(input);
|
|
/// AnsiConsole.MarkupLineInterpolated($"[blue]{input}[/] -> [green]{output}[/]");
|
|
/// </code>
|
|
/// </example>
|
|
/// <param name="value">The interpolated string value to write.</param>
|
|
public static void MarkupLineInterpolated(FormattableString value)
|
|
{
|
|
Console.MarkupLineInterpolated(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup, followed by the current line terminator, to the console.
|
|
/// </summary>
|
|
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
|
/// <param name="format">A composite format string.</param>
|
|
/// <param name="args">An array of objects to write.</param>
|
|
public static void MarkupLine(IFormatProvider provider, string format, params object[] args)
|
|
{
|
|
Console.MarkupLine(provider, format, args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the specified markup, followed by the current line terminator, to the console.
|
|
/// <para/>
|
|
/// All interpolation holes which contain a string are automatically escaped so you must not call <see cref="StringExtensions.EscapeMarkup"/>.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// string input = args[0];
|
|
/// string output = Process(input);
|
|
/// AnsiConsole.MarkupLineInterpolated(CultureInfo.InvariantCulture, $"[blue]{input}[/] -> [green]{output}[/]");
|
|
/// </code>
|
|
/// </example>
|
|
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
|
/// <param name="value">The interpolated string value to write.</param>
|
|
public static void MarkupLineInterpolated(IFormatProvider provider, FormattableString value)
|
|
{
|
|
Console.MarkupLineInterpolated(provider, value);
|
|
}
|
|
} |