mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-12-27 08:17:57 +01:00
* Renames Style -> Decoration * Renames Appearance -> Style * Adds Style.Parse and Style.TryParse
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using Spectre.Console.Composition;
|
|
using Spectre.Console.Internal;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
|
/// </summary>
|
|
public static partial class ConsoleExtensions
|
|
{
|
|
/// <summary>
|
|
/// Renders the specified object to the console.
|
|
/// </summary>
|
|
/// <param name="console">The console to render to.</param>
|
|
/// <param name="renderable">The object to render.</param>
|
|
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));
|
|
}
|
|
|
|
foreach (var segment in renderable.Render(console.Encoding, console.Width))
|
|
{
|
|
if (!segment.Style.Equals(Style.Plain))
|
|
{
|
|
using (var style = console.PushStyle(segment.Style))
|
|
{
|
|
console.Write(segment.Text);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
console.Write(segment.Text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|