Files
spectre.console/src/Spectre.Console/Live/LiveDisplayContext.cs
Patrik Svensson fa5a1e88ec Clean up Widgets
* Move /Widgets/Live/* to /Live/*
* Move /Widgets/Prompt/* to /Prompts/*
* Move tests and expectations to match the new locations
2021-07-14 08:38:44 -04:00

55 lines
1.4 KiB
C#

using System;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
/// <summary>
/// Represents a context that can be used to interact with a <see cref="LiveDisplay"/>.
/// </summary>
public sealed class LiveDisplayContext
{
private readonly IAnsiConsole _console;
internal object Lock { get; }
internal LiveRenderable Live { get; }
internal LiveDisplayContext(IAnsiConsole console, IRenderable target)
{
_console = console ?? throw new ArgumentNullException(nameof(console));
Live = new LiveRenderable(_console, target);
Lock = new object();
}
/// <summary>
/// Updates the live display target.
/// </summary>
/// <param name="target">The new live display target.</param>
public void UpdateTarget(IRenderable? target)
{
lock (Lock)
{
Live.SetRenderable(target);
Refresh();
}
}
/// <summary>
/// Refreshes the live display.
/// </summary>
public void Refresh()
{
lock (Lock)
{
_console.Write(new ControlCode(string.Empty));
}
}
internal void SetOverflow(VerticalOverflow overflow, VerticalOverflowCropping cropping)
{
Live.Overflow = overflow;
Live.OverflowCropping = cropping;
}
}
}