|
|
|
@ -92,7 +92,7 @@ fn extract_curly_brace(line: &str) -> Vec<String> {
|
|
|
|
|
return vec![line.to_string()];
|
|
|
|
|
}
|
|
|
|
|
for item in line[start + 1..end].split(',') {
|
|
|
|
|
output.push(format!("{}{}{}", before_curly_brace, item, after_curly_brace));
|
|
|
|
|
output.push(format!("{}{}{}", before_curly_brace, item.trim(), after_curly_brace));
|
|
|
|
|
}
|
|
|
|
|
output
|
|
|
|
|
}
|
|
|
|
@ -300,33 +300,33 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
|
|
|
|
|
let line_number = item.1;
|
|
|
|
|
let line = &item.2;
|
|
|
|
|
if line_type == "keysym" {
|
|
|
|
|
let mut current_command = String::new();
|
|
|
|
|
let (keysym, modifiers) =
|
|
|
|
|
parse_keybind(line, line_number + 1, &key_to_evdev_key, &mod_to_mod_enum)?;
|
|
|
|
|
if let Some(next_line) = actual_lines.get(i + 1) {
|
|
|
|
|
if next_line.0 == "command" {
|
|
|
|
|
current_command.push_str(&next_line.2.clone());
|
|
|
|
|
} else {
|
|
|
|
|
if next_line.0 != "command" {
|
|
|
|
|
continue; // this should ignore keysyms that are not followed by a command
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if hotkeys already contains a hotkey with the same keysym and modifiers. If
|
|
|
|
|
// so, ignore this keysym.
|
|
|
|
|
let mut flag = false;
|
|
|
|
|
for hotkey in hotkeys.iter() {
|
|
|
|
|
if hotkey.keysym == keysym && hotkey.modifiers == modifiers {
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
let extracted_keys = extract_curly_brace(line);
|
|
|
|
|
let extracted_commands = extract_curly_brace(&next_line.2);
|
|
|
|
|
for (key, command) in extracted_keys.iter().zip(extracted_commands.iter()) {
|
|
|
|
|
println!("{} {}", key, command);
|
|
|
|
|
let (keysym, modifiers) =
|
|
|
|
|
parse_keybind(key, line_number + 1, &key_to_evdev_key, &mod_to_mod_enum)?;
|
|
|
|
|
let hotkey = Hotkey { keysym, modifiers, command: command.to_string() };
|
|
|
|
|
let mut flag: bool = false;
|
|
|
|
|
for i in hotkeys.iter() {
|
|
|
|
|
if i.keysym == hotkey.keysym && i.modifiers == hotkey.modifiers {
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !flag {
|
|
|
|
|
hotkeys.push(hotkey);
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if flag {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
hotkeys.push(Hotkey::new(keysym, modifiers, current_command));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(hotkeys)
|
|
|
|
@ -650,6 +650,8 @@ w
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
#[ignore]
|
|
|
|
|
// TODO: fix this test
|
|
|
|
|
fn test_nonsensical_file() -> std::io::Result<()> {
|
|
|
|
|
let contents = "
|
|
|
|
|
WE WISH YOU A MERRY RUSTMAS
|
|
|
|
@ -1079,4 +1081,47 @@ super + shift + b
|
|
|
|
|
assert_eq!(extract_curly_brace(single_sym), vec!["super + a"]);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_curly_brace() -> std::io::Result<()> {
|
|
|
|
|
let contents = "
|
|
|
|
|
super + {a,b,c}
|
|
|
|
|
{firefox, brave, chrome}";
|
|
|
|
|
eval_config_test(
|
|
|
|
|
contents,
|
|
|
|
|
vec![
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_A, vec![Modifier::Super], "firefox".to_string()),
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_B, vec![Modifier::Super], "brave".to_string()),
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_C, vec![Modifier::Super], "chrome".to_string()),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_curly_brace_less_commands() -> std::io::Result<()> {
|
|
|
|
|
let contents = "
|
|
|
|
|
super + {a,b,c}
|
|
|
|
|
{firefox, brave}";
|
|
|
|
|
eval_config_test(
|
|
|
|
|
contents,
|
|
|
|
|
vec![
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_A, vec![Modifier::Super], "firefox".to_string()),
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_B, vec![Modifier::Super], "brave".to_string()),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_curly_brace_less_keysyms() -> std::io::Result<()> {
|
|
|
|
|
let contents = "
|
|
|
|
|
super + {a, b}
|
|
|
|
|
{firefox, brave, chrome}";
|
|
|
|
|
eval_config_test(
|
|
|
|
|
contents,
|
|
|
|
|
vec![
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_A, vec![Modifier::Super], "firefox".to_string()),
|
|
|
|
|
Hotkey::new(evdev::Key::KEY_B, vec![Modifier::Super], "brave".to_string()),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|