feat: displaying filter shortcut in help menu instead of "{widget}.help"

This commit is contained in:
MarkZaytsev 2024-07-27 23:33:51 +07:00
parent f024ce03e7
commit b017ae0f68
2 changed files with 16 additions and 3 deletions

View file

@ -30,6 +30,18 @@ impl Keymap {
Layer::Which => unreachable!(),
}
}
pub fn get_shortcut_for_command(&self, cmd_name: &str, layer: Layer) -> Option<String> {
let control = self
.get(layer)
.iter()
.find(|&c| c.run.iter().any(|cmd| cmd.name.eq(cmd_name)));
match control {
Some(c) => Some(c.on()),
None => None
}
}
}
impl FromStr for Keymap {

View file

@ -1,6 +1,6 @@
use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, text::Line, widgets::Widget};
use yazi_config::THEME;
use yazi_config::{KEYMAP, THEME};
use yazi_shared::Layer;
use super::Bindings;
use crate::Ctx;
@ -18,8 +18,9 @@ impl<'a> Widget for Layout<'a> {
yazi_plugin::elements::Clear::default().render(area, buf);
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
let filter_key = KEYMAP.get_shortcut_for_command("filter", Layer::Help).unwrap_or_else(|| "[undefined]".into());
Line::styled(
help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)),
help.keyword().unwrap_or_else(|| format!("{}.help (press {} to filter)", help.layer, filter_key)),
THEME.help.footer,
)
.render(chunks[1], buf);