expose keybindings in CommandManager for help view
This commit is contained in:
@@ -22,15 +22,25 @@ pub enum CommandResult {
|
||||
|
||||
pub struct CommandManager {
|
||||
aliases: HashMap<String, String>,
|
||||
bindings: HashMap<String, Command>,
|
||||
spotify: Arc<Spotify>,
|
||||
queue: Arc<Queue>,
|
||||
library: Arc<Library>,
|
||||
}
|
||||
|
||||
impl CommandManager {
|
||||
pub fn new(spotify: Arc<Spotify>, queue: Arc<Queue>, library: Arc<Library>) -> CommandManager {
|
||||
pub fn new(
|
||||
spotify: Arc<Spotify>,
|
||||
queue: Arc<Queue>,
|
||||
library: Arc<Library>,
|
||||
bindings: Option<HashMap<String, Command>>,
|
||||
) -> CommandManager {
|
||||
let mut kb = Self::default_keybindings();
|
||||
kb.extend(bindings.unwrap_or_default());
|
||||
|
||||
CommandManager {
|
||||
aliases: HashMap::new(),
|
||||
bindings: kb,
|
||||
spotify,
|
||||
queue,
|
||||
library,
|
||||
@@ -178,23 +188,22 @@ impl CommandManager {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn register_keybindings(
|
||||
this: Arc<Self>,
|
||||
cursive: &mut Cursive,
|
||||
keybindings: Option<HashMap<String, Command>>,
|
||||
) {
|
||||
let mut kb = Self::default_keybindings();
|
||||
kb.extend(keybindings.unwrap_or_default());
|
||||
pub fn register_keybindings(this: Arc<Self>, cursive: &mut Cursive) {
|
||||
let kb = this.keybindings();
|
||||
|
||||
for (k, v) in kb {
|
||||
if let Some(binding) = Self::parse_keybinding(&k) {
|
||||
Self::register_keybinding(this.clone(), cursive, binding, v);
|
||||
Self::register_keybinding(this.clone(), cursive, binding, v.clone());
|
||||
} else {
|
||||
error!("Could not parse keybinding: \"{}\"", &k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keybindings(&self) -> &HashMap<String, Command> {
|
||||
&self.bindings
|
||||
}
|
||||
|
||||
fn default_keybindings() -> HashMap<String, Command> {
|
||||
let mut kb = HashMap::new();
|
||||
|
||||
|
||||
13
src/main.rs
13
src/main.rs
@@ -192,15 +192,16 @@ fn main() {
|
||||
cfg.use_nerdfont.unwrap_or(false),
|
||||
));
|
||||
|
||||
let mut cmd_manager = CommandManager::new(spotify.clone(), queue.clone(), library.clone());
|
||||
let mut cmd_manager = CommandManager::new(
|
||||
spotify.clone(),
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
cfg.keybindings.clone(),
|
||||
);
|
||||
cmd_manager.register_all();
|
||||
|
||||
let cmd_manager = Arc::new(cmd_manager);
|
||||
CommandManager::register_keybindings(
|
||||
cmd_manager.clone(),
|
||||
&mut cursive,
|
||||
cfg.keybindings.clone(),
|
||||
);
|
||||
CommandManager::register_keybindings(cmd_manager.clone(), &mut cursive);
|
||||
|
||||
let search = ui::search::SearchView::new(
|
||||
event_manager.clone(),
|
||||
|
||||
Reference in New Issue
Block a user