Lines
100 %
Functions
Branches
//! The `~X~` hotkey markup of menu titles, items and buttons.
use ratatui::style::Style;
use ratatui::text::Span;
/// The letter a `~X~` mark in `label` names.
#[must_use]
pub fn hotkey(label: &str) -> Option<char> {
let (_, rest) = label.split_once('~')?;
rest.split_once('~')?.0.chars().next()
}
/// `label` without its marks.
pub fn plain(label: &str) -> String {
label.replace('~', "")
/// The spans of `label`: the marked letter in `hot`, the rest in `base`.
pub(crate) fn spans(label: &str, base: Style, hot: Style) -> Vec<Span<'static>> {
let mut spans = Vec::new();
for (index, part) in label.split('~').enumerate() {
if !part.is_empty() {
let style = if index % 2 == 1 { hot } else { base };
spans.push(Span::styled(part.to_string(), style));
spans
#[cfg(test)]
mod tests;