generated from GarandPLG/rust-flake-template
de42569a51
Replace the `default_window` string field with a `View` enum throughout the application. Introduce a new keybinding module providing `Action`, `KeyBinding` structs and helper functions, and integrate a keybindings widget into the main menu. Update the CLI to accept a `View` value enum and adjust imports and event handling accordingly. Add a release profile in `Cargo.toml` with LTO, single codegen unit, higher optimisation level and binary stripping for smaller, faster builds.
32 lines
845 B
Rust
32 lines
845 B
Rust
use ratatui::{
|
|
crossterm::event::KeyCode,
|
|
layout::Alignment,
|
|
style::Stylize,
|
|
text::{Line, Span},
|
|
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::Char(c) => Span::raw(c.to_string()),
|
|
other => Span::raw(format!("{:?}", other)),
|
|
}
|
|
.bold()
|
|
.red();
|
|
|
|
Line::from_iter([key_span, "\t - ".into(), b.description.into()])
|
|
})
|
|
.collect();
|
|
|
|
Paragraph::new(lines).alignment(Alignment::Left).block(
|
|
Block::default()
|
|
.borders(Borders::ALL)
|
|
.title("[ Keybindings ]"),
|
|
)
|
|
}
|