Make command_key configurable

Fixes #487
This commit is contained in:
Henrik Friedrichsen
2021-07-27 01:35:21 +02:00
parent ad3383657d
commit d731fe7188
4 changed files with 23 additions and 9 deletions

View File

@@ -187,6 +187,8 @@ configuration during runtime use the `reload` statement in the command prompt
Possible configuration values are:
* `command_key`: Key to open command line <single character>, set to `:` by
default
* `use_nerdfont`: Turn nerdfont glyphs on/off <true/false>
* `flip_status_indicators`: By default the statusbar will show a play icon when
a track is playing and a pause icon when playback is stopped. If this setting

View File

@@ -16,6 +16,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct ConfigValues {
pub command_key: Option<char>,
pub default_keybindings: Option<bool>,
pub keybindings: Option<HashMap<String, String>>,
pub theme: Option<ConfigTheme>,

View File

@@ -11,6 +11,7 @@ use std::str::FromStr;
use std::sync::Arc;
use clap::{App, Arg};
use cursive::event::EventTrigger;
use cursive::traits::Identifiable;
use librespot_core::authentication::Credentials;
use librespot_core::cache::Cache;
@@ -229,13 +230,23 @@ async fn main() -> Result<(), String> {
// initial screen is library
layout.set_screen("library");
cursive.add_global_callback(':', move |s| {
if s.find_name::<ContextMenu>("contextmenu").is_none() {
s.call_on_name("main", |v: &mut ui::layout::Layout| {
v.enable_cmdline();
});
}
});
let cmd_key = |cfg: Arc<Config>| cfg.values().command_key.unwrap_or(':');
{
let c = cfg.clone();
cursive.set_on_post_event(
EventTrigger::from_fn(move |event| {
event == &cursive::event::Event::Char(cmd_key(c.clone()))
}),
move |s| {
if s.find_name::<ContextMenu>("contextmenu").is_none() {
s.call_on_name("main", |v: &mut ui::layout::Layout| {
v.enable_cmdline(cmd_key(cfg.clone()));
});
}
},
);
}
cursive.add_global_callback('/', move |s| {
if s.find_name::<ContextMenu>("contextmenu").is_none() {

View File

@@ -56,9 +56,9 @@ impl Layout {
}
}
pub fn enable_cmdline(&mut self) {
pub fn enable_cmdline(&mut self, prefix: char) {
if !self.cmdline_focus {
self.cmdline.set_content(":");
self.cmdline.set_content(prefix);
self.cmdline_focus = true;
}
}