Guide API
Skip to main content

hot_key

Function hot_key 

Source
pub fn hot_key(s: &str) -> Option<char>
Expand description

Extract the hotkey character from a label string.

The convention: the first ~-delimited run in s marks the hotkey. The char immediately following the first ~ is the hotkey, uppercased. Returns None if there is no ~, if the ~ is at the end of the string (nothing after it), or if the char after ~ is itself ~ (a tilde-escape, i.e. a literal ~ in the label).

§Turbo Vision heritage

Ports hotKey/hotKeyStr (tinputli.cpp); they returned a null char for the no-hotkey case, where tvision-rs returns Option<char>.

§Examples

use tvision_rs::event::hot_key;
assert_eq!(hot_key("~o~k"), Some('O'));  // uppercased
assert_eq!(hot_key("O~k"), Some('K'));  // first char after first '~'
assert_eq!(hot_key("No tilde here"), None);
assert_eq!(hot_key("trailing~"), None);
assert_eq!(hot_key("~~x"), None);       // char after '~' is '~'