add initial help screen + keybinding -> command parsing

still needs some more work, i.e. to show commands in help instead of parsed data
structures, but it's a start.

fixes #117
fixes #121
This commit is contained in:
Henrik Friedrichsen
2020-02-02 21:51:40 +01:00
parent bf2a72ad81
commit fa960a4eba
6 changed files with 64 additions and 5 deletions

45
src/ui/help.rs Normal file
View File

@@ -0,0 +1,45 @@
use std::collections::HashMap;
use cursive::theme::Effect;
use cursive::utils::markup::StyledString;
use cursive::view::ViewWrapper;
use cursive::views::{ScrollView, TextView};
use command::Command;
use config::config_path;
use traits::ViewExt;
pub struct HelpView {
view: ScrollView<TextView>,
}
impl HelpView {
pub fn new(bindings: HashMap<String, Command>) -> HelpView {
let mut text = StyledString::styled("Keybindings\n\n", Effect::Bold);
let note = format!(
"Custom bindings can be set in {} within the [keybindings] section.\n\n",
config_path("config.toml").to_str().unwrap_or_default()
);
text.append(StyledString::styled(note, Effect::Italic));
let mut keys: Vec<&String> = bindings.keys().collect();
keys.sort();
for key in keys {
let command = serde_json::to_string(&bindings[key]).unwrap_or_default();
let binding = format!("{} -> {}\n", key, command);
text.append(binding);
}
HelpView {
view: ScrollView::new(TextView::new(text)),
}
}
}
impl ViewWrapper for HelpView {
wrap_impl!(self.view: ScrollView<TextView>);
}
impl ViewExt for HelpView {}

View File

@@ -1,6 +1,7 @@
pub mod album;
pub mod artist;
pub mod contextmenu;
pub mod help;
pub mod layout;
pub mod library;
pub mod listview;