Restore terminal cursor visibility on exit in collect-linux#5707
Restore terminal cursor visibility on exit in collect-linux#5707
Conversation
- Add finally block to restore cursor visibility on all exit paths - Check IsOutputRedirected before restoring cursor - Add unit tests to verify cursor restoration behavior Co-authored-by: hoyosjs <19413848+hoyosjs@users.noreply.github.com>
Remove manual cursor state manipulation in test to properly verify that the finally block respects IsOutputRedirected flag Co-authored-by: hoyosjs <19413848+hoyosjs@users.noreply.github.com>
Co-authored-by: hoyosjs <19413848+hoyosjs@users.noreply.github.com>
|
I tested and this seems to be working correctly. |
There was a problem hiding this comment.
Pull request overview
Fixes terminal state cleanup for dotnet-trace collect-linux by ensuring the cursor is restored after trace collection, and adds functional tests around cursor visibility behavior.
Changes:
- Restore cursor visibility in
CollectLinuxCommandHandler.CollectLinuxvia afinallyblock. - Add functional tests for cursor visibility on success, error, and redirected-output scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs | Adds cursor restoration logic in finally for collect-linux execution paths. |
| src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs | Adds tests intended to validate cursor visibility restoration behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
- Check IsOutputRedirected before hiding cursor - Cache original cursor visibility state - Restore original state only if changed - Update test to verify cursor unchanged when redirected Co-authored-by: hoyosjs <19413848+hoyosjs@users.noreply.github.com>
| @@ -257,14 +257,14 @@ public void CollectLinuxCommand_RestoresCursorVisibility_OnError() | |||
| public void CollectLinuxCommand_DoesNotRestoreCursor_WhenOutputIsRedirected() | |||
There was a problem hiding this comment.
@copilot the test name suggests that the cursor would be hidden and remain hidden when the output is redirected. Could it be renamed to CollectLinuxCommand_DoesNotChangeCursorVisibility_WhenOutputIsRedirected.
Can this be a theory taking in true/false as the original cursor's visibility
There was a problem hiding this comment.
It would be nice to have a test validating that the cursor is still visible during tracing, but given that it's currently a synchronous method, it doesn't seem reasonably easily testable.
There was a problem hiding this comment.
Done in commit ecb67f1. Renamed the test to CollectLinuxCommand_DoesNotChangeCursorVisibility_WhenOutputIsRedirected and converted it to a theory with InlineData(true) and InlineData(false) to test both initial cursor visibility states.
- Rename test to CollectLinuxCommand_DoesNotChangeCursorVisibility_WhenOutputIsRedirected - Convert from Fact to Theory with InlineData for true/false cursor states - Test now validates both initial cursor visibility states Co-authored-by: mdh1418 <16830051+mdh1418@users.noreply.github.com>
Fix terminal cursor visibility in dotnet-trace collect-linux
Problem
The
dotnet-trace collect-linuxcommand hides the terminal cursor during operation but fails to restore it on exit, leaving users with an invisible cursor that requires manual restoration viatput cnormorreset.Solution
Added cursor visibility restoration in the
finallyblock with proper state tracking to ensure the cursor is restored correctly on all exit paths.Changes Made
CollectLinuxCommand.cs: Enhanced cursor visibility handling
!Console.IsOutputRedirectedfinallyblock only if changed--probe)CollectLinuxCommandFunctionalTests.cs: Updated and improved tests
CollectLinuxCommand_DoesNotChangeCursorVisibility_WhenOutputIsRedirectedto better reflect behaviorInlineDatato test bothtrueandfalseinitial cursor statesTesting
Code Changes
Original prompt
dotnet-trace collect-linuxleaves terminal cursor hidden after tracing completes #5706💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.