generated from GarandPLG/rust-flake-template
KeybindingsWidget now accepts actions
Views now pass a list of `Action` values to `KeybindingsWidget` instead of pre‑resolved `KeyBinding` references. The widget resolves the bindings internally using `binding_for`, simplifying import statements and view logic.
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
use crate::app::{
|
use crate::app::{keybindings::Action, widgets::KeybindingsWidget};
|
||||||
keybindings::{Action, KeyBinding, binding_for},
|
|
||||||
widgets::KeybindingsWidget,
|
|
||||||
};
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Alignment, Constraint, Layout, Rect},
|
layout::{Alignment, Constraint, Layout, Rect},
|
||||||
@@ -25,12 +22,8 @@ pub fn default_view(area: Rect, buf: &mut Buffer) {
|
|||||||
.render(main_area, buf);
|
.render(main_area, buf);
|
||||||
|
|
||||||
{
|
{
|
||||||
let keybindings: Vec<Option<&'static KeyBinding>> = vec![
|
let actions: Vec<Action> = vec![Action::Quit, Action::Quit2, Action::Esc];
|
||||||
binding_for(Action::Quit),
|
|
||||||
binding_for(Action::Quit2),
|
|
||||||
binding_for(Action::Esc),
|
|
||||||
];
|
|
||||||
|
|
||||||
KeybindingsWidget::new(keybindings).render(keybindings_area, buf);
|
KeybindingsWidget::new(actions).render(keybindings_area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
use crate::app::{
|
use crate::app::{App, View, keybindings::Action, widgets::KeybindingsWidget};
|
||||||
App, View,
|
|
||||||
keybindings::{Action, KeyBinding, binding_for},
|
|
||||||
widgets::KeybindingsWidget,
|
|
||||||
};
|
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
@@ -87,14 +83,14 @@ pub fn main_menu_view(app: &App, area: Rect, buf: &mut Buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let keybindings: Vec<Option<&'static KeyBinding>> = vec![
|
let actions: Vec<Action> = vec![
|
||||||
binding_for(Action::Up),
|
Action::Up,
|
||||||
binding_for(Action::Down),
|
Action::Down,
|
||||||
binding_for(Action::Space),
|
Action::Space,
|
||||||
binding_for(Action::Quit),
|
Action::Quit,
|
||||||
binding_for(Action::Quit2),
|
Action::Quit2,
|
||||||
];
|
];
|
||||||
|
|
||||||
KeybindingsWidget::new(keybindings).render(keybindings_area, buf);
|
KeybindingsWidget::new(actions).render(keybindings_area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-14
@@ -1,8 +1,4 @@
|
|||||||
use crate::app::{
|
use crate::app::{App, keybindings::Action, widgets::KeybindingsWidget};
|
||||||
App,
|
|
||||||
keybindings::{Action, KeyBinding, binding_for},
|
|
||||||
widgets::KeybindingsWidget,
|
|
||||||
};
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Alignment, Constraint, Layout, Rect},
|
layout::{Alignment, Constraint, Layout, Rect},
|
||||||
@@ -64,16 +60,16 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let keybindings: Vec<Option<&'static KeyBinding>> = vec![
|
let actions: Vec<Action> = vec![
|
||||||
binding_for(Action::Up),
|
Action::Up,
|
||||||
binding_for(Action::Down),
|
Action::Down,
|
||||||
binding_for(Action::Space),
|
Action::Space,
|
||||||
binding_for(Action::Enter),
|
Action::Enter,
|
||||||
binding_for(Action::Quit),
|
Action::Quit,
|
||||||
binding_for(Action::Quit2),
|
Action::Quit2,
|
||||||
binding_for(Action::Esc),
|
Action::Esc,
|
||||||
];
|
];
|
||||||
|
|
||||||
KeybindingsWidget::new(keybindings).render(keybindings_area, buf);
|
KeybindingsWidget::new(actions).render(keybindings_area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use crate::app::keybindings::{Action, Group, KeyBinding, binding_for};
|
||||||
|
|
||||||
use crate::app::keybindings::{Group, KeyBinding};
|
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
@@ -9,13 +7,17 @@ use ratatui::{
|
|||||||
text::Line,
|
text::Line,
|
||||||
widgets::{Block, Borders, Padding, Paragraph, Widget},
|
widgets::{Block, Borders, Padding, Paragraph, Widget},
|
||||||
};
|
};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub struct KeybindingsWidget {
|
pub struct KeybindingsWidget {
|
||||||
grouped: Vec<Paragraph<'static>>,
|
grouped: Vec<Paragraph<'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeybindingsWidget {
|
impl KeybindingsWidget {
|
||||||
pub fn new(keybindings: Vec<Option<&'static KeyBinding>>) -> Self {
|
pub fn new(actions: Vec<Action>) -> Self {
|
||||||
|
let keybindings: Vec<Option<&'static KeyBinding>> =
|
||||||
|
actions.iter().map(|a| binding_for(*a)).collect();
|
||||||
|
|
||||||
let used_groups: HashSet<Group> = keybindings
|
let used_groups: HashSet<Group> = keybindings
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|b| b.map(|binding| binding.group))
|
.filter_map(|b| b.map(|binding| binding.group))
|
||||||
|
|||||||
Reference in New Issue
Block a user