From 71a5d830671220e601e4e6ab4d4c352ae0e0a64a Mon Sep 17 00:00:00 2001 From: fredrikbentzen Date: Wed, 11 Jan 2023 22:09:09 +0100 Subject: [PATCH] Fixed render issue where writeline inside status caused corrupt output #415 #694 --- src/Spectre.Console/Live/LiveRenderable.cs | 2 +- .../Live/Status/Render.Output.verified.txt | 4 +-- .../WriteLineOverflow.Output.verified.txt | 12 +++++++++ .../Unit/Live/StatusTests.cs | 26 +++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/Spectre.Console.Tests/Expectations/Live/Status/WriteLineOverflow.Output.verified.txt diff --git a/src/Spectre.Console/Live/LiveRenderable.cs b/src/Spectre.Console/Live/LiveRenderable.cs index 40107f9..a681d24 100644 --- a/src/Spectre.Console/Live/LiveRenderable.cs +++ b/src/Spectre.Console/Live/LiveRenderable.cs @@ -49,7 +49,7 @@ internal sealed class LiveRenderable : Renderable } var linesToMoveUp = _shape.Value.Height - 1; - return new ControlCode("\r" + CUU(linesToMoveUp)); + return new ControlCode("\r" + (EL(2) + CUU(1)).Repeat(linesToMoveUp)); } } diff --git a/test/Spectre.Console.Tests/Expectations/Live/Status/Render.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Live/Status/Render.Output.verified.txt index debe239..cd5fed9 100644 --- a/test/Spectre.Console.Tests/Expectations/Live/Status/Render.Output.verified.txt +++ b/test/Spectre.Console.Tests/Expectations/Live/Status/Render.Output.verified.txt @@ -1,10 +1,10 @@ [?25l * foo - + - bar - + * baz [?25h \ No newline at end of file diff --git a/test/Spectre.Console.Tests/Expectations/Live/Status/WriteLineOverflow.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Live/Status/WriteLineOverflow.Output.verified.txt new file mode 100644 index 0000000..d3647bb --- /dev/null +++ b/test/Spectre.Console.Tests/Expectations/Live/Status/WriteLineOverflow.Output.verified.txt @@ -0,0 +1,12 @@ +[?25l +⣷ long text that should not interfere writeline text + +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxx + +⣷ long text that should not interfere writeline text + + +⣷ long text that should not interfere writeline text + +[?25h \ No newline at end of file diff --git a/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs b/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs index 60f914d..dc4723d 100644 --- a/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs +++ b/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs @@ -49,4 +49,30 @@ public sealed class StatusTests // Then return Verifier.Verify(console.Output); } + + [Fact] + [Expectation("WriteLineOverflow")] + public Task Should_Render_Correctly_When_WriteLine_Exceeds_Console_Width() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.TrueColor) + .Width(100) + .Interactive() + .EmitAnsiSequences(); + var status = new Status(console) + { + AutoRefresh = false, + }; + + // When + status.Start("long text that should not interfere writeline text", ctx => + { + ctx.Refresh(); + console.WriteLine("x".Repeat(console.Profile.Width + 10), new Style(foreground: Color.White)); + }); + + // Then + return Verifier.Verify(console.Output); + } }