Skip to content

Commit d587b59

Browse files
committed
fixed stopping while mocking
1 parent bcf3220 commit d587b59

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

keyboard.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func stopListener() error {
6767
// })
6868
func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
6969
cancel := make(chan bool)
70+
stopRoutine := false
7071

7172
go func() {
7273
for {
@@ -76,7 +77,10 @@ func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
7677
return
7778
}
7879
case keyInfo := <-mockChannel:
79-
onKeyPress(keyInfo)
80+
stopRoutine, _ = onKeyPress(keyInfo)
81+
if stopRoutine {
82+
inputTTY.Close()
83+
}
8084
}
8185
}
8286
}()
@@ -86,7 +90,7 @@ func Listen(onKeyPress func(key keys.Key) (stop bool, err error)) error {
8690
return err
8791
}
8892

89-
for {
93+
for !stopRoutine {
9094
key, err := getKeyPress(inputTTY)
9195
if err != nil {
9296
return err

0 commit comments

Comments
 (0)