Add profile support

Closes #231
This commit is contained in:
Patrik Svensson
2021-01-16 17:23:58 +01:00
committed by Patrik Svensson
parent 913a7b1e37
commit a23bec4082
230 changed files with 1241 additions and 1628 deletions

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
internal sealed class FallbackStatusRenderer : ProgressRenderer
{
private readonly object _lock;
private IRenderable? _renderable;
private string? _lastStatus;
public override TimeSpan RefreshRate => TimeSpan.FromMilliseconds(100);
public FallbackStatusRenderer()
{
_lock = new object();
}
public override void Update(ProgressContext context)
{
lock (_lock)
{
var task = context.GetTasks().SingleOrDefault();
if (task != null)
{
// Not same description?
if (_lastStatus != task.Description)
{
_lastStatus = task.Description;
_renderable = new Markup(task.Description + Environment.NewLine);
return;
}
}
_renderable = null;
return;
}
}
public override IEnumerable<IRenderable> Process(RenderContext context, IEnumerable<IRenderable> renderables)
{
lock (_lock)
{
var result = new List<IRenderable>();
result.AddRange(renderables);
if (_renderable != null)
{
result.Add(_renderable);
}
_renderable = null;
return result;
}
}
}
}