mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-17 17:32:50 +08:00
Clean up status related code a bit
This commit is contained in:
parent
501db5d287
commit
acf01e056f
@ -20,11 +20,7 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(column));
|
throw new ArgumentNullException(nameof(column));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style != null)
|
column.Style = style;
|
||||||
{
|
|
||||||
column.Style = style;
|
|
||||||
}
|
|
||||||
|
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ namespace Spectre.Console.Internal
|
|||||||
private IRenderable? _renderable;
|
private IRenderable? _renderable;
|
||||||
private string? _lastStatus;
|
private string? _lastStatus;
|
||||||
|
|
||||||
public override TimeSpan RefreshRate => TimeSpan.FromSeconds(1);
|
public override TimeSpan RefreshRate => TimeSpan.FromMilliseconds(100);
|
||||||
|
|
||||||
public StatusFallbackRenderer()
|
public StatusFallbackRenderer()
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ namespace Spectre.Console.Rendering
|
|||||||
|
|
||||||
var shape = SegmentShape.Calculate(context, lines);
|
var shape = SegmentShape.Calculate(context, lines);
|
||||||
_shape = _shape == null ? shape : _shape.Value.Inflate(shape);
|
_shape = _shape == null ? shape : _shape.Value.Inflate(shape);
|
||||||
_shape.Value.SetShape(context, lines);
|
_shape.Value.Apply(context, ref lines);
|
||||||
|
|
||||||
foreach (var (_, _, last, line) in lines.Enumerate())
|
foreach (var (_, _, last, line) in lines.Enumerate())
|
||||||
{
|
{
|
||||||
|
@ -620,49 +620,5 @@ namespace Spectre.Console.Rendering
|
|||||||
|
|
||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static (int Width, int Height) GetShape(RenderContext context, List<SegmentLine> lines)
|
|
||||||
{
|
|
||||||
if (context is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lines is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(lines));
|
|
||||||
}
|
|
||||||
|
|
||||||
var height = lines.Count;
|
|
||||||
var width = lines.Max(l => CellCount(context, l));
|
|
||||||
|
|
||||||
return (width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static List<SegmentLine> SetShape(RenderContext context, List<SegmentLine> lines, (int Width, int Height) shape)
|
|
||||||
{
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
var length = CellCount(context, line);
|
|
||||||
var missing = shape.Width - length;
|
|
||||||
if (missing > 0)
|
|
||||||
{
|
|
||||||
line.Add(new Segment(new string(' ', missing)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lines.Count < shape.Height)
|
|
||||||
{
|
|
||||||
var missing = shape.Height - lines.Count;
|
|
||||||
for (int i = 0; i < missing; i++)
|
|
||||||
{
|
|
||||||
var line = new SegmentLine();
|
|
||||||
line.Add(new Segment(new string(' ', shape.Width)));
|
|
||||||
lines.Add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace Spectre.Console.Rendering
|
|||||||
Math.Max(Height, other.Height));
|
Math.Max(Height, other.Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetShape(RenderContext context, List<SegmentLine> lines)
|
public void Apply(RenderContext context, ref List<SegmentLine> lines)
|
||||||
{
|
{
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
@ -52,14 +52,15 @@ namespace Spectre.Console.Rendering
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lines.Count < Height)
|
if (lines.Count < Height && Width > 0)
|
||||||
{
|
{
|
||||||
var missing = Height - lines.Count;
|
var missing = Height - lines.Count;
|
||||||
for (var i = 0; i < missing; i++)
|
for (var i = 0; i < missing; i++)
|
||||||
{
|
{
|
||||||
var line = new SegmentLine();
|
lines.Add(new SegmentLine
|
||||||
line.Add(new Segment(new string(' ', Width)));
|
{
|
||||||
lines.Add(line);
|
new Segment(new string(' ', Width)),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user