Skip to main content

Module keystroke_format

Module keystroke_format 

Source
Expand description

Platform- and locale-aware formatting for [KeyStroke]s.

  • On macOS, the returned string uses the traditional symbol modifiers (⌘⇧⌥⌃) and Unicode key glyphs (↑↩⇥ …). These symbols are universal, so no locale lookup is needed.
  • On Windows / Linux, the modifier labels and named-key labels (Enter, Esc, Space, arrows, Home/End, PageUp/Down, …) flow through tr_widget! (teksilo-i18n’s compile-time-checked translation macro) so apps that register teksilo-widgets’ framework locales see “Strg+Eingabe” in German, “Ctrl+Entrée” in French, “Ctrl+Enter” in English, etc. Letters, digits, character keys and F1..F24 fall through to Key::Display: those names are universal.

format_keystroke gives the whole chord as one label; keystroke_parts gives one label per key, for a surface that draws each key on its own key cap. Both come from the same per-key labels, so they cannot disagree.

Functions§

format_keystroke
Render keystroke as the conventional label for the current platform and active locale.
keystroke_parts
The labels of the keys in keystroke, modifiers first in the platform’s order, the main key last: ["Ctrl", "Shift", "Z"], or ["⇧", "⌘", "Z"] on macOS.