using System;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
///
/// Represents a context that can be used to interact with a .
///
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();
}
///
/// Updates the live display target.
///
/// The new live display target.
public void UpdateTarget(IRenderable? target)
{
lock (Lock)
{
Live.SetRenderable(target);
Refresh();
}
}
///
/// Refreshes the live display.
///
public void Refresh()
{
lock (Lock)
{
_console.Write(new ControlCode(string.Empty));
}
}
internal void SetOverflow(VerticalOverflow overflow, VerticalOverflowCropping cropping)
{
Live.Overflow = overflow;
Live.OverflowCropping = cropping;
}
}
}