-
-
Notifications
You must be signed in to change notification settings - Fork 660
feat(cli): add the ability to specify a custom keybinding/symbols file via the cli #2731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5a14779
70dc4af
367f999
942b3c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use anyhow::Result; | ||
| use anyhow::{anyhow, Result}; | ||
| use crossterm::event::{KeyCode, KeyModifiers}; | ||
| use std::{fs::canonicalize, path::PathBuf, rc::Rc}; | ||
|
|
||
|
|
@@ -34,9 +34,32 @@ impl KeyConfig { | |
| .map_or_else(|_| Ok(symbols_file), Ok) | ||
| } | ||
|
|
||
| pub fn init() -> Result<Self> { | ||
| let keys = KeysList::init(Self::get_config_file()?); | ||
| let symbols = KeySymbols::init(Self::get_symbols_file()?); | ||
| pub fn init( | ||
| key_bindings_path: Option<&PathBuf>, | ||
| key_symbols_path: Option<&PathBuf>, | ||
| ) -> Result<Self> { | ||
| let keys = if let Some(path) = key_bindings_path { | ||
| if !path.exists() { | ||
| return Err(anyhow!( | ||
| "The custom key bindings file dosen't exists" | ||
| )); | ||
| } | ||
|
Comment on lines
+42
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check can be removed as |
||
| KeysList::init(path.clone()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about something like |
||
| } else { | ||
| KeysList::init(Self::get_config_file()?) | ||
| }; | ||
|
|
||
| let symbols = if let Some(path) = key_symbols_path { | ||
| if !path.exists() { | ||
| return Err(anyhow!( | ||
| "The custom key symbols file dosen't exists" | ||
| )); | ||
| } | ||
|
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check can be removed as |
||
| KeySymbols::init(path.clone()) | ||
| } else { | ||
| KeySymbols::init(Self::get_symbols_file()?) | ||
| }; | ||
|
|
||
| Ok(Self { keys, symbols }) | ||
| } | ||
|
|
||
|
|
@@ -193,7 +216,7 @@ mod tests { | |
|
|
||
| // testing | ||
| let result = std::panic::catch_unwind(|| { | ||
| let loaded_config = KeyConfig::init().unwrap(); | ||
| let loaded_config = KeyConfig::init(None, None).unwrap(); | ||
| assert_eq!( | ||
| loaded_config.keys.move_down, | ||
| KeysList::default().move_down | ||
|
|
@@ -208,7 +231,7 @@ mod tests { | |
| &original_key_symbols_path, | ||
| ) | ||
| .unwrap(); | ||
| let loaded_config = KeyConfig::init().unwrap(); | ||
| let loaded_config = KeyConfig::init(None, None).unwrap(); | ||
| assert_eq!( | ||
| loaded_config.keys.move_down, | ||
| KeysList::default().move_down | ||
|
|
@@ -220,7 +243,7 @@ mod tests { | |
| &original_key_list_path, | ||
| ) | ||
| .unwrap(); | ||
| let loaded_config = KeyConfig::init().unwrap(); | ||
| let loaded_config = KeyConfig::init(None, None).unwrap(); | ||
| assert_eq!( | ||
| loaded_config.keys.move_down, | ||
| GituiKeyEvent::new( | ||
|
|
@@ -231,7 +254,7 @@ mod tests { | |
| assert_eq!(loaded_config.symbols.esc, "Esc"); | ||
|
|
||
| fs::remove_file(&original_key_symbols_path).unwrap(); | ||
| let loaded_config = KeyConfig::init().unwrap(); | ||
| let loaded_config = KeyConfig::init(None, None).unwrap(); | ||
| assert_eq!( | ||
| loaded_config.keys.move_down, | ||
| GituiKeyEvent::new( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: this should by
key-symbols.