generated from GarandPLG/rust-flake-template
Refactor keybinding handling and update widgets
- Remove the old `keybindings.rs` and stop re‑exporting its symbols. - Add view‑specific handling: `App::handle_key_event` now delegates to `main_menu_keybindings` when the view is `MainMenu`. - Update imports in `app.rs`, `widget.rs`, and widget modules to use the new `app::keybindings` path. - Enhance `keybindings_widget` to display ↑, ↓ and “Space” for special keys. - Change main menu layout percentages from 90/10 to 87/13. - Reorder the `clap` import in `cli.rs` for consistency.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::app::{View, keybindings::binding_for_view};
|
||||
use ratatui::{
|
||||
crossterm::event::KeyCode,
|
||||
layout::Alignment,
|
||||
@@ -6,13 +7,14 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
};
|
||||
|
||||
use crate::app::{View, binding_for_view};
|
||||
|
||||
pub fn keybindings_widget(view: View) -> Paragraph<'static> {
|
||||
let lines: Vec<Line> = binding_for_view(view)
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let key_span = match b.code {
|
||||
KeyCode::Up => Span::raw("↑".to_string()),
|
||||
KeyCode::Down => Span::raw("↓".to_string()),
|
||||
KeyCode::Char(' ') => Span::raw("Space".to_string()),
|
||||
KeyCode::Char(c) => Span::raw(c.to_string()),
|
||||
other => Span::raw(format!("{:?}", other)),
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::app::{View, widgets::keybindings_widget};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
@@ -5,11 +6,9 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Paragraph, Widget},
|
||||
};
|
||||
|
||||
use crate::app::{View, widgets::keybindings_widget};
|
||||
|
||||
pub fn main_menu_widget(area: Rect, buf: &mut Buffer) {
|
||||
let vertical_layout: Layout =
|
||||
Layout::vertical([Constraint::Percentage(90), Constraint::Percentage(10)]);
|
||||
Layout::vertical([Constraint::Percentage(87), Constraint::Percentage(13)]);
|
||||
|
||||
let [main_menu_area, keybindings_area] = vertical_layout.areas(area);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user