feat: Add keyboard interrupt support to typewriter animation#4
Merged
feat: Add keyboard interrupt support to typewriter animation#4
Conversation
Add ability for users to skip typewriter animation by pressing keys during output. This provides better UX for users who want to see content faster. Changes: - Add interrupt parameter to Typewrite.write() accepting :enter, :any, or array of specific keys - Implement non-blocking keyboard input detection using io/console - Add write_interruptible() and key_matches?() private methods - When interrupted, remaining text prints immediately Technical details: - Uses io.wait_readable(0) for non-blocking keyboard polling - Maintains backwards compatibility via keyword argument (interrupt: false) - Terminal state automatically restored via $stdin.raw block Testing: - Add 15 new RSpec tests covering all interrupt modes - All existing tests pass (100% backwards compatible) - Update RuboCop config to allow slightly higher metrics for interrupt logic Documentation: - Update README with interrupt mode examples and usage - Bump version 1.1.0 → 1.2.0 (minor: new feature)
Replace io.wait_readable(0) with IO.select([io], nil, nil, 0) to support Ruby 3.0 and 3.1, as wait_readable was only added in Ruby 3.2. The gem requires >= 3.0.0, so we need to use IO.select which works across all supported Ruby versions. Disabled RuboCop's IncompatibleIoSelectWithFiberScheduler warning for this specific use case. Changes: - Revert to IO.select in write_interruptible method - Update all test mocks to use IO.select instead of wait_readable - Add rubocop:disable comment for backwards compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
:enter,:any, and array of specific keysio/consolewithio.wait_readable(0)Technical Details
write_interruptibleandkey_matches?Testing
Test Plan
Follow MANUAL_TESTING.md for interactive testing of all interrupt modes.