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