Skip to content

Commit

Permalink
fix(whkd): allow single cmd configs
Browse files Browse the repository at this point in the history
This commit fixes issue #18 where a user reported that whkd would crash
when the config file only contained a single hotkey.

fix #18
  • Loading branch information
LGUG2Z committed Jun 28, 2023
1 parent 3098e89 commit cc2cbc9
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn parser() -> impl Parser<char, Whkdrc, Error = Simple<char>> {

let delimiter = just(":").padded();

let command = take_until(choice((comment, text::newline())))
let command = take_until(choice((comment, text::newline(), end())))
.padded()
.map(|c| c.0)
.collect::<String>();
Expand All @@ -45,7 +45,7 @@ pub fn parser() -> impl Parser<char, Whkdrc, Error = Simple<char>> {

let process_mapping = process_name
.then_ignore(delimiter)
.then(command)
.then(command.clone())
.padded()
.padded_by(comment.repeated())
.repeated()
Expand Down Expand Up @@ -104,6 +104,29 @@ pub fn parser() -> impl Parser<char, Whkdrc, Error = Simple<char>> {
mod tests {
use super::*;

#[test]
fn test_single_line_parse() {
let src = r#"
.shell pwsh # can be one of cmd | pwsh | powershell
alt + h : echo "Hello""#;

let output = parser().parse(src);
let expected = Whkdrc {
shell: Shell::Pwsh,
app_bindings: vec![],
bindings: vec![
HotkeyBinding {
keys: vec![String::from("alt"), String::from("h")],
command: String::from("echo \"Hello\""),
process_name: None,
},
],
};

assert_eq!(output.unwrap(), expected);
}

#[test]
fn test_parse() {
let src = r#"
Expand Down

0 comments on commit cc2cbc9

Please sign in to comment.