crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Implement Display for KeyCode and KeyModifiers #862

Closed joshka closed 6 months ago

joshka commented 9 months ago

Partially addresses #792

In Ratatui apps using Crossterm, something we'd like to be able to generally provide approaches for is help screens that show the key bindings that will be used. The responsibility for displaying each keys properly most likely belongs in Crossterm rather than each application.

I've tried to make some reasonable choices about displaying the keys that match the target platform (e.g. on Mac, Backspace is Delete, Delete is Fwd Del, Enter is Return, Alt is Option, Ctrl is Control, Super is Command, and on Windows Super is the Windows key). These choices are backed by the style guidelines from Apple and Microsoft where possible and intuition where not (e.g. Next Track instead of Track Next).

It would be nice to be able to have used something like strum's Display derive macro to make the implementation of this simple, but there currently isn't a way to make the format for the function keys (F1) or the media / modifier key variants work with that, so a more manual approach is taken.

joshka commented 6 months ago

Ping @TimonPost for a review on this.