I am trying to write a program which prints "wait" whenever cntrl + c is being pressed and continue printing the numbers from 1 to 10. Otherwise, numbers from 1 to 10 should be printed with delay of 10 seconds between each number.However control+ c is not being recognized whenever i click and "wait" is not being printed only numbers from 1 to 10 are.
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
fmt.Print(sig)
fmt.Print("WAIT")
}
}()
for i := 1; i <= 10; i++ {
fmt.Println(i)
time.Sleep(time.Second)
}
}
You need to ensure that your terminal or terminal emulator settings are set up to do what you are trying to do. Terminal drivers do a lot of filtering. For example on Enunchs, keys get translated into sent to the application and then get echoed back to the terminal as as .
Your terminal driver could be just ignoring . It could be in a passthu mode where it just sends as a character to your application.
How you would make such settings depends upon your operating system.