use ratada::shortcut_hints;
use crate::keymap::Action;
use crate::tui::app::{App, GLOBAL_GROUP};
use crate::tui::appframe::HintGroups;
use crate::tui::bindings;
use crate::tui::views::ViewId;
use crate::tui::views::calc::Mode;
impl App {
fn global_group(&self) -> (String, Vec<(String, String)>) {
let mut hints = self.keymap.hints(&[
Action::OpenPalette,
Action::OpenHelp,
Action::Quit,
]);
hints.extend(shortcut_hints::global_bindings());
(GLOBAL_GROUP.to_string(), hints)
}
fn groups_of(&self, table: &[bindings::Group]) -> HintGroups {
table
.iter()
.filter_map(|(label, actions)| {
let hints = self.keymap.hints(actions);
(!hints.is_empty()).then(|| ((*label).to_string(), hints))
})
.collect()
}
pub(super) fn hint_groups(&self) -> HintGroups {
let table = match (self.active, self.mode) {
(ViewId::Calc, Mode::Input) => bindings::INPUT_HINT_GROUPS,
(ViewId::Calc, Mode::Edit(_)) => bindings::EDIT_HINT_GROUPS,
(ViewId::Calc, Mode::History) => bindings::HISTORY_HINT_GROUPS,
(ViewId::Variables, _) => bindings::VARIABLES_HINT_GROUPS,
(ViewId::Settings, _) => bindings::SETTINGS_HINT_GROUPS,
};
let mut groups = self.groups_of(table);
groups.extend(self.groups_of(&[bindings::SETTINGS_CHORDS]));
if !matches!(self.mode, Mode::Edit(_)) {
groups.extend(self.groups_of(&[bindings::VIEW_GROUP]));
}
groups.push(self.global_group());
groups
}
pub(crate) fn help_sections(&self) -> HintGroups {
let mut sections: HintGroups = Vec::new();
for (view, table) in bindings::HELP_TABLES {
for (label, hints) in self.groups_of(table) {
sections.push((format!("{view} \u{b7} {label}"), hints));
}
}
sections.extend(self.groups_of(&[bindings::SETTINGS_CHORDS]));
sections.extend(self.groups_of(&[bindings::VIEW_GROUP]));
sections.push(self.global_group());
sections
}
}