From 98cd1d95023a31650045f0b9c603caa2eb17afaf Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Sep 2026 06:33:20 +0000 Subject: [PATCH] fix: hide and show the cursor on the injected console without moving it [patch] SetCursorVisibility moved the cursor to a position read from System.Console and toggled System.Console.CursorVisible, so a redirected or test console got a stray cursor move and never saw the visibility change. It now calls Cursor.Show on the injected IAnsiConsole. Fixes ktsu-dev/TUI#153 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XMvgrK1uK13jn4qeVXxDi1 --- TUI.Test/SpectreConsoleProviderTests.cs | 18 ++++++++++++++++++ TUI/Services/SpectreConsoleProvider.cs | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) 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)