From d731fe71885abf51fb63c4cada4716592bd48a24 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Tue, 27 Jul 2021 01:35:21 +0200 Subject: [PATCH] Make `command_key` configurable Fixes #487 --- README.md | 2 ++ src/config.rs | 1 + src/main.rs | 25 ++++++++++++++++++------- src/ui/layout.rs | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 30ac809..a5bade7 100644 --- a/README.md +++ b/README.md @@ -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 , set to `:` by + default * `use_nerdfont`: Turn nerdfont glyphs on/off * `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 diff --git a/src/config.rs b/src/config.rs index 6cf87f9..81fcf2e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,6 +16,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b"; #[derive(Clone, Serialize, Deserialize, Debug, Default)] pub struct ConfigValues { + pub command_key: Option, pub default_keybindings: Option, pub keybindings: Option>, pub theme: Option, diff --git a/src/main.rs b/src/main.rs index c40ed8b..b24478f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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").is_none() { - s.call_on_name("main", |v: &mut ui::layout::Layout| { - v.enable_cmdline(); - }); - } - }); + let cmd_key = |cfg: Arc| 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").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").is_none() { diff --git a/src/ui/layout.rs b/src/ui/layout.rs index 3758f50..26b704e 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -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; } }