Skip to content
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

Add keyboard commands to watch mode #7

Merged
merged 1 commit into from
Feb 22, 2024
Merged

Conversation

mattbrictson
Copy link
Owner

This commit makes watch mode interactive. It now understands these keys:

  • Press ENTER to run all tests
  • Press "q" to quit

To do this, I start another background thread that listens for key presses. When a key is pressed, the thread posts a :keypress event to the event loop. The event loop then takes an appropriate action.

Because they keypress listener is running in a thread separate from the file system listener, that means the watcher is still able to detect changes to files and auto-run tests. The event loop funnels all of these events into a single thread of execution.

This commit makes watch mode interactive. It now understands these keys:

- Press ENTER to run all tests
- Press "q" to quit

To do this, I start another background thread that listens for key
presses. When a key is pressed, the thread posts a `:keypress` event to
the event loop. The event loop then takes an appropriate action.

Because they keypress listener is running in a thread separate from the
file system listener, that means the watcher is still able to detect
changes to files and auto-run tests. The event loop funnels all of these
events into a single thread of execution.
@mattbrictson mattbrictson added the ✨ Feature Adds a new feature label Feb 22, 2024
Comment on lines +79 to +80
rescue Interrupt
retry
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗒️ If the user presses ctrl-c to interrupt a slow test, we want the test to be canceled, but the watcher to continue running. That's why the Interrupt exception is ignored here and the keypress loop continues.

If a test is not running and the user presses ctrl-c, the event loop in the main (foreground) thread will exit with an un-rescued Interrupt exception and die, and the entire watcher process will exit, effectively killing any background threads. So we don't need to explicitly handle that scenario here.

@mattbrictson mattbrictson merged commit fc76461 into main Feb 22, 2024
6 checks passed
@mattbrictson mattbrictson deleted the watch-interactive branch February 22, 2024 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature Adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant