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

refactor: use is_key_* helpers for consistency in key event methods #980

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

gaesa
Copy link
Contributor

@gaesa gaesa commented Mar 25, 2025

Description

This PR refactors as_key_release_event and as_key_repeat_event to use the existing is_key_release and is_key_repeat helper methods for consistency. This aligns all as_key_*_event methods to follow the same structure, improving maintainability.

Changes

  • as_key_release_event now calls is_key_release() instead of manually checking event.kind == KeyEventKind::Release
  • as_key_repeat_event now calls is_key_repeat() instead of manually checking event.kind == KeyEventKind::Repeat

Rationale

  • is_key_press_event already uses is_key_press(), so the other two methods should follow the same pattern.
  • The matches! macro used in is_key_* functions is more general and can sometimes be optimized better by the compiler.
  • Improves code clarity.

@gaesa gaesa requested a review from TimonPost as a code owner March 25, 2025 07:34
Copy link
Collaborator

@joshka joshka left a comment

Choose a reason for hiding this comment

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

Thanks!

@joshka joshka merged commit b6562fe into crossterm-rs:master Mar 25, 2025
6 checks passed
@gaesa gaesa deleted the consistency branch March 25, 2025 08:17
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.

2 participants