Skip to content

Commit

Permalink
fixed stopping while mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Jun 5, 2022
1 parent bcf3220 commit d587b59
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func stopListener() error {
// })
func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
cancel := make(chan bool)
stopRoutine := false

go func() {
for {
Expand All @@ -76,7 +77,10 @@ func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
return
}
case keyInfo := <-mockChannel:
onKeyPress(keyInfo)
stopRoutine, _ = onKeyPress(keyInfo)
if stopRoutine {
inputTTY.Close()
}
}
}
}()
Expand All @@ -86,7 +90,7 @@ func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
return err
}

for {
for !stopRoutine {
key, err := getKeyPress(inputTTY)
if err != nil {
return err
Expand Down

0 comments on commit d587b59

Please sign in to comment.