-
Notifications
You must be signed in to change notification settings - Fork 0
Restore cursor visibility and properly handle Ctrl+C interruption #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Display a styled warning message to inform the user that the operation was interrupted when they press Ctrl+C. The message uses the warning color from the console color scheme for consistency. Message format: '⚠️ Operation interrupted by user' This provides better user feedback that their interrupt was received and explains why the operation stopped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses issue #47 by implementing cursor visibility management and proper Ctrl+C signal handling to prevent terminal cursor state issues during application interruption.
Changes:
- Added
CursorManagerutility class with IDisposable pattern to manage terminal cursor visibility - Enhanced
Program.Main()with CancelKeyPress and ProcessExit handlers for graceful shutdown - Integrated cursor restoration in exception handling to ensure cleanup on crash
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/RipSharp/Utilities/CursorManager.cs | New utility class implementing IDisposable to hide cursor on initialization and restore on disposal with error handling |
| src/RipSharp/Core/Program.cs | Added signal handlers for Ctrl+C and ProcessExit, integrated CursorManager with using statement and exception handling, added Spectre.Console import for styled warning messages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| AnsiConsole.Cursor.Hide(); | ||
| Console.CursorVisible = false; | ||
| } | ||
| catch | ||
| { | ||
| // Silently fail if cursor operations aren't supported | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Restores cursor visibility. Safe to call multiple times. | ||
| /// </summary> | ||
| public void RestoreCursor() | ||
| { | ||
| if (_disposed) return; | ||
|
|
||
| try | ||
| { | ||
| AnsiConsole.Cursor.Show(); | ||
| Console.CursorVisible = true; |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both AnsiConsole.Cursor methods and Console.CursorVisible property are being used together to manage cursor visibility. While this dual approach provides redundancy, it may be unnecessary since Spectre.Console's AnsiConsole likely manages the underlying Console cursor state. Consider whether both approaches are needed, or document why this dual management is necessary for compatibility across different terminal environments.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added 9 test cases covering CursorManager functionality: - Constructor successfully hides cursor - RestoreCursor can be called multiple times safely - Dispose properly restores cursor - Dispose can be called multiple times - RestoreCursor after Dispose returns early (safe) - Using statement ensures proper disposal - Implements IDisposable interface - RestoreCursor is idempotent - Gracefully handles unsupported environments All tests verify the class handles cursor operations safely without throwing exceptions, even in unsupported environments. Test count increased from 112 to 121 (all passing)
Overview
Fixes issue #47 - Restore cursor visibility on application exit and properly handle user interruption via Ctrl+C.
Problem
When the application was interrupted with Ctrl+C during ripping operations, it would:
Solution
Added CursorManager Utility
CursorManagerclass implementsIDisposableEnhanced Program.Main() with Signal Handlers
Console.CancelKeyPress handler (Ctrl+C):
AppDomain.ProcessExit handler:
Try/catch wrapper:
Changes
src/RipSharp/Utilities/CursorManager.cssrc/RipSharp/Core/Program.cswith cursor management and signal handlersBehavior Changes
✅ Ctrl+C now immediately exits the application instead of skipping tracks
✅ Cursor is always restored to visible state on exit
✅ User receives clear feedback when interrupting
✅ Exit code 130 properly indicates SIGINT termination
Testing
Closes #47