Skip to main content

max / mountaineer

1.2 KB · 45 lines History Blame Raw
1 use crate::palette;
2 use ratatui::buffer::Buffer;
3 use ratatui::layout::Rect;
4 use ratatui::style::Style;
5 use ratatui::text::{Line, Span};
6 use ratatui::widgets::{Paragraph, Widget};
7
8 pub struct Hint {
9 pub key: &'static str,
10 pub label: &'static str,
11 }
12
13 pub fn hint(key: &'static str, label: &'static str) -> Hint {
14 Hint { key, label }
15 }
16
17 pub struct Footer {
18 hints: Vec<Hint>,
19 }
20
21 impl Footer {
22 pub fn new(hints: impl IntoIterator<Item = Hint>) -> Self {
23 Self {
24 hints: hints.into_iter().collect(),
25 }
26 }
27 }
28
29 impl Widget for &Footer {
30 fn render(self, area: Rect, buf: &mut Buffer) {
31 let mut spans: Vec<Span> = Vec::with_capacity(self.hints.len() * 4);
32 for (i, h) in self.hints.iter().enumerate() {
33 if i > 0 {
34 spans.push(Span::raw(" "));
35 }
36 spans.push(Span::styled(h.key, Style::default().fg(palette::ACCENT)));
37 spans.push(Span::raw(" "));
38 spans.push(Span::styled(h.label, Style::default().fg(palette::DIM)));
39 }
40 Paragraph::new(Line::from(spans))
41 .style(Style::default().bg(palette::BG))
42 .render(area, buf);
43 }
44 }
45