-
Notifications
You must be signed in to change notification settings - Fork 59
After closing app using this library, Ctrl+C no longer works in terminal #44
Copy link
Copy link
Open
Description
Whenever I exit my app, I can't Ctrl+C or use certain other commands in my terminal. I'm on MacOS and using iterm2.
Here is my code - I usually exit the app cleanly by hitting q
// Start keyboard listener
if err := keyboard.Open(); err != nil {
fmt.Printf("Error opening keyboard: %v\n", err)
os.Exit(1)
}
defer keyboard.Close()
// Start a goroutine to watch for the 'q' key
go func() {
for {
char, key, err := keyboard.GetKey()
if err != nil {
if strings.Contains(err.Error(), "cancel") {
fmt.Println("exiting")
keyboard.Close()
return
}
keyboard.Close()
fmt.Printf("Error getting key: %v\n", err)
return
}
if char == 'q' || key == keyboard.KeyEsc {
fmt.Println("\nReceived quit signal")
cancel()
return
}
if key == keyboard.KeyCtrlC {
fmt.Println("\nReceived interrupt signal")
os.Exit(0) // Exit immediately
}
}
}()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels