40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
pub struct ControlsEntry {
|
|
pub key: String,
|
|
pub action: String,
|
|
}
|
|
|
|
pub struct Controls {
|
|
pub entries: Vec<ControlsEntry>
|
|
}
|
|
|
|
impl Controls {
|
|
|
|
pub fn new() -> Controls {
|
|
Controls {
|
|
entries: vec![]
|
|
}
|
|
}
|
|
|
|
pub fn add(&mut self, key: String, action: String) -> &mut Self {
|
|
self.entries.push(ControlsEntry {
|
|
key,
|
|
action
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn render(&self) -> tui::widgets::Paragraph {
|
|
let key_style = tui::style::Style::default()
|
|
.add_modifier(tui::style::Modifier::BOLD)
|
|
.fg(tui::style::Color::Green)
|
|
.bg(tui::style::Color::Black);
|
|
let control_text = self.entries.iter().fold(Vec::new(), |mut spans, entry| {
|
|
spans.push(tui::text::Span::styled(entry.key.clone(), key_style));
|
|
spans.push(tui::text::Span::raw(format!(" {}", entry.action)));
|
|
spans.push(tui::text::Span::raw(" "));
|
|
spans
|
|
});
|
|
tui::widgets::Paragraph::new(tui::text::Spans::from(control_text))
|
|
.style(tui::style::Style::default().fg(tui::style::Color::White))
|
|
}
|
|
} |