@@ -2,10 +2,7 @@ use anyhow::{anyhow, Result};
2
2
use crossterm:: event:: { KeyCode , KeyModifiers } ;
3
3
use std:: { fs:: canonicalize, path:: PathBuf , rc:: Rc } ;
4
4
5
- use crate :: {
6
- args:: { get_app_config_path, CliArgs } ,
7
- strings:: symbol,
8
- } ;
5
+ use crate :: { args:: get_app_config_path, strings:: symbol} ;
9
6
10
7
use super :: {
11
8
key_list:: { GituiKeyEvent , KeysList } ,
@@ -37,8 +34,11 @@ impl KeyConfig {
37
34
. map_or_else ( |_| Ok ( symbols_file) , Ok )
38
35
}
39
36
40
- pub fn init ( cli_args : & CliArgs ) -> Result < Self > {
41
- let keys = if let Some ( path) = & cli_args. key_bindings_path {
37
+ pub fn init (
38
+ key_bindings_path : Option < & PathBuf > ,
39
+ key_symbols_path : Option < & PathBuf > ,
40
+ ) -> Result < Self > {
41
+ let keys = if let Some ( path) = key_bindings_path {
42
42
if !path. exists ( ) {
43
43
return Err ( anyhow ! (
44
44
"The custom key bindings file dosen't exists"
@@ -49,7 +49,7 @@ impl KeyConfig {
49
49
KeysList :: init ( Self :: get_config_file ( ) ?)
50
50
} ;
51
51
52
- let symbols = if let Some ( path) = & cli_args . key_symbols_path {
52
+ let symbols = if let Some ( path) = key_symbols_path {
53
53
if !path. exists ( ) {
54
54
return Err ( anyhow ! (
55
55
"The custom key symbols file dosen't exists"
@@ -216,7 +216,7 @@ mod tests {
216
216
217
217
// testing
218
218
let result = std:: panic:: catch_unwind ( || {
219
- let loaded_config = KeyConfig :: init ( ) . unwrap ( ) ;
219
+ let loaded_config = KeyConfig :: init ( None , None ) . unwrap ( ) ;
220
220
assert_eq ! (
221
221
loaded_config. keys. move_down,
222
222
KeysList :: default ( ) . move_down
@@ -231,7 +231,7 @@ mod tests {
231
231
& original_key_symbols_path,
232
232
)
233
233
. unwrap ( ) ;
234
- let loaded_config = KeyConfig :: init ( ) . unwrap ( ) ;
234
+ let loaded_config = KeyConfig :: init ( None , None ) . unwrap ( ) ;
235
235
assert_eq ! (
236
236
loaded_config. keys. move_down,
237
237
KeysList :: default ( ) . move_down
@@ -243,7 +243,7 @@ mod tests {
243
243
& original_key_list_path,
244
244
)
245
245
. unwrap ( ) ;
246
- let loaded_config = KeyConfig :: init ( ) . unwrap ( ) ;
246
+ let loaded_config = KeyConfig :: init ( None , None ) . unwrap ( ) ;
247
247
assert_eq ! (
248
248
loaded_config. keys. move_down,
249
249
GituiKeyEvent :: new(
@@ -254,7 +254,7 @@ mod tests {
254
254
assert_eq ! ( loaded_config. symbols. esc, "Esc" ) ;
255
255
256
256
fs:: remove_file ( & original_key_symbols_path) . unwrap ( ) ;
257
- let loaded_config = KeyConfig :: init ( ) . unwrap ( ) ;
257
+ let loaded_config = KeyConfig :: init ( None , None ) . unwrap ( ) ;
258
258
assert_eq ! (
259
259
loaded_config. keys. move_down,
260
260
GituiKeyEvent :: new(
0 commit comments