Skip to content

Commit f32f80d

Browse files
authored
Fix resizing of Live views with reduced size. (#1840)
1 parent 7f3ebe0 commit f32f80d

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/Spectre.Console/Live/LiveDisplayRenderer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ internal sealed class LiveDisplayRenderer : IRenderHook
44
{
55
private readonly IAnsiConsole _console;
66
private readonly LiveDisplayContext _context;
7-
87
public LiveDisplayRenderer(IAnsiConsole console, LiveDisplayContext context)
98
{
109
_console = console;
@@ -45,7 +44,7 @@ public IEnumerable<IRenderable> Process(RenderOptions options, IEnumerable<IRend
4544
{
4645
lock (_context.Lock)
4746
{
48-
yield return _context.Live.PositionCursor();
47+
yield return _context.Live.PositionCursor(options);
4948

5049
foreach (var renderable in renderables)
5150
{

src/Spectre.Console/Live/LiveRenderable.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void SetRenderable(IRenderable? renderable)
3939
}
4040
}
4141

42-
public IRenderable PositionCursor()
42+
public IRenderable PositionCursor(RenderOptions options)
4343
{
4444
lock (_lock)
4545
{
@@ -48,6 +48,14 @@ public IRenderable PositionCursor()
4848
return new ControlCode(string.Empty);
4949
}
5050

51+
// Check if the size have been reduced
52+
if (_shape.Value.Height > options.ConsoleSize.Height || _shape.Value.Width > options.ConsoleSize.Width)
53+
{
54+
// Important reset shape, so the size can shrink
55+
_shape = null;
56+
return new ControlCode(ED(2) + ED(3) + CUP(1, 1));
57+
}
58+
5159
var linesToMoveUp = _shape.Value.Height - 1;
5260
return new ControlCode("\r" + CUU(linesToMoveUp));
5361
}

src/Spectre.Console/Live/Progress/Renderers/DefaultProgressRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override IEnumerable<IRenderable> Process(RenderOptions options, IEnumera
118118
{
119119
lock (_lock)
120120
{
121-
yield return _live.PositionCursor();
121+
yield return _live.PositionCursor(options);
122122

123123
foreach (var renderable in renderables)
124124
{

src/Spectre.Console/Prompts/List/ListPromptRenderHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public IEnumerable<IRenderable> Process(RenderOptions options, IEnumerable<IRend
4242
_dirty = false;
4343
}
4444

45-
yield return _live.PositionCursor();
45+
yield return _live.PositionCursor(options);
4646

4747
foreach (var renderable in renderables)
4848
{

0 commit comments

Comments
 (0)