diff --git a/TUI.Test/SpectreConsoleProviderTests.cs b/TUI.Test/SpectreConsoleProviderTests.cs index 1631612..df5aa6c 100644 --- a/TUI.Test/SpectreConsoleProviderTests.cs +++ b/TUI.Test/SpectreConsoleProviderTests.cs @@ -112,4 +112,22 @@ public void WriteAtClipsTextOverflowingTheRightEdge() Assert.AreEqual("\u001b[3;8Habc", output.ToString()); } + + /// + /// Tests that showing or hiding the cursor writes the DECTCEM sequence to the injected console + /// and does not move the cursor (ktsu-dev/TUI#153). + /// + /// Whether the cursor is shown. + /// The sequence expected in the captured output. + [TestMethod] + [DataRow(false, "\u001b[?25l")] + [DataRow(true, "\u001b[?25h")] + public void SetCursorVisibilityWritesToTheInjectedConsoleWithoutMovingTheCursor(bool visible, string expected) + { + (SpectreConsoleProvider provider, StringWriter output) = CreateProvider(); + + provider.SetCursorVisibility(visible); + + Assert.AreEqual(expected, output.ToString()); + } } diff --git a/TUI/Services/SpectreConsoleProvider.cs b/TUI/Services/SpectreConsoleProvider.cs index c24546f..6cfb12c 100644 --- a/TUI/Services/SpectreConsoleProvider.cs +++ b/TUI/Services/SpectreConsoleProvider.cs @@ -98,11 +98,11 @@ public async Task ReadInputAsync() } /// - public void SetCursorVisibility(bool visible) - { - _console.Cursor.SetPosition(Console.CursorLeft + 1, Console.CursorTop + 1); - Console.CursorVisible = visible; - } + /// + /// Writes to the injected console rather than , and leaves the cursor where + /// it is (ktsu-dev/TUI#153). + /// + public void SetCursorVisibility(bool visible) => _console.Cursor.Show(visible); /// public void SetCursorPosition(Position position)