joshka / bevy_ratatui

A rust crate to use Ratatui in a Bevy App
https://crates.io/crates/bevy_ratatui
Apache License 2.0
35 stars 3 forks source link

Pass through crossterm keys to bevy's input system. #13

Closed shanecelis closed 3 months ago

shanecelis commented 3 months ago

I was working on bevy_crossterm adding passing keys from it to bevy's input system, and someone pointed out your crate. Well, I took my changes there and adapted them here, and they were easy to integrate. This is a nice crate! This feature will work with and without kitty. Without kitty it merely sends a released key event on the next frame, which is fine for a pressed key but when a key is held down I'm not sure it's the best we can do.

I only added two public items bevy_compat::KeyboardPlugin and an event::InputSet. The InputSet is to ensure that crossterm sends out its events, then this plugin can read them and send out bevy's events.

I did add this plugin to the default plugins. It doesn't seem to interfere with any of the examples. It hopefully merely lets the users choose to use which input is most convenient for them.

I covered many of the keys, but they are definitely some gaps. Gaps will result in no bevy event being emitted. I did not attempt to discriminate between numpad keys.

I added a bevy_keys example copied from the kitty example initially.

If this is accepted, I imagine a bevy_compat::MousePlugin will come in the future.

shanecelis commented 3 months ago

I tried to do a little better about repeated keys when kitty isn't present. Now it will check if a key is pressed again when kitty isn't present before sending a release event. I'm pretty happy with that.

cxreiff commented 3 months ago

Wow, this is great! I've been hoping to add something like this because I'd like bevy_ratatui_render to be something that can be dropped into any bevy project as-is without needing to handle TTY idiosyncrasies. I'll try to give a review some time this evening.

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 0% with 633 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (9d26164) to head (e7410a5).

Files Patch % Lines
src/input_forwarding/keyboard.rs 0.00% 611 Missing :warning:
src/event.rs 0.00% 18 Missing :warning:
src/ratatui.rs 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #13 +/- ## ====================================== Coverage 0.00% 0.00% ====================================== Files 6 7 +1 Lines 173 805 +632 ====================================== - Misses 173 805 +632 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

shanecelis commented 3 months ago

All right. Have a look at it now.