Skip to content

feat: Add keyboard interrupt support to typewriter animation#4

Merged
CJGlitter merged 3 commits intomainfrom
feature/interrupt-typewriting
Feb 2, 2026
Merged

feat: Add keyboard interrupt support to typewriter animation#4
CJGlitter merged 3 commits intomainfrom
feature/interrupt-typewriting

Conversation

@CJGlitter
Copy link
Owner

Summary

  • Add keyboard interrupt functionality to allow users to skip typewriter animation
  • Maintains 100% backwards compatibility via keyword argument
  • Comprehensive test coverage and documentation

Changes

  • Added interrupt modes: :enter, :any, and array of specific keys
  • Non-blocking input detection: Uses io/console with io.wait_readable(0)
  • Immediate text completion: Remaining text prints instantly when interrupted
  • 15 new tests: Full coverage of all interrupt modes and edge cases
  • Documentation: Updated README with examples and created CHANGELOG

Technical Details

  • Version bump: 1.1.0 → 1.2.0 (minor feature addition)
  • New private methods: write_interruptible and key_matches?
  • RuboCop config adjusted for interrupt logic complexity
  • All existing tests pass (backwards compatibility verified)

Testing

  • ✅ All 24 tests pass (9 original + 15 new)
  • ✅ RuboCop clean (no offenses)
  • ✅ Manually tested in IRB on macOS

Test Plan

Follow MANUAL_TESTING.md for interactive testing of all interrupt modes.

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
@CJGlitter CJGlitter merged commit e5a40b2 into main Feb 2, 2026
6 checks passed
@CJGlitter CJGlitter deleted the feature/interrupt-typewriting branch February 2, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant