use crate::palette; use ratatui::buffer::Buffer; use ratatui::layout::Rect; use ratatui::style::Style; use ratatui::text::{Line, Span}; use ratatui::widgets::{Paragraph, Widget}; pub struct Hint { pub key: &'static str, pub label: &'static str, } pub fn hint(key: &'static str, label: &'static str) -> Hint { Hint { key, label } } pub struct Footer { hints: Vec, } impl Footer { pub fn new(hints: impl IntoIterator) -> Self { Self { hints: hints.into_iter().collect(), } } } impl Widget for &Footer { fn render(self, area: Rect, buf: &mut Buffer) { let mut spans: Vec = Vec::with_capacity(self.hints.len() * 4); for (i, h) in self.hints.iter().enumerate() { if i > 0 { spans.push(Span::raw(" ")); } spans.push(Span::styled(h.key, Style::default().fg(palette::ACCENT))); spans.push(Span::raw(" ")); spans.push(Span::styled(h.label, Style::default().fg(palette::DIM))); } Paragraph::new(Line::from(spans)) .style(Style::default().bg(palette::BG)) .render(area, buf); } }